Skip to content

Commit 26b4f18

Browse files
Add label field to root nodes for module-name toggle
1 parent eee3ce4 commit 26b4f18

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Lib/profiling/sampling/stack_collector.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,11 @@ def convert_children(children, min_samples, path_info):
309309
# If we only have one root child, make it the root to avoid redundant level
310310
if len(root_children) == 1:
311311
main_child = root_children[0]
312-
# Update the name to indicate it's the program root
312+
# Update name and label to indicate it's the program root
313313
old_name = self._string_table.get_string(main_child["name"])
314-
new_name = f"Program Root: {old_name}"
315-
main_child["name"] = self._string_table.intern(new_name)
314+
main_child["name"] = self._string_table.intern(f"Program Root: {old_name}")
315+
old_label = self._string_table.get_string(main_child["label"])
316+
main_child["label"] = self._string_table.intern(f"Program Root: {old_label}")
316317
main_child["stats"] = {
317318
**self.stats,
318319
"thread_stats": thread_stats,
@@ -323,8 +324,10 @@ def convert_children(children, min_samples, path_info):
323324
main_child["opcode_mapping"] = opcode_mapping
324325
return main_child
325326

327+
program_root_idx = self._string_table.intern("Program Root")
326328
return {
327-
"name": self._string_table.intern("Program Root"),
329+
"name": program_root_idx,
330+
"label": program_root_idx,
328331
"value": total_samples,
329332
"children": root_children,
330333
"stats": {

Lib/test/test_profiling/test_sampling_profiler/test_collectors.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,8 @@ def test_flamegraph_collector_basic(self):
436436
name = resolve_name(data, strings)
437437
self.assertTrue(name.startswith("Program Root: "))
438438
self.assertIn("func2 (file:20)", name)
439+
label = strings[data["label"]]
440+
self.assertTrue(label.startswith("Program Root: "))
439441
self.assertEqual(data["self"], 0) # non-leaf: no self time
440442
children = data.get("children", [])
441443
self.assertEqual(len(children), 1)

0 commit comments

Comments
 (0)