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