diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-24 12:18:54 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-24 12:18:54 +0200 |
| commit | bd3c53086a3fe3ac177f4c656d1e521a2f0595b1 (patch) | |
| tree | 4a1ecc4b62842c6483a939c157c6a4fb5e440cf7 /internal/statsengine/process_test.go | |
| parent | 76468727f1ef06caefd8fc8c48cf1a12aa414035 (diff) | |
statsengine: compact process accumulator at high cardinality
Diffstat (limited to 'internal/statsengine/process_test.go')
| -rw-r--r-- | internal/statsengine/process_test.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/internal/statsengine/process_test.go b/internal/statsengine/process_test.go index add5ae1..aa3c5d2 100644 --- a/internal/statsengine/process_test.go +++ b/internal/statsengine/process_test.go @@ -115,6 +115,35 @@ func TestProcessAccumulatorNilInputs(t *testing.T) { } } +func TestProcessAccumulatorCompactsHighCardinality(t *testing.T) { + acc := newProcessAccumulatorWithLimits(2, 4) + + for i := 0; i < 5; i++ { + acc.Add(newProcessPair(10, "hot-a", 10, 1)) + } + for i := 0; i < 4; i++ { + acc.Add(newProcessPair(20, "hot-b", 10, 1)) + } + acc.Add(newProcessPair(1, "cold-1", 10, 1)) + acc.Add(newProcessPair(2, "cold-2", 10, 1)) + acc.Add(newProcessPair(3, "cold-3", 10, 1)) + + if got := len(acc.byPID); got != 2 { + t.Fatalf("expected compaction to keep topN processes, got %d entries", got) + } + if acc.byPID[10] == nil || acc.byPID[20] == nil { + t.Fatalf("expected hot pids to survive compaction") + } + + snap := acc.Snapshot(time.Second) + if len(snap) != 2 { + t.Fatalf("expected 2 rows after compaction, got %d", len(snap)) + } + if snap[0].PID != 10 || snap[1].PID != 20 { + t.Fatalf("unexpected rank order after compaction: %+v", snap) + } +} + func newProcessPair(pid uint32, comm string, duration uint64, bytes uint64) *event.Pair { return &event.Pair{ EnterEv: &types.RetEvent{Pid: pid}, |
