Skip to content

Commit f20eb52

Browse files
committed
check if it works fine with (file, loc, func, op)
1 parent c183109 commit f20eb52

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Lib/test/test_profiling/test_sampling_profiler/test_collectors.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,6 +2467,38 @@ def test_gecko_collector_frame_format(self):
24672467
# Should have recorded 3 functions
24682468
self.assertEqual(thread["funcTable"]["length"], 3)
24692469

2470+
def test_jsonl_collector_frame_format(self):
2471+
"""Test JsonlCollector with 4-element frame format."""
2472+
collector = JsonlCollector(sample_interval_usec=1000)
2473+
collector.collect(self._make_sample_frames())
2474+
2475+
with tempfile.NamedTemporaryFile(delete=False) as f:
2476+
self.addClassCleanup(close_and_unlink, f)
2477+
collector.export(f.name)
2478+
2479+
with open(f.name, "r", encoding="utf-8") as fp:
2480+
records = [json.loads(line) for line in fp]
2481+
2482+
str_defs = {
2483+
item["str_id"]: item["value"]
2484+
for record in records
2485+
if record["type"] == "str_def"
2486+
for item in record["defs"]
2487+
}
2488+
frame_defs = [
2489+
item
2490+
for record in records
2491+
if record["type"] == "frame_def"
2492+
for item in record["defs"]
2493+
]
2494+
2495+
self.assertEqual(len(frame_defs), 3)
2496+
2497+
paths = {str_defs[item["path_str_id"]] for item in frame_defs}
2498+
funcs = {str_defs[item["func_str_id"]] for item in frame_defs}
2499+
2500+
self.assertEqual(paths, {"app.py", "utils.py", "lib.py"})
2501+
self.assertEqual(funcs, {"main", "helper", "process"})
24702502

24712503
class TestInternalFrameFiltering(unittest.TestCase):
24722504
"""Tests for filtering internal profiler frames from output."""

0 commit comments

Comments
 (0)