From 5f23af510bd9031c515f2a3cc495bd996c795e69 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 27 Feb 2026 18:52:23 +0200 Subject: flamegraph: add live baseline reset hotkey --- internal/flamegraph/livehtml.go | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'internal/flamegraph/livehtml.go') diff --git a/internal/flamegraph/livehtml.go b/internal/flamegraph/livehtml.go index 9531f85..8ca74cd 100644 --- a/internal/flamegraph/livehtml.go +++ b/internal/flamegraph/livehtml.go @@ -109,6 +109,7 @@ const liveHTML = ` + LIVE @@ -118,6 +119,7 @@ const liveHTML = ` (function () { var fg = { paused: false, + resetting: false, pendingData: null, searchQuery: '', zoomStack: [], @@ -133,6 +135,7 @@ const liveHTML = ` resetSearchBtn: document.getElementById('btn-reset-search'), undoZoomBtn: document.getElementById('btn-undo-zoom'), resetZoomBtn: document.getElementById('btn-reset-zoom'), + resetBaselineBtn: document.getElementById('btn-reset-baseline'), cfg: { width: 1200, frameHeight: 16, @@ -465,6 +468,39 @@ const liveHTML = ` } } + function fgClearLocalState() { + fg.pendingData = null; + fg.searchQuery = ''; + fg.zoomStack = []; + fg.zoomRange = null; + } + + function fgResetBaseline() { + if (fg.resetting) { + return; + } + fg.resetting = true; + fgSetStatus('resetting baseline...'); + fetch('/reset', { method: 'POST' }) + .then(function (resp) { + if (!resp.ok) { + throw new Error('reset failed'); + } + return resp.text(); + }) + .then(function (payload) { + fgClearLocalState(); + fgProcessUpdate(payload); + fgSetStatus('baseline reset'); + }) + .catch(function () { + fgSetStatus('reset failed'); + }) + .then(function () { + fg.resetting = false; + }); + } + function fgBindFrameEvents() { for (var i = 0; i < fg.frames.length; i++) { fg.frames[i].addEventListener('mouseenter', function () { fgHover(this); }); @@ -579,6 +615,11 @@ const liveHTML = ` fgSearch(); return; } + if (ev.key === 'r' || ev.key === 'R') { + ev.preventDefault(); + fgResetBaseline(); + return; + } if (ev.key === 'Escape') { ev.preventDefault(); fgResetZoom(); @@ -591,6 +632,7 @@ const liveHTML = ` fg.resetSearchBtn.addEventListener('click', fgResetSearch); fg.undoZoomBtn.addEventListener('click', fgUndoZoom); fg.resetZoomBtn.addEventListener('click', fgResetZoom); + fg.resetBaselineBtn.addEventListener('click', fgResetBaseline); document.addEventListener('keydown', fgHandleKeydown); fgSetStatus(''); @@ -608,6 +650,7 @@ const liveHTML = ` window.fgSearch = fgSearch; window.fgResetSearch = fgResetSearch; window.fgTogglePause = fgTogglePause; + window.fgResetBaseline = fgResetBaseline; window.liveFlamegraphState = fg; })(); -- cgit v1.2.3