Update alignments.
[beam_stats.git] / src / beam_stats_delta.erl
index 45cfdb0..fae6c63 100644 (file)
@@ -7,6 +7,7 @@
 -export(
     [ start/0
     , stop/1
+    , gc/1
     , of_context_switches/1
     , of_io/1
     , of_reductions/1
@@ -31,7 +32,8 @@ start() ->
         , public
         ],
     ?T
-    { erlang_statistics = ets:new(beam_stats_delta_erlang_statistics, Options)
+    { erlang_statistics =
+        ets:new(beam_stats_delta_erlang_statistics, Options)
     , erlang_process_info_reductions =
         ets:new(beam_stats_delta_erlang_process_info_reductions, Options)
     }.
@@ -39,7 +41,7 @@ start() ->
 -spec stop(t()) ->
     {}.
 stop(?T
-    { erlang_statistics = TidErlangStatistics
+    { erlang_statistics              = TidErlangStatistics
     , erlang_process_info_reductions = TidErlangProcessInfoReductions
     }
 ) ->
@@ -47,6 +49,31 @@ 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) ->
+    Next = ets:next(Table, Pid),
+    case beam_stats_source:erlang_is_process_alive(Pid)
+    of  true  -> true
+    ;   false -> ets:delete(Table, Pid)
+    end,
+    case Next
+    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}) ->
This page took 0.02774 seconds and 4 git commands to generate.