Skip to content

Commit fad0674

Browse files
authored
gh-150258: Show relative percentage on Tachyon flamegraph (#150266)
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.
1 parent b0a149a commit fad0674

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

Lib/profiling/sampling/_flamegraph_assets/flamegraph.js

Lines changed: 12 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.min(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">Relative Percentage:</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;
@@ -629,6 +639,7 @@ function renderFlamegraph(chart, data) {
629639
d3.select("#chart").datum(data).call(chart);
630640
window.flamegraphChart = chart;
631641
window.flamegraphData = data;
642+
zoomedNodeValue = null;
632643
populateStats(data);
633644
}
634645

@@ -1269,6 +1280,7 @@ function filterDataByThread(data, threadId) {
12691280

12701281
function resetZoom() {
12711282
if (window.flamegraphChart) {
1283+
zoomedNodeValue = null;
12721284
window.flamegraphChart.resetZoom();
12731285
}
12741286
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update the tooltip on the Tachyon flame graph to show both absolute and relative percentages.

0 commit comments

Comments
 (0)