Implement printing process stats.
[beam_stats.git] / src / beam_stats_processes.erl
index 707a534..2505178 100644 (file)
@@ -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
+        ]
+    ).
This page took 0.018307 seconds and 4 git commands to generate.