1b3fcb2ef26429ecca4ca41d25b125a86eba3f08
[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 Pids = beam_stats_source:erlang_processes(),
25 PsOpts = [beam_stats_process:of_pid(P) || P <- Pids],
26 Ps = [P || {some, P} <- PsOpts],
27 ?T
28 { individual_stats
29 = Ps
30 , count_all
31 = length(Ps)
32 , count_exiting
33 = length([P || P <- Ps, P#beam_stats_process.status =:= exiting])
34 , count_garbage_collecting
35 = length([P || P <- Ps, P#beam_stats_process.status =:= garbage_collecting])
36 , count_registered
37 = length(beam_stats_source:erlang_registered())
38 , count_runnable
39 = length([P || P <- Ps, P#beam_stats_process.status =:= runnable])
40 , count_running
41 = length([P || P <- Ps, P#beam_stats_process.status =:= running])
42 , count_suspended
43 = length([P || P <- Ps, P#beam_stats_process.status =:= suspended])
44 , count_waiting
45 = length([P || P <- Ps, P#beam_stats_process.status =:= waiting])
46 }.
47
48 collect_and_print() ->
49 print(collect()).
50
51 -spec print(t()) ->
52 ok.
53 print(
54 ?T
55 { individual_stats = PerProcessStats
56 , count_all = CountAll
57 , count_exiting = CountExiting
58 , count_garbage_collecting = CountGarbageCollecting
59 , count_registered = CountRegistered
60 , count_runnable = CountRunnable
61 , count_running = CountRunning
62 , count_suspended = CountSuspended
63 , count_waiting = CountWaiting
64 }
65 ) ->
66 PerProcessStatsSorted = lists:sort(
67 fun (#beam_stats_process{memory=A}, #beam_stats_process{memory=B}) ->
68 % From lowest to highest:
69 A < B
70 end,
71 PerProcessStats
72 ),
73 lists:foreach(fun beam_stats_process:print/1, PerProcessStatsSorted),
74 io:format("==================================================~n"),
75 io:format(
76 "CountAll : ~b~n"
77 "CountExiting : ~b~n"
78 "CountGarbageCollecting : ~b~n"
79 "CountRegistered : ~b~n"
80 "CountRunnable : ~b~n"
81 "CountRunning : ~b~n"
82 "CountSuspended : ~b~n"
83 "CountWaiting : ~b~n"
84 "~n",
85 [ CountAll
86 , CountExiting
87 , CountGarbageCollecting
88 , CountRegistered
89 , CountRunnable
90 , CountRunning
91 , CountSuspended
92 , CountWaiting
93 ]
94 ).
This page took 0.047351 seconds and 3 git commands to generate.