Add reductions delta.
[beam_stats.git] / src / beam_stats_state.erl
index 552b5b1..4dcadd6 100644 (file)
     { 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()
+
+    , reductions                :: non_neg_integer()
     }).
 
 -define(T, #?MODULE).
@@ -33,6 +39,8 @@ new() ->
     { {input  , CurrentIOBytesIn}
     , {output , CurrentIOBytesOut}
     } = erlang:statistics(io),
+    {CurrentContextSwitches, 0} = erlang:statistics(context_switches),
+    {_ReductionsTotal, ReductionsDelta} = erlang:statistics(reductions),
     ?T
     { timestamp             = os:timestamp()
     , node_id               = erlang:node()
@@ -41,6 +49,9 @@ new() ->
     , previous_io_bytes_out = 0
     , current_io_bytes_in   = CurrentIOBytesIn
     , current_io_bytes_out  = CurrentIOBytesOut
+    , previous_context_switches = 0
+    ,  current_context_switches = CurrentContextSwitches
+    , reductions                = ReductionsDelta
     }.
 
 -spec update(t()) ->
@@ -48,11 +59,14 @@ 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),
+    {_ReductionsTotal, ReductionsDelta} = erlang:statistics(reductions),
     ?T
     { timestamp             = os:timestamp()
     , node_id               = erlang:node()
@@ -61,6 +75,9 @@ 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
+    , reductions                = ReductionsDelta
     }.
 
 -spec export(t()) ->
@@ -74,6 +91,9 @@ export(
     , previous_io_bytes_out = PreviousIOBytesOut
     , current_io_bytes_in   = CurrentIOBytesIn
     , current_io_bytes_out  = CurrentIOBytesOut
+    , previous_context_switches = PreviousContextSwitches
+    ,  current_context_switches = CurrentContextSwitches
+    , reductions                = Reductions
     }
 ) ->
     #beam_stats
@@ -82,4 +102,6 @@ export(
     , memory       = Memory
     , io_bytes_in  = CurrentIOBytesIn  - PreviousIOBytesIn
     , io_bytes_out = CurrentIOBytesOut - PreviousIOBytesOut
+    , context_switches = CurrentContextSwitches - PreviousContextSwitches
+    , reductions       = Reductions
     }.
This page took 0.02184 seconds and 4 git commands to generate.