1 -module(beam_stats_state).
3 -include("include/beam_stats.hrl").
4 -include("include/beam_stats_process.hrl").
5 -include("include/beam_stats_processes.hrl").
18 { memory :: [{atom(), non_neg_integer()}]
19 , processes :: beam_stats_processes:t()
20 , run_queue :: non_neg_integer()
21 , ets :: beam_stats_ets:t()
28 { reductions :: non_neg_integer()
35 { io_bytes_in :: non_neg_integer()
36 , io_bytes_out :: non_neg_integer()
37 , context_switches :: non_neg_integer()
44 { timestamp :: erlang:timestamp()
46 , snapshots :: snapshots() % Current state
47 , deltas :: deltas() % Accumulated since last check
48 , totals_previous :: totals() % Accumulated since VM start, as of last state
49 , totals_current :: totals() % Accumulated since VM start, as of this state
60 TotalsPrevious = totals_empty(),
63 -spec new(TotalsPrevious :: totals()) ->
65 new(#totals{}=TotalsPrevious) ->
67 { timestamp = os:timestamp()
68 , node_id = erlang:node()
69 , snapshots = snapshots_new()
70 , deltas = deltas_new()
71 , totals_previous = TotalsPrevious
72 , totals_current = totals_new()
77 update(?T{totals_current=TotalsPrevious}) ->
84 { timestamp = Timestamp
89 , processes = Processes
90 , run_queue = RunQueue
95 { reductions = Reductions
99 { io_bytes_in = PreviousIOBytesIn
100 , io_bytes_out = PreviousIOBytesOut
101 , context_switches = PreviousContextSwitches
105 { io_bytes_in = CurrentIOBytesIn
106 , io_bytes_out = CurrentIOBytesOut
107 , context_switches = CurrentContextSwitches
112 { timestamp = Timestamp
115 , io_bytes_in = CurrentIOBytesIn - PreviousIOBytesIn
116 , io_bytes_out = CurrentIOBytesOut - PreviousIOBytesOut
117 , context_switches = CurrentContextSwitches - PreviousContextSwitches
118 , reductions = Reductions
119 , run_queue = RunQueue
121 , processes = Processes
126 { memory = erlang:memory()
127 , processes = beam_stats_processes:collect()
128 , run_queue = erlang:statistics(run_queue)
129 , ets = beam_stats_ets:collect()
133 {_ReductionsTotal, ReductionsDelta} = erlang:statistics(reductions),
135 { reductions = ReductionsDelta
139 { {input , IOBytesIn}
140 , {output , IOBytesOut}
141 } = erlang:statistics(io),
142 {ContextSwitches, 0} = erlang:statistics(context_switches),
144 { io_bytes_in = IOBytesIn
145 , io_bytes_out = IOBytesOut
146 , context_switches = ContextSwitches
153 , context_switches = 0