Skip to content

Instantly share code, notes, and snippets.

@ferd
Last active December 18, 2015 00:09
Show Gist options
  • Save ferd/5694838 to your computer and use it in GitHub Desktop.
Save ferd/5694838 to your computer and use it in GitHub Desktop.
f(Window).
Window = fun(AttrName, Time,NumProcs) ->
Attrs = fun(Name) ->
[{Pid, {Attr, Curr, Init}}
|| Pid <- processes() -- [self()],
[{_, Attr}, {_, Curr}, {_, Init}] <-
[process_info(Pid, [Name, current_function, initial_call])]]
end,
F = fun() -> Attrs(AttrName) end,
Fetch = fun(T) -> A = F(), timer:sleep(T), B = F(), {A,B} end,
Build = fun({A,B}) ->
D = dict:from_list(A),
lists:foldl(fun({Pid,{Red,Cur,Init}}, Dict) ->
dict:update(Pid, fun({RedOld,_,_}) ->
{Red-RedOld,Cur,Init}
end, {Red,Cur,Init}, Dict)
end, D, B)
end,
lists:sublist(lists:usort(
fun({_,{X,A1,A2}}, {_,{Y,B1,B2}}) -> X > Y end,
dict:to_list(Build(Fetch(Time)))
),NumProcs)
end.
% Window(reductions, Time, NumProcs).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment