diff --git a/tests/test_perf.py b/tests/test_perf.py index 04b144a05..cbdb62f2b 100644 --- a/tests/test_perf.py +++ b/tests/test_perf.py @@ -15,6 +15,7 @@ # import logging +import time from threading import Event from typing import Dict, cast @@ -144,6 +145,7 @@ def test_perf_comm_change( I'm not sure it can be done, i.e is this info even kept anywhere). """ with system_profiler as profiler: + time.sleep(2) # first run - we get the changed name, because the app started before perf began recording. _assert_comm_in_profile(profiler, application_pid, False) @@ -170,6 +172,7 @@ def test_perf_thread_comm_is_process_comm( starts after perf, the exec comm of the process should be used (see test_perf_comm_change) """ with system_profiler as profiler: + time.sleep(2) # running perf & script now with --show-task-events would show: # pative 1925947 [010] 987095.272656: PERF_RECORD_COMM: pative:1925904/1925947 # our perf will prefer to use the exec comm, OR oldest comm available if exec diff --git a/tests/utils.py b/tests/utils.py index 73aa8c5cf..b1203dd66 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -206,15 +206,17 @@ def assert_ldd_version_container(container: Container, version: str) -> None: def snapshot_pid_profile(profiler: ProfilerInterface, pid: int) -> ProfileData: - last_snapshot = None + last_snapshot = profiler.snapshot() def has_profile() -> bool: nonlocal last_snapshot + if pid in last_snapshot: + return True last_snapshot = profiler.snapshot() return pid in last_snapshot - wait_event(timeout=5, stop_event=Event(), condition=has_profile, interval=1) - return last_snapshot[pid] # type: ignore + wait_event(timeout=5, stop_event=Event(), condition=has_profile, interval=0.1) + return last_snapshot[pid] def snapshot_pid_collapsed(profiler: ProfilerInterface, pid: int) -> StackToSampleCount: