|
|
@ -15,7 +15,7 @@ |
|
|
|
|
|
|
|
-spec trace(userInput()) -> ok. |
|
|
|
trace(Input) -> |
|
|
|
trace(Input, tpTracerConsole). |
|
|
|
trace(Input, tpTracerShell). |
|
|
|
|
|
|
|
-spec trace(userInput(), module()) -> ok. |
|
|
|
trace(Input, TracerMod) -> |
|
|
@ -33,23 +33,19 @@ trace(Input, TracerMod, TracerOpts, TraceOpts) when is_list(Input) -> |
|
|
|
do_trace(InputList, TracerMod, TracerOpts, TraceOpts) -> |
|
|
|
_ = application:ensure_all_started(eTpf), |
|
|
|
|
|
|
|
%% Start the pool of tracer processes. |
|
|
|
PoolID = maps:get(poolId, TraceOpts, ?eTpfPoolId), |
|
|
|
PoolSize = maps:get(poolSize, TraceOpts, erlang:system_info(schedulers)), |
|
|
|
true = PoolSize > 0, |
|
|
|
{ok, PoolPid} = supervisor:start_child(eTpf_sup, #{ |
|
|
|
id => PoolID, |
|
|
|
start => {tpTracerPool, start_link, [PoolSize, TracerMod, TracerOpts]}, |
|
|
|
TracerId = maps:get(tracerId, TraceOpts, ?eTpfTracerId), |
|
|
|
{ok, TracerPid} = supervisor:start_child(eTpf_sup, #{ |
|
|
|
id => TracerId, |
|
|
|
start => {TracerMod, start_link, [TracerOpts]}, |
|
|
|
restart => temporary, |
|
|
|
type => supervisor |
|
|
|
type => worker |
|
|
|
}), |
|
|
|
Tracers = tpTracerPool:tracers(PoolPid), |
|
|
|
TracersMap = maps:from_list(lists:zip(lists:seq(0, length(Tracers) - 1), Tracers)), |
|
|
|
|
|
|
|
Mode = maps:get(mode, TraceOpts, trace), |
|
|
|
Tem0InputList = flattenInput(InputList, []), |
|
|
|
Tem1InputList = ensurePattern(Tem0InputList), |
|
|
|
LastInputList = ensureScope(Tem1InputList), |
|
|
|
traceInput(LastInputList, #{mode => Mode, tracers => TracersMap}, TraceOpts), |
|
|
|
traceInput(LastInputList, {Mode, TracerPid}, TraceOpts), |
|
|
|
ok. |
|
|
|
|
|
|
|
flattenInput([], Acc) -> |
|
|
@ -111,11 +107,7 @@ traceInput([Mod | Tail], TracerState, TraceOpts) when is_atom(Mod) -> |
|
|
|
traceInput(Tail, TracerState, TraceOpts). |
|
|
|
|
|
|
|
stop() -> |
|
|
|
stop(?eTpfPoolId). |
|
|
|
|
|
|
|
%% @todo Confirm that we don't need to stop tracing, |
|
|
|
%% that just terminating the tracers is enough. The |
|
|
|
%% NIF does cancel traces when tracers go away, but |
|
|
|
%% better make sure. |
|
|
|
stop(PoolID) -> |
|
|
|
supervisor:terminate_child(eTpf_sup, PoolID). |
|
|
|
stop(?eTpfTracerId). |
|
|
|
|
|
|
|
stop(TracerId) -> |
|
|
|
supervisor:terminate_child(eTpf_sup, TracerId). |