X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=src%2Fbeam_stats_processes.erl;h=607376c72b42f1b0fa23f81a8d9300a7c68cbe6c;hb=e99ea129941260681c5518ac37267e1f5b4e28c3;hp=707a534d5d81bc6c018422dfcf44095f04cbaf2d;hpb=5eba068e902ebd18f8368a783291292117a217fe;p=beam_stats.git diff --git a/src/beam_stats_processes.erl b/src/beam_stats_processes.erl index 707a534..607376c 100644 --- a/src/beam_stats_processes.erl +++ b/src/beam_stats_processes.erl @@ -8,7 +8,9 @@ ]). -export( - [ collect/0 + [ collect/1 + , collect_and_print/1 + , print/1 ]). -define(T, #?MODULE). @@ -16,10 +18,12 @@ -type t() :: ?T{}. --spec collect() -> +-spec collect(beam_stats_delta:t()) -> t(). -collect() -> - Ps = [beam_stats_process:of_pid(P) || P <- erlang:processes()], +collect(DeltasServer) -> + Pids = beam_stats_source:erlang_processes(), + PsOpts = [beam_stats_process:of_pid(P, DeltasServer) || P <- Pids], + Ps = [P || {some, P} <- PsOpts], ?T { individual_stats = Ps @@ -30,7 +34,7 @@ collect() -> , count_garbage_collecting = length([P || P <- Ps, P#beam_stats_process.status =:= garbage_collecting]) , count_registered - = length(registered()) + = length(beam_stats_source:erlang_registered()) , count_runnable = length([P || P <- Ps, P#beam_stats_process.status =:= runnable]) , count_running @@ -40,3 +44,54 @@ collect() -> , count_waiting = length([P || P <- Ps, P#beam_stats_process.status =:= waiting]) }. + +-spec collect_and_print(beam_stats_delta:t()) -> + ok. +collect_and_print(DeltasServer) -> + print(collect(DeltasServer)). + +-spec print(t()) -> + ok. +print( + ?T + { individual_stats = PerProcessStats + , count_all = CountAll + , count_exiting = CountExiting + , count_garbage_collecting = CountGarbageCollecting + , count_registered = CountRegistered + , count_runnable = CountRunnable + , count_running = CountRunning + , count_suspended = CountSuspended + , count_waiting = CountWaiting + } +) -> + PerProcessStatsSorted = lists:sort( + fun (#beam_stats_process{memory=A}, #beam_stats_process{memory=B}) -> + % From lowest to highest, so that the largest appears the end of + % the output and be easier to see (without scrolling back): + A < B + end, + PerProcessStats + ), + lists:foreach(fun beam_stats_process:print/1, PerProcessStatsSorted), + io:format("==================================================~n"), + io:format( + "CountAll : ~b~n" + "CountExiting : ~b~n" + "CountGarbageCollecting : ~b~n" + "CountRegistered : ~b~n" + "CountRunnable : ~b~n" + "CountRunning : ~b~n" + "CountSuspended : ~b~n" + "CountWaiting : ~b~n" + "~n", + [ CountAll + , CountExiting + , CountGarbageCollecting + , CountRegistered + , CountRunnable + , CountRunning + , CountSuspended + , CountWaiting + ] + ).