Skip to content

Commit 2df7394

Browse files
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.
1 parent 4286227 commit 2df7394

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

Lib/profiling/sampling/_flamegraph_assets/flamegraph.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,11 +1063,7 @@ function populateStats(data) {
10631063
funcname = funcname || 'unknown';
10641064

10651065
if (filename !== 'unknown' && funcname !== 'unknown' && node.value > 0) {
1066-
let childrenValue = 0;
1067-
if (node.children) {
1068-
childrenValue = node.children.reduce((sum, child) => sum + child.value, 0);
1069-
}
1070-
const directSamples = Math.max(0, node.value - childrenValue);
1066+
const directSamples = node.self || 0;
10711067

10721068
const funcKey = `${filename}:${node.lineno || '?'}:${funcname}`;
10731069

@@ -1345,14 +1341,13 @@ function processLeaf(invertedRoot, path, leafNode, isDifferential) {
13451341
}
13461342

13471343
function traverseInvert(path, currentNode, invertedRoot, isDifferential) {
1348-
const children = currentNode.children || [];
1349-
const childThreads = new Set(children.flatMap(c => c.threads || []));
1350-
const selfThreads = (currentNode.threads || []).filter(t => !childThreads.has(t));
1344+
const selfValue = currentNode.self || 0;
13511345

1352-
if (selfThreads.length > 0) {
1353-
processLeaf(invertedRoot, path, { ...currentNode, threads: selfThreads }, isDifferential);
1346+
if (selfValue > 0) {
1347+
processLeaf(invertedRoot, path, { ...currentNode, value: selfValue }, isDifferential);
13541348
}
13551349

1350+
const children = currentNode.children || [];
13561351
children.forEach(child => traverseInvert(path.concat([child]), child, invertedRoot, isDifferential));
13571352
}
13581353

0 commit comments

Comments
 (0)