2505178132606005c0178399fd1bd36f56c63806
[beam_stats.git] / src / beam_stats_processes.erl
1 -module(beam_stats_processes).
2
3 -include("include/beam_stats_process.hrl").
4 -include("include/beam_stats_processes.hrl").
5
6 -export_type(
7 [ t/0
8 ]).
9
10 -export(
11 [ collect/0
12 , collect_and_print/0
13 , print/1
14 ]).
15
16 -define(T, #?MODULE).
17
18 -type t() ::
19 ?T{}.
20
21 -spec collect() ->
22 t().
23 collect() ->
24 Ps = [beam_stats_process:of_pid(P) || P <- erlang:processes()],
25 ?T
26 { individual_stats
27 = Ps
28 , count_all
29 = length(Ps)
30 , count_exiting
31 = length([P || P <- Ps, P#beam_stats_process.status =:= exiting])
32 , count_garbage_collecting
33 = length([P || P <- Ps, P#beam_stats_process.status =:= garbage_collecting])
34 , count_registered
35 = length(registered())
36 , count_runnable
37 = length([P || P <- Ps, P#beam_stats_process.status =:= runnable])
38 , count_running
39 = length([P || P <- Ps, P#beam_stats_process.status =:= running])
40 , count_suspended
41 = length([P || P <- Ps, P#beam_stats_process.status =:= suspended])
42 , count_waiting
43 = length([P || P <- Ps, P#beam_stats_process.status =:= waiting])
44 }.
45
46 collect_and_print() ->
47 print(collect()).
48
49 -spec print(t()) ->
50 ok.
51 print(
52 ?T
53 { individual_stats = PerProcessStats
54 , count_all = CountAll
55 , count_exiting = CountExiting
56 , count_garbage_collecting = CountGarbageCollecting
57 , count_registered = CountRegistered
58 , count_runnable = CountRunnable
59 , count_running = CountRunning
60 , count_suspended = CountSuspended
61 , count_waiting = CountWaiting
62 }
63 ) ->
64 PerProcessStatsSorted = lists:sort(
65 fun (#beam_stats_process{memory=A}, #beam_stats_process{memory=B}) ->
66 % From lowest to highest:
67 A < B
68 end,
69 PerProcessStats
70 ),
71 lists:foreach(fun beam_stats_process:print/1, PerProcessStatsSorted),
72 io:format("==================================================~n"),
73 io:format(
74 "CountAll : ~b~n"
75 "CountExiting : ~b~n"
76 "CountGarbageCollecting : ~b~n"
77 "CountRegistered : ~b~n"
78 "CountRunnable : ~b~n"
79 "CountRunning : ~b~n"
80 "CountSuspended : ~b~n"
81 "CountWaiting : ~b~n"
82 "~n",
83 [ CountAll
84 , CountExiting
85 , CountGarbageCollecting
86 , CountRegistered
87 , CountRunnable
88 , CountRunning
89 , CountSuspended
90 , CountWaiting
91 ]
92 ).
This page took 0.063436 seconds and 3 git commands to generate.