diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-13 14:41:28 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-13 14:41:28 +0300 |
| commit | de3405c275898c8cd528a636dbd40e1b685cfaa5 (patch) | |
| tree | 53711959800677aa694e18331476add24a21b8ef /internal/statsengine/filerank.go | |
| parent | d392eebe5bd127e1573734321b0cabaad4182d7c (diff) | |
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 <noreply@anthropic.com>
Diffstat (limited to 'internal/statsengine/filerank.go')
| -rw-r--r-- | internal/statsengine/filerank.go | 15 |
1 files changed, 12 insertions, 3 deletions
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) { |
