1 -module(beam_stats_state).
3 -include("include/beam_stats.hrl").
16 { memory :: [{atom(), non_neg_integer()}]
17 , run_queue :: non_neg_integer()
18 , ets :: beam_stats_ets:t()
25 { reductions :: non_neg_integer()
32 { io_bytes_in :: non_neg_integer()
33 , io_bytes_out :: non_neg_integer()
34 , context_switches :: non_neg_integer()
41 { timestamp :: erlang:timestamp()
43 , snapshots :: snapshots() % Current state
44 , deltas :: deltas() % Accumulated since last check
45 , totals_previous :: totals() % Accumulated since VM start, as of last state
46 , totals_current :: totals() % Accumulated since VM start, as of this state
57 TotalsPrevious = totals_empty(),
60 -spec new(TotalsPrevious :: totals()) ->
62 new(#totals{}=TotalsPrevious) ->
64 { timestamp = os:timestamp()
65 , node_id = erlang:node()
66 , snapshots = snapshots_new()
67 , deltas = deltas_new()
68 , totals_previous = TotalsPrevious
69 , totals_current = totals_new()
74 update(?T{totals_current=TotalsPrevious}) ->
81 { timestamp = Timestamp
86 , run_queue = RunQueue
91 { reductions = Reductions
95 { io_bytes_in = PreviousIOBytesIn
96 , io_bytes_out = PreviousIOBytesOut
97 , context_switches = PreviousContextSwitches
101 { io_bytes_in = CurrentIOBytesIn
102 , io_bytes_out = CurrentIOBytesOut
103 , context_switches = CurrentContextSwitches
108 { timestamp = Timestamp
111 , io_bytes_in = CurrentIOBytesIn - PreviousIOBytesIn
112 , io_bytes_out = CurrentIOBytesOut - PreviousIOBytesOut
113 , context_switches = CurrentContextSwitches - PreviousContextSwitches
114 , reductions = Reductions
115 , run_queue = RunQueue
121 { memory = erlang:memory()
122 , run_queue = erlang:statistics(run_queue)
123 , ets = beam_stats_ets:collect()
127 {_ReductionsTotal, ReductionsDelta} = erlang:statistics(reductions),
129 { reductions = ReductionsDelta
133 { {input , IOBytesIn}
134 , {output , IOBytesOut}
135 } = erlang:statistics(io),
136 {ContextSwitches, 0} = erlang:statistics(context_switches),
138 { io_bytes_in = IOBytesIn
139 , io_bytes_out = IOBytesOut
140 , context_switches = ContextSwitches
147 , context_switches = 0