Fix not-updated previous stats state values.
[beam_stats.git] / src / beam_stats_state.erl
index 17f9c90..1fd6e9d 100644 (file)
@@ -24,6 +24,9 @@
 
     , previous_context_switches :: non_neg_integer()
     ,  current_context_switches :: non_neg_integer()
+
+    , reductions                :: non_neg_integer()
+    , run_queue                 :: non_neg_integer()
     }).
 
 -define(T, #?MODULE).
@@ -38,6 +41,8 @@ new() ->
     , {output , CurrentIOBytesOut}
     } = erlang:statistics(io),
     {CurrentContextSwitches, 0} = erlang:statistics(context_switches),
+    {_ReductionsTotal, ReductionsDelta} = erlang:statistics(reductions),
+    RunQueue = erlang:statistics(run_queue),
     ?T
     { timestamp             = os:timestamp()
     , node_id               = erlang:node()
@@ -48,20 +53,24 @@ new() ->
     , current_io_bytes_out  = CurrentIOBytesOut
     , previous_context_switches = 0
     ,  current_context_switches = CurrentContextSwitches
+    , reductions                = ReductionsDelta
+    , run_queue                 = RunQueue
     }.
 
 -spec update(t()) ->
     t().
 update(?T
-    { previous_io_bytes_in  = PreviousIOBytesIn
-    , previous_io_bytes_out = PreviousIOBytesOut
-    , previous_context_switches = PreviousContextSwitches
+    { current_io_bytes_in      = PreviousIOBytesIn
+    , current_io_bytes_out     = PreviousIOBytesOut
+    , current_context_switches = PreviousContextSwitches
     }
 ) ->
     { {input  , CurrentIOBytesIn}
     , {output , CurrentIOBytesOut}
     } = erlang:statistics(io),
     {CurrentContextSwitches, 0} = erlang:statistics(context_switches),
+    {_ReductionsTotal, ReductionsDelta} = erlang:statistics(reductions),
+    RunQueue = erlang:statistics(run_queue),
     ?T
     { timestamp             = os:timestamp()
     , node_id               = erlang:node()
@@ -72,6 +81,8 @@ update(?T
     , current_io_bytes_out  = CurrentIOBytesOut
     , previous_context_switches = PreviousContextSwitches
     ,  current_context_switches = CurrentContextSwitches
+    , reductions                = ReductionsDelta
+    , run_queue                 = RunQueue
     }.
 
 -spec export(t()) ->
@@ -87,6 +98,8 @@ export(
     , current_io_bytes_out  = CurrentIOBytesOut
     , previous_context_switches = PreviousContextSwitches
     ,  current_context_switches = CurrentContextSwitches
+    , reductions                = Reductions
+    , run_queue                 = RunQueue
     }
 ) ->
     #beam_stats
@@ -96,4 +109,6 @@ export(
     , io_bytes_in  = CurrentIOBytesIn  - PreviousIOBytesIn
     , io_bytes_out = CurrentIOBytesOut - PreviousIOBytesOut
     , context_switches = CurrentContextSwitches - PreviousContextSwitches
+    , reductions       = Reductions
+    , run_queue        = RunQueue
     }.
This page took 0.031304 seconds and 4 git commands to generate.