Skip to content

Commit 350ad99

Browse files
committed
filter out sync coordinator
1 parent 546ce90 commit 350ad99

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

Lib/test/test_profiling/test_sampling_profiler/test_collectors.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,3 +2627,54 @@ def test_collapsed_stack_collector_filters_internal_frames(self):
26272627
for (call_tree, _), _ in collector.stack_counter.items():
26282628
for filename, _, _ in call_tree:
26292629
self.assertNotIn("_sync_coordinator", filename)
2630+
2631+
def test_jsonl_collector_filters_internal_frames(self):
2632+
"""Test that JsonlCollector filters out internal frames."""
2633+
jsonl_out = tempfile.NamedTemporaryFile(delete=False)
2634+
self.addCleanup(close_and_unlink, jsonl_out)
2635+
2636+
collector = JsonlCollector(sample_interval_usec=1000)
2637+
2638+
frames = [
2639+
MockInterpreterInfo(
2640+
0,
2641+
[
2642+
MockThreadInfo(
2643+
1,
2644+
[
2645+
MockFrameInfo("app.py", 50, "run"),
2646+
MockFrameInfo("/lib/_sync_coordinator.py", 100, "main"),
2647+
MockFrameInfo("<frozen runpy>", 87, "_run_code"),
2648+
],
2649+
status=THREAD_STATUS_HAS_GIL,
2650+
)
2651+
],
2652+
)
2653+
]
2654+
2655+
collector.collect(frames)
2656+
collector.export(jsonl_out.name)
2657+
2658+
with open(jsonl_out.name, "r", encoding="utf-8") as f:
2659+
records = [json.loads(line) for line in f]
2660+
2661+
str_defs = {
2662+
item["str_id"]: item["value"]
2663+
for record in records
2664+
if record["type"] == "str_def"
2665+
for item in record["defs"]
2666+
}
2667+
frame_defs = [
2668+
item
2669+
for record in records
2670+
if record["type"] == "frame_def"
2671+
for item in record["defs"]
2672+
]
2673+
2674+
paths = {str_defs[item["path_str_id"]] for item in frame_defs}
2675+
2676+
self.assertIn("app.py", paths)
2677+
self.assertIn("<frozen runpy>", paths)
2678+
2679+
for path in paths:
2680+
self.assertNotIn("_sync_coordinator", path)

0 commit comments

Comments
 (0)