Add reductions delta.
[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()
b4e2333f
SK
29 }).
30
31-define(T, #?MODULE).
32
33-opaque t() ::
34 ?T{}.
35
36-spec new() ->
37 t().
38new() ->
39 { {input , CurrentIOBytesIn}
40 , {output , CurrentIOBytesOut}
41 } = erlang:statistics(io),
3fe887d7 42 {CurrentContextSwitches, 0} = erlang:statistics(context_switches),
142c0796 43 {_ReductionsTotal, ReductionsDelta} = erlang:statistics(reductions),
b4e2333f
SK
44 ?T
45 { timestamp = os:timestamp()
46 , node_id = erlang:node()
47 , memory = erlang:memory()
48 , previous_io_bytes_in = 0
49 , previous_io_bytes_out = 0
50 , current_io_bytes_in = CurrentIOBytesIn
51 , current_io_bytes_out = CurrentIOBytesOut
3fe887d7
SK
52 , previous_context_switches = 0
53 , current_context_switches = CurrentContextSwitches
142c0796 54 , reductions = ReductionsDelta
b4e2333f
SK
55 }.
56
57-spec update(t()) ->
58 t().
59update(?T
60 { previous_io_bytes_in = PreviousIOBytesIn
61 , previous_io_bytes_out = PreviousIOBytesOut
3fe887d7 62 , previous_context_switches = PreviousContextSwitches
b4e2333f
SK
63 }
64) ->
65 { {input , CurrentIOBytesIn}
66 , {output , CurrentIOBytesOut}
67 } = erlang:statistics(io),
3fe887d7 68 {CurrentContextSwitches, 0} = erlang:statistics(context_switches),
142c0796 69 {_ReductionsTotal, ReductionsDelta} = erlang:statistics(reductions),
b4e2333f
SK
70 ?T
71 { timestamp = os:timestamp()
72 , node_id = erlang:node()
73 , memory = erlang:memory()
74 , previous_io_bytes_in = PreviousIOBytesIn
75 , previous_io_bytes_out = PreviousIOBytesOut
76 , current_io_bytes_in = CurrentIOBytesIn
77 , current_io_bytes_out = CurrentIOBytesOut
3fe887d7
SK
78 , previous_context_switches = PreviousContextSwitches
79 , current_context_switches = CurrentContextSwitches
142c0796 80 , reductions = ReductionsDelta
b4e2333f
SK
81 }.
82
83-spec export(t()) ->
84 beam_stats:t().
85export(
86 ?T
87 { timestamp = Timestamp
88 , node_id = NodeID
89 , memory = Memory
90 , previous_io_bytes_in = PreviousIOBytesIn
91 , previous_io_bytes_out = PreviousIOBytesOut
92 , current_io_bytes_in = CurrentIOBytesIn
93 , current_io_bytes_out = CurrentIOBytesOut
3fe887d7
SK
94 , previous_context_switches = PreviousContextSwitches
95 , current_context_switches = CurrentContextSwitches
142c0796 96 , reductions = Reductions
b4e2333f
SK
97 }
98) ->
99 #beam_stats
100 { timestamp = Timestamp
101 , node_id = NodeID
102 , memory = Memory
103 , io_bytes_in = CurrentIOBytesIn - PreviousIOBytesIn
104 , io_bytes_out = CurrentIOBytesOut - PreviousIOBytesOut
3fe887d7 105 , context_switches = CurrentContextSwitches - PreviousContextSwitches
142c0796 106 , reductions = Reductions
b4e2333f 107 }.
This page took 0.03159 seconds and 4 git commands to generate.