Skip to content

Instantly share code, notes, and snippets.

@rlipscombe
Last active March 25, 2017 00:54
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save rlipscombe/a8e87583d47799170f8b to your computer and use it in GitHub Desktop.
Save rlipscombe/a8e87583d47799170f8b 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,{erlang,apply,A}} ->
case erlang:process_info(Pid, current_function) of
{current_function,MFA} -> MFA;
_ -> {erlang,apply,A}
end;
{initial_call,IC} ->
IC;
Other ->
Other
end,
dict:update_counter(InitialCall, 1, Dict)
end, dict:new(), erlang:processes()))).
@loxs
Copy link

loxs commented Mar 24, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment