summaryrefslogtreecommitdiff
path: root/internal/flamegraph/livehtml.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-27 18:52:23 +0200
committerPaul Buetow <paul@buetow.org>2026-02-27 18:52:23 +0200
commit5f23af510bd9031c515f2a3cc495bd996c795e69 (patch)
tree151d94f6ffacf7446b72481d51f8f8925d5dee8d /internal/flamegraph/livehtml.go
parent3783d23b8d608c3bf4a2dedd6b4bfb9165439bed (diff)
flamegraph: add live baseline reset hotkey
Diffstat (limited to 'internal/flamegraph/livehtml.go')
-rw-r--r--internal/flamegraph/livehtml.go43
1 files changed, 43 insertions, 0 deletions
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 = `<!doctype html>
<button id="btn-reset-search" type="button">Reset Search</button>
<button id="btn-undo-zoom" type="button">Undo Zoom</button>
<button id="btn-reset-zoom" type="button">Reset Zoom</button>
+ <button id="btn-reset-baseline" type="button">Reset Baseline</button>
<span id="status">LIVE</span>
</div>
@@ -118,6 +119,7 @@ const liveHTML = `<!doctype html>
(function () {
var fg = {
paused: false,
+ resetting: false,
pendingData: null,
searchQuery: '',
zoomStack: [],
@@ -133,6 +135,7 @@ const liveHTML = `<!doctype html>
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 = `<!doctype html>
}
}
+ 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 = `<!doctype html>
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 = `<!doctype html>
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 = `<!doctype html>
window.fgSearch = fgSearch;
window.fgResetSearch = fgResetSearch;
window.fgTogglePause = fgTogglePause;
+ window.fgResetBaseline = fgResetBaseline;
window.liveFlamegraphState = fg;
})();
</script>