4040 server_all /0 , server_all /1 ,
4141 hierarchy /0 , hierarchy /1 ,
4242 code_reload /0 , code_reload /1 ,
43- code_load /0 , code_load /1
43+ code_load /0 , code_load /1 ,
44+ disable_trace /0 , disable_trace /1
4445]).
4546
4647-include_lib (" stdlib/include/assert.hrl" ).
@@ -53,6 +54,7 @@ suite() ->
5354
5455all () ->
5556 [call_count_ad_hoc , % % Cannot be run in parallel
57+ disable_trace , % % Cannot be run in parallel
5658 {group , all }].
5759
5860groups () ->
@@ -209,6 +211,48 @@ int_to_bin_twice(M) ->
209211 B = integer_to_binary (M ),
210212 <<B /binary , B /binary >>.
211213
214+ disable_trace () ->
215+ [{doc , " Test `disable_trace` does not continue tracing" }].
216+
217+ disable_trace (_Config ) when is_list (_Config ) ->
218+ ok = disable_trace (new ),
219+ ok = disable_trace (existing ),
220+ true ;
221+ disable_trace (new = Trace ) ->
222+ {ok , TracePid } = tprof :start (#{type => call_memory , session => Trace }),
223+ tprof :set_pattern (TracePid , lists , '_' , '_' ),
224+ tprof :enable_trace (TracePid , Trace , #{set_on_spawn => true }),
225+
226+ Pid = spawn (fun () -> lists :sum (lists :seq (1 , 5000 )) end ),
227+ timer :sleep (100 ),
228+
229+ tprof :disable_trace (TracePid , Trace , #{set_on_spawn => true }),
230+ _ = spawn (fun () -> lists :sum (lists :seq (1 , 5000 )) end ),
231+ timer :sleep (100 ),
232+
233+ Result = tprof :collect (TracePid ),
234+ tprof :stop (TracePid ),
235+
236+ Expected = tprof :inspect (Result , process , percent ),
237+ ? assertMatch ([Pid ], maps :keys (Expected ));
238+ disable_trace (existing = Trace ) ->
239+ {ok , TracePid } = tprof :start (#{type => call_memory , session => Trace }),
240+ tprof :set_pattern (TracePid , lists , '_' , '_' ),
241+ tprof :enable_trace (TracePid , Trace , #{set_on_spawn => false }),
242+
243+ Pid = spawn (fun () -> lists :sum (lists :seq (1 , 5000 )) end ),
244+ timer :sleep (100 ),
245+
246+ tprof :disable_trace (TracePid , Trace , #{set_on_spawn => false }),
247+
248+ {call_memory , Result } = tprof :collect (TracePid ),
249+ tprof :stop (TracePid ),
250+
251+ MatchingPids = lists :flatmap (fun ({_ , _ , _ , L }) -> [P || {P , _ , _ } <- L , P == Pid ] end , Result ),
252+ ? assertMatch (0 , length (Result )),
253+ ? assertMatch ([], MatchingPids ).
254+
255+
212256% % Ensure total is not truncated,
213257% % as per https://github.com/erlang/otp/issues/8139
214258call_memory_total (_Config ) ->
0 commit comments