Skip to content

Commit 67583f6

Browse files
committed
Merge branch 'kiko/tools/fix-tprof-not-stopping-tracing/OTP-20302' into maint
* kiko/tools/fix-tprof-not-stopping-tracing/OTP-20302: tools: add test for disabling trace tools: fixes tprof not stopping tracing OTP-20302
2 parents 3f6555f + de91799 commit 67583f6

2 files changed

Lines changed: 47 additions & 3 deletions

File tree

lib/tools/src/tprof.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,8 +753,8 @@ disable_trace(Server, Spec, Options) ->
753753
disable_session_trace(Session, Procs) ->
754754
disable_session_trace(Session, Procs, default_trace_options()).
755755
disable_session_trace(Session, Procs, Options) when Procs =:= all;
756-
Procs =:= new_processes;
757-
Procs =:= existing_processes ->
756+
Procs =:= new;
757+
Procs =:= existing ->
758758
trace:process(Session, Procs, false, trace_options(Options));
759759
disable_session_trace(Session, {Children, PidOrName}, Options) when Children =:= children;
760760
Children =:= all_children ->

lib/tools/test/tprof_SUITE.erl

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
server_all/0, server_all/1,
4747
hierarchy/0, hierarchy/1,
4848
code_reload/0, code_reload/1,
49-
code_load/0, code_load/1
49+
code_load/0, code_load/1,
50+
disable_trace/0, disable_trace/1
5051
]).
5152

5253
-include_lib("stdlib/include/assert.hrl").
@@ -59,6 +60,7 @@ suite() ->
5960

6061
all() ->
6162
[call_count_ad_hoc, %% Cannot be run in parallel
63+
disable_trace, %% Cannot be run in parallel
6264
{group, all}].
6365

6466
groups() ->
@@ -220,6 +222,48 @@ int_to_bin_twice(M) ->
220222
B = integer_to_binary(M),
221223
<<B/binary, B/binary>>.
222224

225+
disable_trace() ->
226+
[{doc, "Test `disable_trace` does not continue tracing"}].
227+
228+
disable_trace(_Config) when is_list(_Config) ->
229+
ok = disable_trace(new),
230+
ok = disable_trace(existing),
231+
true;
232+
disable_trace(new=Trace) ->
233+
{ok, TracePid} = tprof:start(#{type => call_memory, session => Trace}),
234+
tprof:set_pattern(TracePid, lists, '_', '_'),
235+
tprof:enable_trace(TracePid, Trace, #{set_on_spawn => true}),
236+
237+
Pid = spawn(fun () -> lists:sum(lists:seq(1, 5000)) end),
238+
timer:sleep(100),
239+
240+
tprof:disable_trace(TracePid, Trace, #{set_on_spawn => true}),
241+
_ = spawn(fun () -> lists:sum(lists:seq(1, 5000)) end),
242+
timer:sleep(100),
243+
244+
Result = tprof:collect(TracePid),
245+
tprof:stop(TracePid),
246+
247+
Expected = tprof:inspect(Result, process, percent),
248+
?assertMatch([Pid], maps:keys(Expected));
249+
disable_trace(existing=Trace) ->
250+
{ok, TracePid} = tprof:start(#{type => call_memory, session => Trace}),
251+
tprof:set_pattern(TracePid, lists, '_', '_'),
252+
tprof:enable_trace(TracePid, Trace, #{set_on_spawn => false}),
253+
254+
Pid = spawn(fun () -> lists:sum(lists:seq(1, 5000)) end),
255+
timer:sleep(100),
256+
257+
tprof:disable_trace(TracePid, Trace, #{set_on_spawn => false}),
258+
259+
{call_memory, Result} = tprof:collect(TracePid),
260+
tprof:stop(TracePid),
261+
262+
MatchingPids = lists:flatmap(fun ({_, _, _, L}) -> [P || {P, _, _} <- L, P == Pid] end, Result),
263+
?assertMatch(0, length(Result)),
264+
?assertMatch([], MatchingPids).
265+
266+
223267
%% Ensure total is not truncated,
224268
%% as per https://github.com/erlang/otp/issues/8139
225269
call_memory_total(_Config) ->

0 commit comments

Comments
 (0)