summaryrefslogtreecommitdiff
path: root/internal/flamegraph/livetrie.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-06 15:21:01 +0200
committerPaul Buetow <paul@buetow.org>2026-03-06 15:21:01 +0200
commit4ff17c30120d657b966f8a55188ba167dc875e64 (patch)
tree62737caf6b8e7411c2437dd995d3de5ce6aeca99 /internal/flamegraph/livetrie.go
parent1530bf2856bbb32a6e0457596b55c07f3836a0ec (diff)
feat(tui): add flamegraph bytes metric toggle
Diffstat (limited to 'internal/flamegraph/livetrie.go')
-rw-r--r--internal/flamegraph/livetrie.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/internal/flamegraph/livetrie.go b/internal/flamegraph/livetrie.go
index 13d7de9..9f1fd91 100644
--- a/internal/flamegraph/livetrie.go
+++ b/internal/flamegraph/livetrie.go
@@ -42,6 +42,9 @@ type LiveTrie struct {
// NewLiveTrie constructs an empty live trie with the configured frame/count fields.
func NewLiveTrie(fields []string, countField string) *LiveTrie {
+ if !isLiveTrieCountField(countField) {
+ countField = "count"
+ }
return &LiveTrie{
root: &trieNode{
childMap: make(map[string]*trieNode),
@@ -123,6 +126,33 @@ func (lt *LiveTrie) Fields() []string {
return out
}
+// CountField returns the active metric used to aggregate node values.
+func (lt *LiveTrie) CountField() string {
+ lt.mu.RLock()
+ field := lt.countField
+ lt.mu.RUnlock()
+ return field
+}
+
+// SetCountField changes the active aggregation metric and starts a new baseline.
+func (lt *LiveTrie) SetCountField(countField string) error {
+ field := strings.TrimSpace(countField)
+ if !isLiveTrieCountField(field) {
+ return fmt.Errorf("invalid count field %q", countField)
+ }
+
+ lt.mu.Lock()
+ if lt.countField == field {
+ lt.mu.Unlock()
+ return nil
+ }
+ lt.countField = field
+ lt.resetLocked()
+ lt.mu.Unlock()
+ lt.invalidateCache()
+ return nil
+}
+
// Reconfigure changes frame fields and clears accumulated data for a new baseline.
func (lt *LiveTrie) Reconfigure(fields []string) error {
normalized, err := normalizeLiveTrieFields(fields)
@@ -239,6 +269,15 @@ func isLiveTrieField(field string) bool {
}
}
+func isLiveTrieCountField(field string) bool {
+ switch field {
+ case "count", "duration", "durationToPrev", "bytes":
+ return true
+ default:
+ return false
+ }
+}
+
func subtreeTotal(node *trieNode) uint64 {
total := node.value
for _, child := range node.children {