Skip to content

Commit f2ca704

Browse files
committed
tools: Test concurrent ad-hoc tprof sessions
Run two ad-hoc call-memory profiles with the same pattern. Verify that tearing down one session does not affect the other. Remove the ignored registered option from the existing coexistence test. Signed-off-by: ruslandoga <ruslandoga+gh@icloud.com>
1 parent 8ae46b1 commit f2ca704

1 file changed

Lines changed: 50 additions & 2 deletions

File tree

lib/tools/test/tprof_SUITE.erl

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
rootset/0, rootset/1,
4040
set_on_spawn/0, set_on_spawn/1, seq/1,
4141
separate_sessions/0, separate_sessions/1,
42+
concurrent_ad_hoc/0, concurrent_ad_hoc/1,
4243
live_trace/0, live_trace/1,
4344
patterns/0, patterns/1, pattern_fun/1, pattern_fun/2, pattern_fun/3,
4445
processes/0, processes/1,
@@ -67,7 +68,7 @@ groups() ->
6768
[{all, parallel(),
6869
[call_time_ad_hoc, call_memory_ad_hoc,
6970
call_memory_total, sort, rootset, set_on_spawn,
70-
code_load, code_reload, separate_sessions,
71+
code_load, code_reload, separate_sessions, concurrent_ad_hoc,
7172
{group, default_session},
7273
{group, custom_session}]},
7374
{default_session,[],session()},
@@ -383,6 +384,53 @@ separate_sessions(Config) when is_list(Config) ->
383384
?assert(lists:all(fun({lists, reverse, 1, _}) -> true; (_) -> false end, Profile1)),
384385
?assert(lists:all(fun({lists, map, 2, _}) -> true; (_) -> false end, Profile2)).
385386

387+
concurrent_ad_hoc() ->
388+
[{doc, "Tests overlapping ad-hoc profiles using the same trace pattern"}].
389+
390+
concurrent_ad_hoc(Config) when is_list(Config) ->
391+
Parent = self(),
392+
Ref = make_ref(),
393+
Start = fun(Tag) ->
394+
spawn_link(fun() ->
395+
Result = tprof:profile(
396+
fun() ->
397+
%% Reaching this point means that this profile's pattern and
398+
%% process trace have both been enabled.
399+
Parent ! {Ref, ready, Tag, self()},
400+
receive
401+
{Ref, run} ->
402+
_ = lists:seq(1, 32),
403+
done
404+
end
405+
end,
406+
#{pattern => {lists, seq_loop, 3}, report => return,
407+
set_on_spawn => false, type => call_memory}),
408+
Parent ! {Ref, result, Tag, Result}
409+
end)
410+
end,
411+
412+
_ = Start(first),
413+
_ = Start(second),
414+
Profiled1 = receive {Ref, ready, first, Pid1} -> Pid1 end,
415+
Profiled2 = receive {Ref, ready, second, Pid2} -> Pid2 end,
416+
417+
%% Complete and tear down the first session while the second is active.
418+
Profiled1 ! {Ref, run},
419+
First = receive {Ref, result, first, Result1} -> Result1 end,
420+
?assertMatch(
421+
{done, {call_memory,
422+
[{lists, seq_loop, 3, [{Profiled1, 9, 64}]}]}},
423+
First),
424+
?assert(is_process_alive(Profiled2)),
425+
426+
%% Destroying the first same-named trace session must not affect this one.
427+
Profiled2 ! {Ref, run},
428+
Second = receive {Ref, result, second, Result2} -> Result2 end,
429+
?assertMatch(
430+
{done, {call_memory,
431+
[{lists, seq_loop, 3, [{Profiled2, 9, 64}]}]}},
432+
Second).
433+
386434
live_trace() ->
387435
[{doc, "Tests memory tracing for pre-existing processes"}].
388436

@@ -517,7 +565,7 @@ server(Config) when is_list(Config) ->
517565

518566
%% test ad-hoc profiling can be done while running server-aided
519567
%% for that, profiler should have very specific pattern
520-
{_, AdHoc} = tprof:profile(lists, seq, [1, 32], #{registered => false, pattern => {lists, '_', '_'},
568+
{_, AdHoc} = tprof:profile(lists, seq, [1, 32], #{pattern => {lists, '_', '_'},
521569
report => return, type => call_memory}),
522570
%% check totals: must be 64 words allocated by a single lists:seq_loop
523571
?assertMatch(#{all := {call_memory, 64, [{lists, _, _, 64, _, _}]}},

0 commit comments

Comments
 (0)