d369314251867a469377bcf3499a90f4869bddc6
[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/1
12 , collect_and_print/1
13 , print/1
14 ]).
15
16 -define(T, #?MODULE).
17
18 -type t() ::
19 ?T{}.
20
21 -spec collect(beam_stats_delta:t()) ->
22 t().
23 collect(DeltasServer) ->
24 Pids = beam_stats_source:erlang_processes(),
25 PsOpts = [beam_stats_process:of_pid(P, DeltasServer) || 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 -spec collect_and_print(beam_stats_delta:t()) ->
49 ok.
50 collect_and_print(DeltasServer) ->
51 print(collect(DeltasServer)).
52
53 -spec print(t()) ->
54 ok.
55 print(
56 ?T
57 { individual_stats = PerProcessStats
58 , count_all = CountAll
59 , count_exiting = CountExiting
60 , count_garbage_collecting = CountGarbageCollecting
61 , count_registered = CountRegistered
62 , count_runnable = CountRunnable
63 , count_running = CountRunning
64 , count_suspended = CountSuspended
65 , count_waiting = CountWaiting
66 }
67 ) ->
68 PerProcessStatsSorted = lists:sort(
69 fun (#beam_stats_process{memory=A}, #beam_stats_process{memory=B}) ->
70 % From lowest to highest:
71 A < B
72 end,
73 PerProcessStats
74 ),
75 lists:foreach(fun beam_stats_process:print/1, PerProcessStatsSorted),
76 io:format("==================================================~n"),
77 io:format(
78 "CountAll : ~b~n"
79 "CountExiting : ~b~n"
80 "CountGarbageCollecting : ~b~n"
81 "CountRegistered : ~b~n"
82 "CountRunnable : ~b~n"
83 "CountRunning : ~b~n"
84 "CountSuspended : ~b~n"
85 "CountWaiting : ~b~n"
86 "~n",
87 [ CountAll
88 , CountExiting
89 , CountGarbageCollecting
90 , CountRegistered
91 , CountRunnable
92 , CountRunning
93 , CountSuspended
94 , CountWaiting
95 ]
96 ).
This page took 0.045436 seconds and 3 git commands to generate.