https://github.com/python/cpython/commit/6f993631501eef77ab4bad6a4f9b5ea1f6351c89
commit: 6f993631501eef77ab4bad6a4f9b5ea1f6351c89
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: pablogsal <[email protected]>
date: 2026-05-23T15:30:19Z
summary:

[3.15] gh-150258: Show relative percentage on Tachyon flamegraph (GH-150266) 
(#150312)

gh-150258: Show relative percentage on Tachyon flamegraph (GH-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.
(cherry picked from commit fad06746051f6bd95a255d49e38ebf049e965109)

Co-authored-by: Eduardo Villalpando Mello <[email protected]>

files:
A Misc/NEWS.d/next/Tools-Demos/2026-05-22-18-51-09.gh-issue-150258.dh8GVK.rst
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 1611bf754424c13..840acf2c27d1201 100644
--- a/Lib/profiling/sampling/_flamegraph_assets/flamegraph.js
+++ b/Lib/profiling/sampling/_flamegraph_assets/flamegraph.js
@@ -7,6 +7,7 @@ let invertedData = null;
 let currentThreadFilter = 'all';
 let isInverted = false;
 let useModuleNames = true;
+let zoomedNodeValue = null;
 
 // Heat colors are now defined in CSS variables (--heat-1 through --heat-8)
 // and automatically switch with theme changes - no JS color arrays needed!
@@ -316,6 +317,7 @@ function createPythonTooltip(data) {
     const selfSamples = d.data.self || 0;
     const selfMs = (selfSamples / 1000).toFixed(2);
     const percentage = ((d.data.value / data.value) * 100).toFixed(2);
+    const relativePercentage = Math.min(100, ((d.data.value / (zoomedNodeValue 
?? data.value)) * 100)).toFixed(2);
     const calls = d.data.calls || 0;
     const childCount = d.children ? d.children.length : 0;
     const source = d.data.source;
@@ -439,6 +441,11 @@ function createPythonTooltip(data) {
         <span class="tooltip-stat-label">Percentage:</span>
         <span class="tooltip-stat-value accent">${percentage}%</span>
 
+        ${relativePercentage != percentage && relativePercentage != "100.00" ? 
`
+          <span class="tooltip-stat-label">Relative Percentage:</span>
+          <span class="tooltip-stat-value accent">${relativePercentage}%</span>
+        ` : ''}
+
         ${calls > 0 ? `
           <span class="tooltip-stat-label">Function Calls:</span>
           <span class="tooltip-stat-value">${calls.toLocaleString()}</span>
@@ -620,6 +627,9 @@ function createFlamegraph(tooltip, rootValue, data) {
       const percentage = d.data.value / rootValue;
       const level = getHeatLevel(percentage);
       return heatColors[level];
+    })
+    .onClick(function (d) {
+      zoomedNodeValue = d.data.value;
     });
 
   return chart;
@@ -629,6 +639,7 @@ function renderFlamegraph(chart, data) {
   d3.select("#chart").datum(data).call(chart);
   window.flamegraphChart = chart;
   window.flamegraphData = data;
+  zoomedNodeValue = null;
   populateStats(data);
 }
 
@@ -1269,6 +1280,7 @@ function filterDataByThread(data, threadId) {
 
 function resetZoom() {
   if (window.flamegraphChart) {
+    zoomedNodeValue = null;
     window.flamegraphChart.resetZoom();
   }
 }
diff --git 
a/Misc/NEWS.d/next/Tools-Demos/2026-05-22-18-51-09.gh-issue-150258.dh8GVK.rst 
b/Misc/NEWS.d/next/Tools-Demos/2026-05-22-18-51-09.gh-issue-150258.dh8GVK.rst
new file mode 100644
index 000000000000000..02cad6c4f53d928
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Tools-Demos/2026-05-22-18-51-09.gh-issue-150258.dh8GVK.rst
@@ -0,0 +1 @@
+Update the tooltip on the Tachyon flame graph to show both absolute and 
relative percentages.

_______________________________________________
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]

Reply via email to