diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-06 17:32:24 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-06 17:32:24 +0200 |
| commit | 1561987330cb898f5ff64383a9c78e7e6559f118 (patch) | |
| tree | 69a823e8f98dce572566c97e6879c11c9d591bda /internal/flamegraph/nativejson.go | |
| parent | 96225fb6159212a8851043a08d781aba721b4e78 (diff) | |
| parent | 110a193e04b81abb8d8e159abd73f9f6ed1acd7e (diff) | |
Merge branch 'feat/bubbletea-v2-migration'
Diffstat (limited to 'internal/flamegraph/nativejson.go')
| -rw-r--r-- | internal/flamegraph/nativejson.go | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/internal/flamegraph/nativejson.go b/internal/flamegraph/nativejson.go deleted file mode 100644 index 088bcfc..0000000 --- a/internal/flamegraph/nativejson.go +++ /dev/null @@ -1,86 +0,0 @@ -package flamegraph - -import ( - "encoding/json" - "fmt" - "io" - "iter" - "os" - "strings" -) - -type jsonNode struct { - Name string `json:"name"` - Value uint64 `json:"value"` - Total uint64 `json:"total"` - Children []jsonNode `json:"children,omitempty"` -} - -type jsonFlamegraph struct { - Fields []string `json:"fields"` - CountField string `json:"countField"` - Root jsonNode `json:"root"` -} - -func (n NativeSVG) WriteJSONFromFile(iorDataFile string) (outFile string, err error) { - outFile = fmt.Sprintf("%s.%s-by-%s.json", - strings.TrimSuffix(iorDataFile, ".ior.zst"), - strings.Join(n.fields, ":"), - n.countField, - ) - defer func() { - if err != nil { - _ = os.Remove(outFile) - } - }() - - iod, err := newIorDataFromFile(iorDataFile) - if err != nil { - return outFile, fmt.Errorf("read ior data: %w", err) - } - - fd, err := os.Create(outFile) - if err != nil { - return outFile, fmt.Errorf("create output %s: %w", outFile, err) - } - defer fd.Close() - - if err := n.WriteJSONFromIter(iod.iter(), fd); err != nil { - return outFile, err - } - return outFile, nil -} - -func (n NativeSVG) WriteJSONFromIter(records iter.Seq[IterRecord], w io.Writer) error { - tr, err := n.buildTrieFromIter(records) - if err != nil { - return err - } - - payload := jsonFlamegraph{ - Fields: append([]string(nil), n.fields...), - CountField: n.countField, - Root: jsonNodeFromTrieNode(tr.root, "root"), - } - - enc := json.NewEncoder(w) - enc.SetIndent("", " ") - return enc.Encode(payload) -} - -func jsonNodeFromTrieNode(node *trieNode, name string) jsonNode { - out := jsonNode{ - Name: name, - Value: node.value, - Total: node.total, - } - if len(node.children) == 0 { - return out - } - - out.Children = make([]jsonNode, 0, len(node.children)) - for _, child := range node.children { - out.Children = append(out.Children, jsonNodeFromTrieNode(child, child.name)) - } - return out -} |
