https://github.com/python/cpython/commit/993e204ad44fd95ac522a7903f83a4bbe5d3af9c
commit: 993e204ad44fd95ac522a7903f83a4bbe5d3af9c
branch: main
author: ivonastojanovic <[email protected]>
committer: pablogsal <[email protected]>
date: 2026-04-28T17:42:21+01:00
summary:
gh-142927: Fix inverted flamegraph width (#148568)
Fix inverted flamegraph width
The inverted view used thread presence as a proxy for self time.
This missed self samples on C-level wrapper frames like _run_code,
where the node's thread always appears in its children too. Those
samples were silently dropped, causing the chart to render narrower
than full width. Now uses the explicit self field on each node
instead of the thread heuristic.
files:
M Lib/profiling/sampling/_flamegraph_assets/flamegraph.js
diff --git a/Lib/profiling/sampling/_flamegraph_assets/flamegraph.js
b/Lib/profiling/sampling/_flamegraph_assets/flamegraph.js
index d7a8890d4a1ad9..3f884c4c690fd1 100644
--- a/Lib/profiling/sampling/_flamegraph_assets/flamegraph.js
+++ b/Lib/profiling/sampling/_flamegraph_assets/flamegraph.js
@@ -1063,11 +1063,7 @@ function populateStats(data) {
funcname = funcname || 'unknown';
if (filename !== 'unknown' && funcname !== 'unknown' && node.value > 0) {
- let childrenValue = 0;
- if (node.children) {
- childrenValue = node.children.reduce((sum, child) => sum +
child.value, 0);
- }
- const directSamples = Math.max(0, node.value - childrenValue);
+ const directSamples = node.self || 0;
const funcKey = `${filename}:${node.lineno || '?'}:${funcname}`;
@@ -1345,14 +1341,13 @@ function processLeaf(invertedRoot, path, leafNode,
isDifferential) {
}
function traverseInvert(path, currentNode, invertedRoot, isDifferential) {
- const children = currentNode.children || [];
- const childThreads = new Set(children.flatMap(c => c.threads || []));
- const selfThreads = (currentNode.threads || []).filter(t =>
!childThreads.has(t));
+ const selfValue = currentNode.self || 0;
- if (selfThreads.length > 0) {
- processLeaf(invertedRoot, path, { ...currentNode, threads: selfThreads },
isDifferential);
+ if (selfValue > 0) {
+ processLeaf(invertedRoot, path, { ...currentNode, value: selfValue },
isDifferential);
}
+ const children = currentNode.children || [];
children.forEach(child => traverseInvert(path.concat([child]), child,
invertedRoot, isDifferential));
}
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]