From: Siraaj Khandkar Date: Sun, 27 Sep 2015 23:05:59 +0000 (-0400) Subject: GC per-process reductions deltas table for dead PIDs X-Git-Tag: 0.15.0^2~3 X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=140077ceda11a34f4880fd2f4871b3aaab34f13d;p=beam_stats.git GC per-process reductions deltas table for dead PIDs --- diff --git a/src/beam_stats_delta.erl b/src/beam_stats_delta.erl index 45cfdb0..8820d71 100644 --- a/src/beam_stats_delta.erl +++ b/src/beam_stats_delta.erl @@ -7,6 +7,7 @@ -export( [ start/0 , stop/1 + , gc/1 , of_context_switches/1 , of_io/1 , of_reductions/1 @@ -47,6 +48,30 @@ stop(?T true = ets:delete(TidErlangProcessInfoReductions), {}. +-spec gc(t()) -> + {}. +gc(?T{erlang_process_info_reductions=Table}=T) -> + case ets:first(Table) + of '$end_of_table' -> + {} + ; FirstPid when is_pid(FirstPid) -> + gc(T, FirstPid) + end. + +-spec gc(t(), pid()) -> + {}. +gc(?T{erlang_process_info_reductions=Table}=T, Pid) -> + case beam_stats_source:erlang_is_process_alive(Pid) + of true -> true + ; false -> ets:delete(Table, Pid) + end, + case ets:next(Table, Pid) + of '$end_of_table' -> + {} + ; NextPid when is_pid(NextPid) -> + gc(T, NextPid) + end. + -spec of_context_switches(t()) -> non_neg_integer(). of_context_switches(?T{erlang_statistics=Table}) -> diff --git a/src/beam_stats_producer.erl b/src/beam_stats_producer.erl index dd52692..e27f9a3 100644 --- a/src/beam_stats_producer.erl +++ b/src/beam_stats_producer.erl @@ -122,6 +122,7 @@ produce( ConsumersList = ordsets:to_list(ConsumersSet), Send = fun (Consumer) -> MsgSendFun(Consumer, Stats) end, ok = lists:foreach(Send, ConsumersList), + beam_stats_delta:gc(DeltasServer), State. -spec schedule_first_production() -> diff --git a/src/beam_stats_source.erl b/src/beam_stats_source.erl index eb0d7d1..1cba827 100644 --- a/src/beam_stats_source.erl +++ b/src/beam_stats_source.erl @@ -1,7 +1,8 @@ -module(beam_stats_source). -export( - [ erlang_memory/0 + [ erlang_is_process_alive/1 + , erlang_memory/0 , erlang_node/0 , erlang_process_info/2 , erlang_processes/0 @@ -13,6 +14,9 @@ , os_timestamp/0 ]). +erlang_is_process_alive(Pid) -> + erlang:is_process_alive(Pid). + erlang_memory() -> erlang:memory(). diff --git a/test/beam_stats_consumer_statsd_SUITE.erl b/test/beam_stats_consumer_statsd_SUITE.erl index ac21f7a..b59ff53 100644 --- a/test/beam_stats_consumer_statsd_SUITE.erl +++ b/test/beam_stats_consumer_statsd_SUITE.erl @@ -264,6 +264,8 @@ meck_expect_beam_stats(Overrides) -> , size = 8 , memory = 64 }, + meck:expect(beam_stats_source, erlang_is_process_alive, + fun (_) -> true end), meck:expect(beam_stats_source, erlang_memory, fun () -> [{mem_type_foo, 1}, {mem_type_bar, 2}, {mem_type_baz, 3}] end), meck:expect(beam_stats_source, erlang_node,