summaryrefslogtreecommitdiff
path: root/internal/flamegraph/liveserver.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/liveserver.go
parent3783d23b8d608c3bf4a2dedd6b4bfb9165439bed (diff)
flamegraph: add live baseline reset hotkey
Diffstat (limited to 'internal/flamegraph/liveserver.go')
-rw-r--r--internal/flamegraph/liveserver.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/internal/flamegraph/liveserver.go b/internal/flamegraph/liveserver.go
index 6b9a72b..5790cb0 100644
--- a/internal/flamegraph/liveserver.go
+++ b/internal/flamegraph/liveserver.go
@@ -12,6 +12,7 @@ func ServeLive(ctx context.Context, lt *LiveTrie, interval time.Duration) error
mux := http.NewServeMux()
mux.HandleFunc("/", handleLivePage())
mux.HandleFunc("/events", handleSSE(lt, interval))
+ mux.HandleFunc("/reset", handleReset(lt))
srv := &http.Server{Handler: mux}
listener, err := listenRandomPort()
@@ -96,6 +97,21 @@ func handleSSE(lt *LiveTrie, interval time.Duration) http.HandlerFunc {
}
}
+func handleReset(lt *LiveTrie) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ if r.Method != http.MethodPost {
+ w.Header().Set("Allow", http.MethodPost)
+ http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
+ return
+ }
+
+ lt.Reset()
+ payload, _ := lt.SnapshotJSON()
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write(payload)
+ }
+}
+
func sendSnapshot(w http.ResponseWriter, flusher http.Flusher, lt *LiveTrie, lastVersion uint64) (uint64, error) {
payload, version := lt.SnapshotJSON()
if version == lastVersion {