Skip to content
Permalink
Browse files
better cleanup
  • Loading branch information
bartekgorny committed Jul 25, 2018
1 parent 7da6555 commit 7e736d7a3a1403121d7633973296e870eaf25afd
Showing 3 changed files with 22 additions and 23 deletions.
@@ -13,6 +13,7 @@
term_to_port/1,
time_map/5, time_fold/6,
scheduler_usage_diff/2,
maybe_kill/1,
sublist_top_n_attrs/2,
format_trace_output/1, format_trace_output/2]).
%% private exports
@@ -264,6 +265,16 @@ format_trace_output(true, Args) when is_list(Args) ->
format_trace_output(_, Args) ->
io_lib:format("~p", [Args]).

maybe_kill(Name) ->
case whereis(Name) of
undefined ->
ok;
Pid ->
unlink(Pid),
exit(Pid, kill),
wait_for_death(Pid, Name)
end.

%%%%%%%%%%%%%%%
%%% PRIVATE %%%
%%%%%%%%%%%%%%%
@@ -301,4 +312,12 @@ merge_pairs([]) -> [];
merge_pairs([H]) -> H;
merge_pairs([A, B|T]) -> merge(merge(A, B), merge_pairs(T)).

wait_for_death(Pid, Name) ->
case is_process_alive(Pid) orelse whereis(Name) =:= Pid of
true ->
timer:sleep(10),
wait_for_death(Pid, Name);
false ->
ok
end.

@@ -56,8 +56,7 @@ clear(Module) ->

%% @doc remove all imported definitions, destroy the table, clean up
clear() ->
catch ets:delete_all_objects(ets_table_name()),
catch whereis(recon_ets) ! stop,
recon_lib:maybe_kill(recon_ets),
ok.

%% @doc prints out all "known" (imported) record definitions and their limit settings.
@@ -219,8 +219,8 @@ clear() ->
erlang:trace(all, false, [all]),
erlang:trace_pattern({'_','_','_'}, false, [local,meta,call_count,call_time]),
erlang:trace_pattern({'_','_','_'}, false, []), % unsets global
maybe_kill(recon_trace_tracer),
maybe_kill(recon_trace_formatter),
recon_lib:maybe_kill(recon_trace_tracer),
recon_lib:maybe_kill(recon_trace_formatter),
ok.

%% @equiv calls({Mod, Fun, Args}, Max, [])
@@ -607,25 +607,6 @@ format_args(Args) when is_list(Args) ->
%%% HELPERS %%%
%%%%%%%%%%%%%%%

maybe_kill(Name) ->
case whereis(Name) of
undefined ->
ok;
Pid ->
unlink(Pid),
exit(Pid, kill),
wait_for_death(Pid, Name)
end.

wait_for_death(Pid, Name) ->
case is_process_alive(Pid) orelse whereis(Name) =:= Pid of
true ->
timer:sleep(10),
wait_for_death(Pid, Name);
false ->
ok
end.

%% Borrowed from dbg
fun_to_ms(ShellFun) when is_function(ShellFun) ->
case erl_eval:fun_data(ShellFun) of

0 comments on commit 7e736d7

Please sign in to comment.