|
39 | 39 | rootset/0, rootset/1, |
40 | 40 | set_on_spawn/0, set_on_spawn/1, seq/1, |
41 | 41 | separate_sessions/0, separate_sessions/1, |
| 42 | + concurrent_ad_hoc/0, concurrent_ad_hoc/1, |
42 | 43 | live_trace/0, live_trace/1, |
43 | 44 | patterns/0, patterns/1, pattern_fun/1, pattern_fun/2, pattern_fun/3, |
44 | 45 | processes/0, processes/1, |
@@ -67,7 +68,7 @@ groups() -> |
67 | 68 | [{all, parallel(), |
68 | 69 | [call_time_ad_hoc, call_memory_ad_hoc, |
69 | 70 | 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, |
71 | 72 | {group, default_session}, |
72 | 73 | {group, custom_session}]}, |
73 | 74 | {default_session,[],session()}, |
@@ -383,6 +384,53 @@ separate_sessions(Config) when is_list(Config) -> |
383 | 384 | ?assert(lists:all(fun({lists, reverse, 1, _}) -> true; (_) -> false end, Profile1)), |
384 | 385 | ?assert(lists:all(fun({lists, map, 2, _}) -> true; (_) -> false end, Profile2)). |
385 | 386 |
|
| 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 | + |
386 | 434 | live_trace() -> |
387 | 435 | [{doc, "Tests memory tracing for pre-existing processes"}]. |
388 | 436 |
|
@@ -517,7 +565,7 @@ server(Config) when is_list(Config) -> |
517 | 565 |
|
518 | 566 | %% test ad-hoc profiling can be done while running server-aided |
519 | 567 | %% 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, '_', '_'}, |
521 | 569 | report => return, type => call_memory}), |
522 | 570 | %% check totals: must be 64 words allocated by a single lists:seq_loop |
523 | 571 | ?assertMatch(#{all := {call_memory, 64, [{lists, _, _, 64, _, _}]}}, |
|
0 commit comments