Skip to content

Commit d58bad9

Browse files
committed
gh-150258: Show relative percentage on Tachyon flamegraph
When running profiling, users rarely care about the global percentage of the runtime. Often, they want to select a function and measure child percentages relative to that. This PR updates the flamegraph tooltips to show both "Percentage" and "Relative Percentage" when the user clicks a specific function. Fixes #150258
1 parent 1d28f9a commit d58bad9

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

Lib/profiling/sampling/_flamegraph_assets/flamegraph.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ let invertedData = null;
77
let currentThreadFilter = 'all';
88
let isInverted = false;
99
let useModuleNames = true;
10+
let zoomedNodeValue = null;
1011

1112
// Heat colors are now defined in CSS variables (--heat-1 through --heat-8)
1213
// and automatically switch with theme changes - no JS color arrays needed!
@@ -316,6 +317,7 @@ function createPythonTooltip(data) {
316317
const selfSamples = d.data.self || 0;
317318
const selfMs = (selfSamples / 1000).toFixed(2);
318319
const percentage = ((d.data.value / data.value) * 100).toFixed(2);
320+
const relativePercentage = Math.max(100, ((d.data.value / (zoomedNodeValue ?? data.value)) * 100)).toFixed(2);
319321
const calls = d.data.calls || 0;
320322
const childCount = d.children ? d.children.length : 0;
321323
const source = d.data.source;
@@ -439,6 +441,11 @@ function createPythonTooltip(data) {
439441
<span class="tooltip-stat-label">Percentage:</span>
440442
<span class="tooltip-stat-value accent">${percentage}%</span>
441443
444+
${relativePercentage !== percentage && relativePercentage !== "100.00" ? `
445+
<span class="tooltip-stat-label">% of Selection:</span>
446+
<span class="tooltip-stat-value accent">${relativePercentage}%</span>
447+
` : ''}
448+
442449
${calls > 0 ? `
443450
<span class="tooltip-stat-label">Function Calls:</span>
444451
<span class="tooltip-stat-value">${calls.toLocaleString()}</span>
@@ -620,6 +627,9 @@ function createFlamegraph(tooltip, rootValue, data) {
620627
const percentage = d.data.value / rootValue;
621628
const level = getHeatLevel(percentage);
622629
return heatColors[level];
630+
})
631+
.onClick(function (d) {
632+
zoomedNodeValue = d.data.value;
623633
});
624634

625635
return chart;
@@ -1269,6 +1279,7 @@ function filterDataByThread(data, threadId) {
12691279

12701280
function resetZoom() {
12711281
if (window.flamegraphChart) {
1282+
zoomedNodeValue = null;
12721283
window.flamegraphChart.resetZoom();
12731284
}
12741285
}

0 commit comments

Comments
 (0)