From de3405c275898c8cd528a636dbd40e1b685cfaa5 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 13 May 2026 14:41:28 +0300 Subject: use errgroup instead of WaitGroup for concurrent snapshot builders Replace sync.WaitGroup with errgroup.Group in buildSubSnapshots so errors from sub-builders (buildSyscallSnapshots, buildFileSnapshots, buildProcessSnapshots, buildHistogramSnapshot) are captured and propagated rather than silently dropped. Change Engine.Snapshot() to return (*Snapshot, error), update runtime.SnapshotSource and dashboard.SnapshotSource interfaces accordingly, and adjust all callers in tui.go, dashboard/model.go, and the test helpers. Each sub-builder now returns (result, error); the error return is currently always nil but establishes the contract for future validation. The per-type Snapshot() convenience methods (histogram, syscall, file, process) panic on error since they are internal helpers where failure would be a programming bug. Co-Authored-By: Claude Sonnet 4.6 --- internal/statsengine/filerank.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'internal/statsengine/filerank.go') diff --git a/internal/statsengine/filerank.go b/internal/statsengine/filerank.go index ef43c6e..a397381 100644 --- a/internal/statsengine/filerank.go +++ b/internal/statsengine/filerank.go @@ -93,12 +93,18 @@ func (r *fileRanker) Add(pair *event.Pair) { r.compactIfNeeded() } +// Snapshot returns a slice of FileSnapshots for all tracked files. +// It panics on build error, which should never happen for a valid ranker. func (r *fileRanker) Snapshot() []FileSnapshot { if r == nil { return nil } - return buildFileSnapshots(r.snapshotInputs()) + snap, err := buildFileSnapshots(r.snapshotInputs()) + if err != nil { + panic("buildFileSnapshots: " + err.Error()) + } + return snap } func (r *fileRanker) snapshotInputs() []fileSnapshotInput { @@ -119,7 +125,10 @@ func (r *fileRanker) snapshotInputs() []fileSnapshotInput { return inputs } -func buildFileSnapshots(inputs []fileSnapshotInput) []FileSnapshot { +// buildFileSnapshots converts raw file ranker inputs into sorted FileSnapshot +// slices. The error return is reserved for future validation; currently this +// function always succeeds. +func buildFileSnapshots(inputs []fileSnapshotInput) ([]FileSnapshot, error) { out := make([]FileSnapshot, 0, len(inputs)) for _, in := range inputs { out = append(out, in.toSnapshot()) @@ -130,7 +139,7 @@ func buildFileSnapshots(inputs []fileSnapshotInput) []FileSnapshot { } return cmp.Compare(a.Path, b.Path) }) - return out + return out, nil } func (r *fileRanker) addBytes(stats *fileRankStats, pair *event.Pair) { -- cgit v1.2.3