From 340a6846743e4a861f3d7bd62d2ae428f40dfa22 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Date: Fri, 12 Dec 2025 15:06:28 +0000 Subject: [PATCH] gh-138122: Add docs button to Tachyon heatmap and flamegraph (#142614) --- .../sampling/_flamegraph_assets/flamegraph.js | 6 ++-- .../flamegraph_template.html | 31 +++++++++++++++++-- .../sampling/_heatmap_assets/heatmap.js | 6 ++-- .../sampling/_heatmap_assets/heatmap_index.js | 6 ++-- .../heatmap_index_template.html | 19 +++++++++++- .../heatmap_pyfile_template.html | 25 +++++++++++++-- Lib/profiling/sampling/heatmap_collector.py | 2 ++ Lib/profiling/sampling/stack_collector.py | 4 +++ 8 files changed, 87 insertions(+), 12 deletions(-) diff --git a/Lib/profiling/sampling/_flamegraph_assets/flamegraph.js b/Lib/profiling/sampling/_flamegraph_assets/flamegraph.js index fb8109452181..6345320bd255 100644 --- a/Lib/profiling/sampling/_flamegraph_assets/flamegraph.js +++ b/Lib/profiling/sampling/_flamegraph_assets/flamegraph.js @@ -92,7 +92,8 @@ function toggleTheme() { // Update theme button icon const btn = document.getElementById('theme-btn'); if (btn) { - btn.innerHTML = next === 'dark' ? '☼' : '☾'; // sun or moon + btn.querySelector('.icon-moon').style.display = next === 'dark' ? 'none' : ''; + btn.querySelector('.icon-sun').style.display = next === 'dark' ? '' : 'none'; } // Re-render flamegraph with new theme colors @@ -160,7 +161,8 @@ function restoreUIState() { document.documentElement.setAttribute('data-theme', savedTheme); const btn = document.getElementById('theme-btn'); if (btn) { - btn.innerHTML = savedTheme === 'dark' ? '☼' : '☾'; + btn.querySelector('.icon-moon').style.display = savedTheme === 'dark' ? 'none' : ''; + btn.querySelector('.icon-sun').style.display = savedTheme === 'dark' ? '' : 'none'; } } diff --git a/Lib/profiling/sampling/_flamegraph_assets/flamegraph_template.html b/Lib/profiling/sampling/_flamegraph_assets/flamegraph_template.html index 211296a70864..02855563f83f 100644 --- a/Lib/profiling/sampling/_flamegraph_assets/flamegraph_template.html +++ b/Lib/profiling/sampling/_flamegraph_assets/flamegraph_template.html @@ -39,18 +39,43 @@ class="toolbar-btn" onclick="resetZoom()" title="Reset zoom" - >⌂ + > + + + > + + + + + + > + + + diff --git a/Lib/profiling/sampling/_heatmap_assets/heatmap.js b/Lib/profiling/sampling/_heatmap_assets/heatmap.js index 038aa44b3df6..8ac4ef43e53b 100644 --- a/Lib/profiling/sampling/_heatmap_assets/heatmap.js +++ b/Lib/profiling/sampling/_heatmap_assets/heatmap.js @@ -24,7 +24,8 @@ function toggleTheme() { // Update theme button icon const btn = document.getElementById('theme-btn'); if (btn) { - btn.innerHTML = next === 'dark' ? '☼' : '☾'; // sun or moon + btn.querySelector('.icon-moon').style.display = next === 'dark' ? 'none' : ''; + btn.querySelector('.icon-sun').style.display = next === 'dark' ? '' : 'none'; } applyLineColors(); @@ -39,7 +40,8 @@ function restoreUIState() { document.documentElement.setAttribute('data-theme', savedTheme); const btn = document.getElementById('theme-btn'); if (btn) { - btn.innerHTML = savedTheme === 'dark' ? '☼' : '☾'; + btn.querySelector('.icon-moon').style.display = savedTheme === 'dark' ? 'none' : ''; + btn.querySelector('.icon-sun').style.display = savedTheme === 'dark' ? '' : 'none'; } } } diff --git a/Lib/profiling/sampling/_heatmap_assets/heatmap_index.js b/Lib/profiling/sampling/_heatmap_assets/heatmap_index.js index 4ddacca5173d..8eb6af0db533 100644 --- a/Lib/profiling/sampling/_heatmap_assets/heatmap_index.js +++ b/Lib/profiling/sampling/_heatmap_assets/heatmap_index.js @@ -28,7 +28,8 @@ function toggleTheme() { // Update theme button icon const btn = document.getElementById('theme-btn'); if (btn) { - btn.innerHTML = next === 'dark' ? '☼' : '☾'; // sun or moon + btn.querySelector('.icon-moon').style.display = next === 'dark' ? 'none' : ''; + btn.querySelector('.icon-sun').style.display = next === 'dark' ? '' : 'none'; } applyHeatmapBarColors(); @@ -41,7 +42,8 @@ function restoreUIState() { document.documentElement.setAttribute('data-theme', savedTheme); const btn = document.getElementById('theme-btn'); if (btn) { - btn.innerHTML = savedTheme === 'dark' ? '☼' : '☾'; + btn.querySelector('.icon-moon').style.display = savedTheme === 'dark' ? 'none' : ''; + btn.querySelector('.icon-sun').style.display = savedTheme === 'dark' ? '' : 'none'; } } } diff --git a/Lib/profiling/sampling/_heatmap_assets/heatmap_index_template.html b/Lib/profiling/sampling/_heatmap_assets/heatmap_index_template.html index 98996bdbf5ff..3620f8efb805 100644 --- a/Lib/profiling/sampling/_heatmap_assets/heatmap_index_template.html +++ b/Lib/profiling/sampling/_heatmap_assets/heatmap_index_template.html @@ -17,12 +17,29 @@ Heatmap Report
diff --git a/Lib/profiling/sampling/_heatmap_assets/heatmap_pyfile_template.html b/Lib/profiling/sampling/_heatmap_assets/heatmap_pyfile_template.html index 3fb6d3a6b91d..91b629b26282 100644 --- a/Lib/profiling/sampling/_heatmap_assets/heatmap_pyfile_template.html +++ b/Lib/profiling/sampling/_heatmap_assets/heatmap_pyfile_template.html @@ -17,14 +17,35 @@ diff --git a/Lib/profiling/sampling/heatmap_collector.py b/Lib/profiling/sampling/heatmap_collector.py index 45649ce2009b..5b4c89283be0 100644 --- a/Lib/profiling/sampling/heatmap_collector.py +++ b/Lib/profiling/sampling/heatmap_collector.py @@ -858,6 +858,7 @@ class HeatmapCollector(StackTraceCollector): "": f"", "": f"", "": self._template_loader.logo_html, + "": f"{sys.version_info.major}.{sys.version_info.minor}", "": str(len(file_stats)), "": f"{self._total_samples:,}", "": f"{self.stats.get('duration_sec', 0):.1f}s", @@ -915,6 +916,7 @@ class HeatmapCollector(StackTraceCollector): "": f"", "": f"", "": self._template_loader.logo_html, + "": f"{sys.version_info.major}.{sys.version_info.minor}", } html_content = self._template_loader.file_template diff --git a/Lib/profiling/sampling/stack_collector.py b/Lib/profiling/sampling/stack_collector.py index b7aa7f5ff82d..e437facd8bb9 100644 --- a/Lib/profiling/sampling/stack_collector.py +++ b/Lib/profiling/sampling/stack_collector.py @@ -5,6 +5,7 @@ import importlib.resources import json import linecache import os +import sys from ._css_utils import get_combined_css from .collector import Collector, extract_lineno @@ -393,6 +394,9 @@ class FlamegraphCollector(StackTraceCollector): # Let CSS control size; keep markup simple logo_html = f'