GC per-process reductions deltas table for dead PIDs
authorSiraaj Khandkar <siraaj@khandkar.net>
Sun, 27 Sep 2015 23:05:59 +0000 (19:05 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Sun, 27 Sep 2015 23:05:59 +0000 (19:05 -0400)
src/beam_stats_delta.erl
src/beam_stats_producer.erl
src/beam_stats_source.erl
test/beam_stats_consumer_statsd_SUITE.erl

index 45cfdb0..8820d71 100644 (file)
@@ -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}) ->
index dd52692..e27f9a3 100644 (file)
@@ -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() ->
index eb0d7d1..1cba827 100644 (file)
@@ -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().
 
index ac21f7a..b59ff53 100644 (file)
@@ -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,
This page took 0.031799 seconds and 4 git commands to generate.