X-Git-Url: https://git.xandkar.net/?p=beam_stats.git;a=blobdiff_plain;f=src%2Fbeam_stats_state.erl;h=17f9c904234bbb4d62c819ea1092e25dec608ff9;hp=552b5b15f859492a46f6b852493f1ffcb367eb02;hb=refs%2Ftags%2F0.3.0;hpb=b4e2333fc5fd9f32c8a0a39db4c6faacdbb15a91 diff --git a/src/beam_stats_state.erl b/src/beam_stats_state.erl index 552b5b1..17f9c90 100644 --- a/src/beam_stats_state.erl +++ b/src/beam_stats_state.erl @@ -16,10 +16,14 @@ { timestamp :: erlang:timestamp() , node_id :: atom() , memory :: [{atom(), non_neg_integer()}] + , previous_io_bytes_in :: non_neg_integer() , previous_io_bytes_out :: non_neg_integer() , current_io_bytes_in :: non_neg_integer() , current_io_bytes_out :: non_neg_integer() + + , previous_context_switches :: non_neg_integer() + , current_context_switches :: non_neg_integer() }). -define(T, #?MODULE). @@ -33,6 +37,7 @@ new() -> { {input , CurrentIOBytesIn} , {output , CurrentIOBytesOut} } = erlang:statistics(io), + {CurrentContextSwitches, 0} = erlang:statistics(context_switches), ?T { timestamp = os:timestamp() , node_id = erlang:node() @@ -41,6 +46,8 @@ new() -> , previous_io_bytes_out = 0 , current_io_bytes_in = CurrentIOBytesIn , current_io_bytes_out = CurrentIOBytesOut + , previous_context_switches = 0 + , current_context_switches = CurrentContextSwitches }. -spec update(t()) -> @@ -48,11 +55,13 @@ new() -> update(?T { previous_io_bytes_in = PreviousIOBytesIn , previous_io_bytes_out = PreviousIOBytesOut + , previous_context_switches = PreviousContextSwitches } ) -> { {input , CurrentIOBytesIn} , {output , CurrentIOBytesOut} } = erlang:statistics(io), + {CurrentContextSwitches, 0} = erlang:statistics(context_switches), ?T { timestamp = os:timestamp() , node_id = erlang:node() @@ -61,6 +70,8 @@ update(?T , previous_io_bytes_out = PreviousIOBytesOut , current_io_bytes_in = CurrentIOBytesIn , current_io_bytes_out = CurrentIOBytesOut + , previous_context_switches = PreviousContextSwitches + , current_context_switches = CurrentContextSwitches }. -spec export(t()) -> @@ -74,6 +85,8 @@ export( , previous_io_bytes_out = PreviousIOBytesOut , current_io_bytes_in = CurrentIOBytesIn , current_io_bytes_out = CurrentIOBytesOut + , previous_context_switches = PreviousContextSwitches + , current_context_switches = CurrentContextSwitches } ) -> #beam_stats @@ -82,4 +95,5 @@ export( , memory = Memory , io_bytes_in = CurrentIOBytesIn - PreviousIOBytesIn , io_bytes_out = CurrentIOBytesOut - PreviousIOBytesOut + , context_switches = CurrentContextSwitches - PreviousContextSwitches }.