Add run_queue
[beam_stats.git] / src / beam_stats_state.erl
CommitLineData
b4e2333f
SK
1-module(beam_stats_state).
2
3-include("include/beam_stats.hrl").
4
5-export_type(
6 [ t/0
7 ]).
8
9-export(
10 [ new/0
11 , update/1
12 , export/1
13 ]).
14
15-record(?MODULE,
16 { timestamp :: erlang:timestamp()
17 , node_id :: atom()
18 , memory :: [{atom(), non_neg_integer()}]
3fe887d7 19
b4e2333f
SK
20 , previous_io_bytes_in :: non_neg_integer()
21 , previous_io_bytes_out :: non_neg_integer()
22 , current_io_bytes_in :: non_neg_integer()
23 , current_io_bytes_out :: non_neg_integer()
3fe887d7
SK
24
25 , previous_context_switches :: non_neg_integer()
26 , current_context_switches :: non_neg_integer()
142c0796
SK
27
28 , reductions :: non_neg_integer()
deefeb3c 29 , run_queue :: non_neg_integer()
b4e2333f
SK
30 }).
31
32-define(T, #?MODULE).
33
34-opaque t() ::
35 ?T{}.
36
37-spec new() ->
38 t().
39new() ->
40 { {input , CurrentIOBytesIn}
41 , {output , CurrentIOBytesOut}
42 } = erlang:statistics(io),
3fe887d7 43 {CurrentContextSwitches, 0} = erlang:statistics(context_switches),
142c0796 44 {_ReductionsTotal, ReductionsDelta} = erlang:statistics(reductions),
deefeb3c 45 RunQueue = erlang:statistics(run_queue),
b4e2333f
SK
46 ?T
47 { timestamp = os:timestamp()
48 , node_id = erlang:node()
49 , memory = erlang:memory()
50 , previous_io_bytes_in = 0
51 , previous_io_bytes_out = 0
52 , current_io_bytes_in = CurrentIOBytesIn
53 , current_io_bytes_out = CurrentIOBytesOut
3fe887d7
SK
54 , previous_context_switches = 0
55 , current_context_switches = CurrentContextSwitches
142c0796 56 , reductions = ReductionsDelta
deefeb3c 57 , run_queue = RunQueue
b4e2333f
SK
58 }.
59
60-spec update(t()) ->
61 t().
62update(?T
63 { previous_io_bytes_in = PreviousIOBytesIn
64 , previous_io_bytes_out = PreviousIOBytesOut
3fe887d7 65 , previous_context_switches = PreviousContextSwitches
b4e2333f
SK
66 }
67) ->
68 { {input , CurrentIOBytesIn}
69 , {output , CurrentIOBytesOut}
70 } = erlang:statistics(io),
3fe887d7 71 {CurrentContextSwitches, 0} = erlang:statistics(context_switches),
142c0796 72 {_ReductionsTotal, ReductionsDelta} = erlang:statistics(reductions),
deefeb3c 73 RunQueue = erlang:statistics(run_queue),
b4e2333f
SK
74 ?T
75 { timestamp = os:timestamp()
76 , node_id = erlang:node()
77 , memory = erlang:memory()
78 , previous_io_bytes_in = PreviousIOBytesIn
79 , previous_io_bytes_out = PreviousIOBytesOut
80 , current_io_bytes_in = CurrentIOBytesIn
81 , current_io_bytes_out = CurrentIOBytesOut
3fe887d7
SK
82 , previous_context_switches = PreviousContextSwitches
83 , current_context_switches = CurrentContextSwitches
142c0796 84 , reductions = ReductionsDelta
deefeb3c 85 , run_queue = RunQueue
b4e2333f
SK
86 }.
87
88-spec export(t()) ->
89 beam_stats:t().
90export(
91 ?T
92 { timestamp = Timestamp
93 , node_id = NodeID
94 , memory = Memory
95 , previous_io_bytes_in = PreviousIOBytesIn
96 , previous_io_bytes_out = PreviousIOBytesOut
97 , current_io_bytes_in = CurrentIOBytesIn
98 , current_io_bytes_out = CurrentIOBytesOut
3fe887d7
SK
99 , previous_context_switches = PreviousContextSwitches
100 , current_context_switches = CurrentContextSwitches
142c0796 101 , reductions = Reductions
deefeb3c 102 , run_queue = RunQueue
b4e2333f
SK
103 }
104) ->
105 #beam_stats
106 { timestamp = Timestamp
107 , node_id = NodeID
108 , memory = Memory
109 , io_bytes_in = CurrentIOBytesIn - PreviousIOBytesIn
110 , io_bytes_out = CurrentIOBytesOut - PreviousIOBytesOut
3fe887d7 111 , context_switches = CurrentContextSwitches - PreviousContextSwitches
142c0796 112 , reductions = Reductions
deefeb3c 113 , run_queue = RunQueue
b4e2333f 114 }.
This page took 0.030569 seconds and 4 git commands to generate.