Skip to content

Instantly share code, notes, and snippets.

@archie
Created July 15, 2009 14:34
Show Gist options
  • Save archie/147767 to your computer and use it in GitHub Desktop.
Save archie/147767 to your computer and use it in GitHub Desktop.
do_set_trace_flags(Tracer,Args,How) ->
Fun=fun({Proc,Flags}) ->
case check_traceflag_pidspec(Proc) of
{ok,Proc2} -> % Reg-names converted.
case check_flags(Flags) of
Flags2 when is_list(Flags2) -> % No error!
case (catch
case How of
true ->
erlang:trace(Proc2,
true,
[{tracer,Tracer}|Flags2]);
false -> % No tracer of turning off.
erlang:trace(Proc2,
false,
Flags2)
end) of
N when is_integer(N) ->
N;
{'EXIT',Reason} ->
if
is_pid(Proc2) ->
0; % Proc2 not alive or not at this node!
true -> % Otherwise, just error!
{error,
{bad_trace_args,
[Reason,Proc2,How,Flags2,Tracer]}}
end
end;
FlagError ->
FlagError
end;
false -> % Skip it.
0; % Indicate that zero processes matched.
{error,Reason} -> % Bad process specification.
{error,{bad_process,[Reason,Proc]}}
end;
(Faulty) ->
{error,{bad_process,Faulty}}
end,
{ok,lists:map(Fun,Args)}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment