Skip to content

Instantly share code, notes, and snippets.

@loxs
Created March 24, 2017 10:20
Show Gist options
  • Save loxs/f38588d1d1c098745624960ebad60e25 to your computer and use it in GitHub Desktop.
Save loxs/f38588d1d1c098745624960ebad60e25 to your computer and use it in GitHub Desktop.
def processes_by_type() do
procs = Enum.reduce(:erlang.processes(), %{}, fn(pid, acc) ->
initial_call = case :erlang.process_info(pid, :initial_call) do
{:initial_call, {:proc_lib, :init_p, a}} ->
case :erlang.process_info(pid, :dictionary) do
{:dictionary, d} ->
Keyword.get(d, :"$initial_call")
_ ->
{:proc_lib, :init_p, a}
end
{:initial_call, {:erlang, :apply, a}} ->
case :erlang.process_info(pid, :current_function) do
{:current_function, mfa} -> mfa
_ -> {:erlang, :apply, a}
end
{:initial_call, IC} ->
IC
other ->
other
end
Map.update(acc, initial_call, 1, &(&1 + 1))
end)
Enum.sort(
Enum.into(procs, []),
fn({_, x}, {_, y}) -> x > y end
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment