-spec collect() ->
t().
collect() ->
- lists:map(fun beam_stats_ets_table:of_id/1, ets:all()).
+ TableIDs = beam_stats_source:ets_all(),
+ lists:map(fun beam_stats_ets_table:of_id/1, TableIDs).
-spec of_id(id()) ->
t().
of_id(ID) ->
- WordSize = erlang:system_info(wordsize),
- NumberOfWords = ets:info(ID, memory),
+ WordSize = beam_stats_source:erlang_system_info(wordsize),
+ NumberOfWords = beam_stats_source:ets_info(ID, memory),
NumberOfBytes = NumberOfWords * WordSize,
#?MODULE
{ id = ID
- , name = ets:info(ID, name)
- , size = ets:info(ID, size)
+ , name = beam_stats_source:ets_info(ID, name)
+ , size = beam_stats_source:ets_info(ID, size)
, memory = NumberOfBytes
}.
Value.
pid_info_opt(Pid, Key) ->
- case {Key, erlang:process_info(Pid, Key)}
+ case {Key, beam_stats_source:erlang_process_info(Pid, Key)}
of {registered_name, []} -> none
; {_ , {Key, Value}} -> {some, Value}
end.
-spec collect() ->
t().
collect() ->
- Ps = [beam_stats_process:of_pid(P) || P <- erlang:processes()],
+ Pids = beam_stats_source:erlang_processes(),
+ Ps = [beam_stats_process:of_pid(P) || P <- Pids],
?T
{ individual_stats
= Ps
, count_garbage_collecting
= length([P || P <- Ps, P#beam_stats_process.status =:= garbage_collecting])
, count_registered
- = length(registered())
+ = length(beam_stats_source:erlang_registered())
, count_runnable
= length([P || P <- Ps, P#beam_stats_process.status =:= runnable])
, count_running
--- /dev/null
+-module(beam_stats_source).
+
+-export(
+ [ erlang_memory/0
+ , erlang_node/0
+ , erlang_process_info/2
+ , erlang_processes/0
+ , erlang_registered/0
+ , erlang_statistics/1
+ , erlang_system_info/1
+ , ets_all/0
+ , ets_info/2
+ , os_timestamp/0
+ ]).
+
+erlang_memory() ->
+ erlang:memory().
+
+erlang_node() ->
+ erlang:node().
+
+erlang_process_info(Pid, Key) ->
+ erlang:process_info(Pid, Key).
+
+erlang_processes() ->
+ erlang:processes().
+
+erlang_registered() ->
+ erlang:registered().
+
+erlang_statistics(Key) ->
+ erlang:statistics(Key).
+
+erlang_system_info(Key) ->
+ erlang:system_info(Key).
+
+ets_all() ->
+ ets:all().
+
+ets_info(Table, Key) ->
+ ets:info(Table, Key).
+
+os_timestamp() ->
+ os:timestamp().
t().
new(#totals{}=TotalsPrevious) ->
?T
- { timestamp = os:timestamp()
- , node_id = erlang:node()
+ { timestamp = beam_stats_source:os_timestamp()
+ , node_id = beam_stats_source:erlang_node()
, snapshots = snapshots_new()
, deltas = deltas_new()
, totals_previous = TotalsPrevious
snapshots_new() ->
#snapshots
- { memory = erlang:memory()
+ { memory = beam_stats_source:erlang_memory()
, processes = beam_stats_processes:collect()
- , run_queue = erlang:statistics(run_queue)
+ , run_queue = beam_stats_source:erlang_statistics(run_queue)
, ets = beam_stats_ets:collect()
}.
deltas_new() ->
- {_ReductionsTotal, ReductionsDelta} = erlang:statistics(reductions),
+ {_ReductionsTotal, ReductionsDelta} = beam_stats_source:erlang_statistics(reductions),
#deltas
{ reductions = ReductionsDelta
}.
totals_new() ->
{ {input , IOBytesIn}
, {output , IOBytesOut}
- } = erlang:statistics(io),
- {ContextSwitches, 0} = erlang:statistics(context_switches),
+ } = beam_stats_source:erlang_statistics(io),
+ {ContextSwitches, 0} = beam_stats_source:erlang_statistics(context_switches),
#totals
{ io_bytes_in = IOBytesIn
, io_bytes_out = IOBytesOut