Commit | Line | Data |
---|---|---|
5eba068e SK |
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( | |
7dbc59b6 SK |
11 | [ collect/1 |
12 | , collect_and_print/1 | |
fa175c94 | 13 | , print/1 |
5eba068e SK |
14 | ]). |
15 | ||
16 | -define(T, #?MODULE). | |
17 | ||
18 | -type t() :: | |
19 | ?T{}. | |
20 | ||
7dbc59b6 | 21 | -spec collect(beam_stats_delta:t()) -> |
5eba068e | 22 | t(). |
7dbc59b6 | 23 | collect(DeltasServer) -> |
aa4143aa | 24 | Pids = beam_stats_source:erlang_processes(), |
7dbc59b6 | 25 | PsOpts = [beam_stats_process:of_pid(P, DeltasServer) || P <- Pids], |
2cd7cf62 | 26 | Ps = [P || {some, P} <- PsOpts], |
5eba068e SK |
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 | |
aa4143aa | 37 | = length(beam_stats_source:erlang_registered()) |
5eba068e SK |
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 | }. | |
fa175c94 | 47 | |
7dbc59b6 SK |
48 | -spec collect_and_print(beam_stats_delta:t()) -> |
49 | ok. | |
50 | collect_and_print(DeltasServer) -> | |
51 | print(collect(DeltasServer)). | |
fa175c94 SK |
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}) -> | |
e99ea129 SK |
70 | % From lowest to highest, so that the largest appears the end of |
71 | % the output and be easier to see (without scrolling back): | |
fa175c94 SK |
72 | A < B |
73 | end, | |
74 | PerProcessStats | |
75 | ), | |
76 | lists:foreach(fun beam_stats_process:print/1, PerProcessStatsSorted), | |
77 | io:format("==================================================~n"), | |
78 | io:format( | |
79 | "CountAll : ~b~n" | |
80 | "CountExiting : ~b~n" | |
81 | "CountGarbageCollecting : ~b~n" | |
82 | "CountRegistered : ~b~n" | |
83 | "CountRunnable : ~b~n" | |
84 | "CountRunning : ~b~n" | |
85 | "CountSuspended : ~b~n" | |
86 | "CountWaiting : ~b~n" | |
87 | "~n", | |
88 | [ CountAll | |
89 | , CountExiting | |
90 | , CountGarbageCollecting | |
91 | , CountRegistered | |
92 | , CountRunnable | |
93 | , CountRunning | |
94 | , CountSuspended | |
95 | , CountWaiting | |
96 | ] | |
97 | ). |