Skip to content

Instantly share code, notes, and snippets.

@ferd
Created August 6, 2012 13:29
Show Gist options
  • Select an option

  • Save ferd/3274480 to your computer and use it in GitHub Desktop.

Select an option

Save ferd/3274480 to your computer and use it in GitHub Desktop.
copy/paste in the shell, call Biggest(Milliseconds, N)
F = fun() -> [{Pid, {Reds, Curr, Init}} || Pid <- processes(),
{_, Reds} <- [process_info(Pid, reductions)],
{_, Curr} <- [process_info(Pid, current_function)],
{_, Init} <- [process_info(Pid, initial_call)]] 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.
Biggest = fun(X,Y) -> lists:sublist(lists:usort(fun({_,{X,A1,A2}}, {_,{Y,B1,B2}}) -> X > Y end, dict:to_list(Build(Fetch(X)))),Y) end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment