From: Siraaj Khandkar Date: Wed, 16 Sep 2015 22:00:53 +0000 (-0400) Subject: Implement printing process stats. X-Git-Tag: 0.7.0^2~4 X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=fa175c943c5d08ca2fdf2156abc3023ccf8b9baa;p=beam_stats.git Implement printing process stats. --- diff --git a/src/beam_stats_process.erl b/src/beam_stats_process.erl index a06c48e..412b4f8 100644 --- a/src/beam_stats_process.erl +++ b/src/beam_stats_process.erl @@ -9,6 +9,7 @@ -export( [ of_pid/1 + , print/1 ]). -type status() :: @@ -25,6 +26,10 @@ -type t() :: ?T{}. +%% ============================================================================ +%% Public API +%% ============================================================================ + -spec of_pid(pid()) -> t(). of_pid(Pid) -> @@ -42,6 +47,52 @@ of_pid(Pid) -> , message_queue_len = pid_info_exn(Pid, message_queue_len) }. +-spec print(t()) -> + ok. +print( + ?T + { pid = Pid + , registered_name = RegisteredNameOpt + , raw_initial_call = InitialCallRaw + , otp_initial_call = InitialCallOTPOpt + , otp_ancestors = AncestorsOpt + , status = Status + , memory = Memory + , total_heap_size = TotalHeapSize + , stack_size = StackSize + , message_queue_len = MsgQueueLen + } +) -> + io:format("--------------------------------------------------~n"), + io:format( + "Pid : ~p~n" + "RegisteredNameOpt : ~p~n" + "InitialCallRaw : ~p~n" + "InitialCallOTPOpt : ~p~n" + "AncestorsOpt : ~p~n" + "Status : ~p~n" + "Memory : ~p~n" + "TotalHeapSize : ~p~n" + "StackSize : ~p~n" + "MsgQueueLen : ~p~n" + "~n", + [ Pid + , RegisteredNameOpt + , InitialCallRaw + , InitialCallOTPOpt + , AncestorsOpt + , Status + , Memory + , TotalHeapSize + , StackSize + , MsgQueueLen + ] + ). + +%% ============================================================================ +%% Private helpers +%% ============================================================================ + pid_info_exn(Pid, Key) -> {some, Value} = pid_info_opt(Pid, Key), Value. diff --git a/src/beam_stats_processes.erl b/src/beam_stats_processes.erl index 707a534..2505178 100644 --- a/src/beam_stats_processes.erl +++ b/src/beam_stats_processes.erl @@ -9,6 +9,8 @@ -export( [ collect/0 + , collect_and_print/0 + , print/1 ]). -define(T, #?MODULE). @@ -40,3 +42,51 @@ collect() -> , count_waiting = length([P || P <- Ps, P#beam_stats_process.status =:= waiting]) }. + +collect_and_print() -> + print(collect()). + +-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: + 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 + ] + ).