From f92382c20193a5366d15c7347dcc8ed2743f3b85 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 3 Mar 2026 13:00:38 +0200 Subject: Add WASM-ready flamegraph JSON export --- internal/flamegraph/nativesvg.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'internal/flamegraph/nativesvg.go') diff --git a/internal/flamegraph/nativesvg.go b/internal/flamegraph/nativesvg.go index 8a2bcd5..80061b4 100644 --- a/internal/flamegraph/nativesvg.go +++ b/internal/flamegraph/nativesvg.go @@ -58,18 +58,26 @@ func (n NativeSVG) WriteSVGFromFile(iorDataFile string) (outFile string, err err } func (n NativeSVG) WriteSVGFromIter(records iter.Seq[IterRecord], w io.Writer) error { + tr, err := n.buildTrieFromIter(records) + if err != nil { + return err + } + return WriteSVG(w, tr, n.config) +} + +func (n NativeSVG) buildTrieFromIter(records iter.Seq[IterRecord]) (*trie, error) { tr := newTrie() var framesBuf []string for record := range records { frames, err := n.recordFrames(record, framesBuf) if err != nil { - return err + return nil, err } framesBuf = frames tr.add(frames, record.Cnt.ValueByName(n.countField)) } tr.computeTotals() - return WriteSVG(w, tr, n.config) + return tr, nil } func (n NativeSVG) recordFrames(record IterRecord, framesBuf []string) ([]string, error) { -- cgit v1.2.3