summaryrefslogtreecommitdiff
path: root/internal/flamegraph/livetrie_test.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_test.go
parent1530bf2856bbb32a6e0457596b55c07f3836a0ec (diff)
feat(tui): add flamegraph bytes metric toggle
Diffstat (limited to 'internal/flamegraph/livetrie_test.go')
-rw-r--r--internal/flamegraph/livetrie_test.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/internal/flamegraph/livetrie_test.go b/internal/flamegraph/livetrie_test.go
index 71f645c..53bdf1f 100644
--- a/internal/flamegraph/livetrie_test.go
+++ b/internal/flamegraph/livetrie_test.go
@@ -223,6 +223,54 @@ func TestLiveTrieReconfigureRejectsInvalidFields(t *testing.T) {
}
}
+func TestLiveTrieSetCountFieldSwitchesMetricAndResetsBaseline(t *testing.T) {
+ lt := NewLiveTrie([]string{"comm"}, "count")
+ lt.Ingest(newTestPair("svc", 42, 1001, "/tmp/a", 10, 1, 64))
+
+ initial := decodeLiveSnapshot(t, lt)
+ if got, want := initial.Total, uint64(1); got != want {
+ t.Fatalf("count snapshot total = %d, want %d", got, want)
+ }
+
+ if err := lt.SetCountField("bytes"); err != nil {
+ t.Fatalf("set count field: %v", err)
+ }
+ if got, want := lt.CountField(), "bytes"; got != want {
+ t.Fatalf("count field = %q, want %q", got, want)
+ }
+
+ empty := decodeLiveSnapshot(t, lt)
+ if got := empty.Total; got != 0 {
+ t.Fatalf("expected reset baseline after metric switch, total=%d", got)
+ }
+
+ lt.Ingest(newTestPair("svc", 42, 1002, "/tmp/b", 10, 1, 64))
+ bytesSnap := decodeLiveSnapshot(t, lt)
+ if got, want := bytesSnap.Total, uint64(64); got != want {
+ t.Fatalf("bytes snapshot total = %d, want %d", got, want)
+ }
+ leaf := findSnapshotPath(t, &bytesSnap, "svc")
+ if got, want := leaf.Total, uint64(64); got != want {
+ t.Fatalf("bytes leaf total = %d, want %d", got, want)
+ }
+}
+
+func TestLiveTrieSetCountFieldRejectsInvalidValue(t *testing.T) {
+ lt := NewLiveTrie([]string{"comm"}, "count")
+ lt.Ingest(newTestPair("svc", 42, 1001, "/tmp/a", 1, 1, 1))
+ beforeVersion := lt.Version()
+
+ if err := lt.SetCountField("bogus"); err == nil {
+ t.Fatalf("expected invalid count field error")
+ }
+ if got, want := lt.CountField(), "count"; got != want {
+ t.Fatalf("count field changed unexpectedly: got %q want %q", got, want)
+ }
+ if got := lt.Version(); got != beforeVersion {
+ t.Fatalf("version changed on invalid count field: got %d want %d", got, beforeVersion)
+ }
+}
+
func TestLiveTrieSnapshotJSONCaching(t *testing.T) {
lt := NewLiveTrie([]string{"comm"}, "count")
lt.Ingest(newTestPair("svc", 42, 1001, "/tmp/a", 1, 1, 1))