Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
slicklash committed Jun 19, 2024
1 parent 755fc4e commit 4c6b6b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions tests/test_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#

import logging
import time
from threading import Event
from typing import Dict, cast

Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 4c6b6b3

Please sign in to comment.