1 -module(beam_stats_state).
3 -include("include/beam_stats.hrl").
16 { memory :: [{atom(), non_neg_integer()}]
17 , run_queue :: non_neg_integer()
24 { reductions :: non_neg_integer()
31 { io_bytes_in :: non_neg_integer()
32 , io_bytes_out :: non_neg_integer()
33 , context_switches :: non_neg_integer()
40 { timestamp :: erlang:timestamp()
42 , snapshots :: snapshots() % Current state
43 , deltas :: deltas() % Accumulated since last check
44 , totals_previous :: totals() % Accumulated since VM start, as of last state
45 , totals_current :: totals() % Accumulated since VM start, as of this state
56 TotalsPrevious = totals_empty(),
59 -spec new(TotalsPrevious :: totals()) ->
61 new(#totals{}=TotalsPrevious) ->
63 { timestamp = os:timestamp()
64 , node_id = erlang:node()
65 , snapshots = snapshots_new()
66 , deltas = deltas_new()
67 , totals_previous = TotalsPrevious
68 , totals_current = totals_new()
73 update(?T{totals_current=TotalsPrevious}) ->
80 { timestamp = Timestamp
85 , run_queue = RunQueue
89 { reductions = Reductions
93 { io_bytes_in = PreviousIOBytesIn
94 , io_bytes_out = PreviousIOBytesOut
95 , context_switches = PreviousContextSwitches
99 { io_bytes_in = CurrentIOBytesIn
100 , io_bytes_out = CurrentIOBytesOut
101 , context_switches = CurrentContextSwitches
106 { timestamp = Timestamp
109 , io_bytes_in = CurrentIOBytesIn - PreviousIOBytesIn
110 , io_bytes_out = CurrentIOBytesOut - PreviousIOBytesOut
111 , context_switches = CurrentContextSwitches - PreviousContextSwitches
112 , reductions = Reductions
113 , run_queue = RunQueue
118 { memory = erlang:memory()
119 , run_queue = erlang:statistics(run_queue)
123 {_ReductionsTotal, ReductionsDelta} = erlang:statistics(reductions),
125 { reductions = ReductionsDelta
129 { {input , IOBytesIn}
130 , {output , IOBytesOut}
131 } = erlang:statistics(io),
132 {ContextSwitches, 0} = erlang:statistics(context_switches),
134 { io_bytes_in = IOBytesIn
135 , io_bytes_out = IOBytesOut
136 , context_switches = ContextSwitches
143 , context_switches = 0