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
6061all () ->
6162 [call_count_ad_hoc , % % Cannot be run in parallel
63+ disable_trace , % % Cannot be run in parallel
6264 {group , all }].
6365
6466groups () ->
@@ -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
225269call_memory_total (_Config ) ->
0 commit comments