Skip to content

Instantly share code, notes, and snippets.

@irr
Forked from rlipscombe/initial_calls.erl
Created November 11, 2015 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irr/74072d4ca649aa5abfd8 to your computer and use it in GitHub Desktop.
Save irr/74072d4ca649aa5abfd8 to your computer and use it in GitHub Desktop.
Finding leaked processes in Erlang
lists:sort(fun({_, X}, {_, Y}) -> X > Y end,
dict:to_list(lists:foldl(
fun(Pid, Dict) ->
InitialCall = case erlang:process_info(Pid, initial_call) of
{initial_call,{proc_lib,init_p,A}} ->
case erlang:process_info(Pid, dictionary) of
{dictionary, D} -> proplists:get_value('$initial_call', D, undefined);
_ -> {proc_lib,init_p,A}
end;
{initial_call,IC} ->
IC;
Other ->
Other
end,
dict:update_counter(InitialCall, 1, Dict)
end, dict:new(), erlang:processes()))).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment