Skip to content

Commit 7a11925

Browse files
committed
Fix child diff flamegraph args
The child process ends up being invoked with `--diff_flamegraph` instead of the correct argument.
1 parent 15d54fe commit 7a11925

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

Lib/profiling/sampling/cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ def _build_child_profiler_args(args):
160160
child_args.extend(["--mode", mode])
161161

162162
# Format options (skip pstats as it's the default)
163-
if args.format != "pstats":
163+
if args.format == "diff_flamegraph":
164+
child_args.extend(["--diff-flamegraph", args.diff_baseline])
165+
elif args.format != "pstats":
164166
child_args.append(f"--{args.format}")
165167

166168
return child_args

Lib/test/test_profiling/test_sampling_profiler/test_children.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,39 @@ def _wait_for_process_ready(proc, timeout):
109109
return proc.poll() is None
110110

111111

112+
@unittest.skipIf(
113+
_build_child_profiler_args is None,
114+
"profiling.sampling.cli unavailable",
115+
)
116+
class TestChildProfilerArgBuilder(unittest.TestCase):
117+
"""Tests for child profiler CLI argument construction."""
118+
119+
def test_build_child_profiler_args_diff_flamegraph(self):
120+
"""Test child args use the real --diff-flamegraph flag."""
121+
args = argparse.Namespace(
122+
sample_interval_usec=1000,
123+
duration=None,
124+
all_threads=False,
125+
realtime_stats=False,
126+
native=False,
127+
gc=True,
128+
opcodes=False,
129+
async_aware=False,
130+
mode="wall",
131+
format="diff_flamegraph",
132+
diff_baseline="baseline.bin",
133+
)
134+
135+
child_args = _build_child_profiler_args(args)
136+
137+
self.assertIn("--diff-flamegraph", child_args)
138+
self.assertNotIn("--diff_flamegraph", child_args)
139+
140+
flag_index = child_args.index("--diff-flamegraph")
141+
self.assertGreater(len(child_args), flag_index + 1)
142+
self.assertEqual(child_args[flag_index + 1], "baseline.bin")
143+
144+
112145
@requires_remote_subprocess_debugging()
113146
class TestGetChildPids(unittest.TestCase):
114147
"""Tests for the get_child_pids function."""

0 commit comments

Comments
 (0)