From: Siraaj Khandkar Date: Sun, 27 Sep 2015 21:07:30 +0000 (-0400) Subject: Manage global reductions delta ourselves X-Git-Tag: 0.14.3^2 X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=11e1cb97537476ce805262952a5c615000a6cf78;p=beam_stats.git Manage global reductions delta ourselves We can get between-calls-delta directly from erlang:statistics(reductions), but then if some other process also calls it - we'll get incorrect data on the next call. Managing deltas ourselves here, will at least reduce the possible callers to only those with knowledge of our table ID. --- diff --git a/src/beam_stats.app.src b/src/beam_stats.app.src index 9c8d943..4e49f59 100644 --- a/src/beam_stats.app.src +++ b/src/beam_stats.app.src @@ -1,7 +1,7 @@ {application, beam_stats, [ {description, "Periodic VM stats production and consumption."}, - {vsn, "0.14.2"}, + {vsn, "0.14.3"}, {registered, []}, {applications, [ kernel diff --git a/src/beam_stats.erl b/src/beam_stats.erl index af5167c..b3e445e 100644 --- a/src/beam_stats.erl +++ b/src/beam_stats.erl @@ -18,7 +18,6 @@ -spec collect(beam_stats_delta:t()) -> t(). collect(DeltasServer) -> - {_, DeltaOfReductions} = beam_stats_source:erlang_statistics(reductions), { {io_bytes_in , DeltaOfIOBytesIn} , {io_bytes_out , DeltaOfIOBytesOut} } = beam_stats_delta:of_io(DeltasServer), @@ -29,7 +28,7 @@ collect(DeltasServer) -> , io_bytes_in = DeltaOfIOBytesIn , io_bytes_out = DeltaOfIOBytesOut , context_switches = beam_stats_delta:of_context_switches(DeltasServer) - , reductions = DeltaOfReductions + , reductions = beam_stats_delta:of_reductions(DeltasServer) , run_queue = beam_stats_source:erlang_statistics(run_queue) , ets = beam_stats_ets:collect() , processes = beam_stats_processes:collect() diff --git a/src/beam_stats_delta.erl b/src/beam_stats_delta.erl index d563507..42f2399 100644 --- a/src/beam_stats_delta.erl +++ b/src/beam_stats_delta.erl @@ -9,6 +9,7 @@ , stop/1 , of_context_switches/1 , of_io/1 + , of_reductions/1 ]). -record(?MODULE, @@ -62,6 +63,18 @@ of_io(?T{erlang_statistics=Table}) -> , {io_bytes_out , DeltaOut} }. +% We can get between-calls-delta directly from erlang:statistics(reductions), +% but then if some other process also calls it - we'll get incorrect data on +% the next call. +% Managing deltas ourselves here, will at least reduce the possible callers to +% only those with knowledge of our table ID. +-spec of_reductions(t()) -> + non_neg_integer(). +of_reductions(?T{erlang_statistics=Table}) -> + Key = reductions, + {Current, _} = beam_stats_source:erlang_statistics(Key), + delta(Table, Key, Current). + -spec delta(ets:tid(), atom(), non_neg_integer()) -> non_neg_integer(). delta(Table, Key, CurrentTotal) -> diff --git a/test/beam_stats_consumer_statsd_SUITE.erl b/test/beam_stats_consumer_statsd_SUITE.erl index 88f82e7..a5b3779 100644 --- a/test/beam_stats_consumer_statsd_SUITE.erl +++ b/test/beam_stats_consumer_statsd_SUITE.erl @@ -60,6 +60,7 @@ t_full_cycle(_Cfg) -> [ {io_bytes_in , 6} , {io_bytes_out , 14} , {context_switches , 10} + , {reductions , 18} ] ), ct:log("meck_expect_beam_stats ok~n"), @@ -150,6 +151,7 @@ meck_expect_beam_stats(Overrides) -> IOBytesIn = hope_kv_list:get(Overrides, io_bytes_in , 3), IOBytesOut = hope_kv_list:get(Overrides, io_bytes_out, 7), ContextSwitches = hope_kv_list:get(Overrides, context_switches, 5), + Reductions = hope_kv_list:get(Overrides, reductions, 9), Pid0 = list_to_pid("<0.0.0>"), Pid1 = list_to_pid("<0.1.0>"), Pid2 = list_to_pid("<0.2.0>"), @@ -266,7 +268,7 @@ meck_expect_beam_stats(Overrides) -> meck:expect(beam_stats_source, erlang_statistics, fun (io ) -> {{input, IOBytesIn}, {output, IOBytesOut}} ; (context_switches) -> {ContextSwitches, 0} - ; (reductions ) -> {0, 9} % 1st element is unused + ; (reductions ) -> {Reductions, undefined} % 2nd element is unused ; (run_queue ) -> 17 end ),