Skip to content
Merged
Prev Previous commit
Next Next commit
Fix opcode merging in inverted flamegraph view
                                                                                                                                                           Opcodes from multiple call paths were silently dropped, only the
first path's opcodes were kept. Now they're summed correctly when
nodes merge.
  • Loading branch information
ivonastojanovic committed Mar 29, 2026
commit c0d937f83fd842b49ab94d07a54fe5fd7e99772e
11 changes: 10 additions & 1 deletion Lib/profiling/sampling/_flamegraph_assets/flamegraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ function accumulateInvertedNode(parent, stackFrame, leaf, isDifferential) {
lineno: stackFrame.lineno,
funcname: stackFrame.funcname,
source: stackFrame.source,
opcodes: stackFrame.opcodes,
opcodes: null,
threads: new Set()
};

Expand All @@ -1296,6 +1296,15 @@ function accumulateInvertedNode(parent, stackFrame, leaf, isDifferential) {
if (leaf.threads) {
leaf.threads.forEach(t => node.threads.add(t));
}
if (stackFrame.opcodes) {
if (!node.opcodes) {
node.opcodes = { ...stackFrame.opcodes };
} else {
for (const [op, count] of Object.entries(stackFrame.opcodes)) {
node.opcodes[op] = (node.opcodes[op] || 0) + count;
}
}
}

if (isDifferential) {
node.baseline += stackFrame.baseline || 0;
Expand Down
Loading