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/syscall.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/syscall.go')
| -rw-r--r-- | internal/statsengine/syscall.go | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/internal/statsengine/syscall.go b/internal/statsengine/syscall.go index 2ef929a..d58e8c9 100644 --- a/internal/statsengine/syscall.go +++ b/internal/statsengine/syscall.go @@ -99,12 +99,18 @@ func (a *syscallAccumulator) Add(pair *event.Pair) { } } +// Snapshot returns a slice of SyscallSnapshots for all tracked syscalls. +// It panics on build error, which should never happen for a valid accumulator. func (a *syscallAccumulator) Snapshot(elapsed time.Duration) []SyscallSnapshot { if a == nil { return nil } - return buildSyscallSnapshots(a.snapshotInputs(), elapsed) + snap, err := buildSyscallSnapshots(a.snapshotInputs(), elapsed) + if err != nil { + panic("buildSyscallSnapshots: " + err.Error()) + } + return snap } func (a *syscallAccumulator) snapshotInputs() []syscallSnapshotInput { @@ -132,7 +138,10 @@ func (a *syscallAccumulator) snapshotInputs() []syscallSnapshotInput { return inputs } -func buildSyscallSnapshots(inputs []syscallSnapshotInput, elapsed time.Duration) []SyscallSnapshot { +// buildSyscallSnapshots converts raw syscall accumulator inputs into sorted +// SyscallSnapshot slices. The error return is reserved for future validation; +// currently this function always succeeds. +func buildSyscallSnapshots(inputs []syscallSnapshotInput, elapsed time.Duration) ([]SyscallSnapshot, error) { rateDiv := elapsed.Seconds() result := make([]SyscallSnapshot, 0, len(inputs)) for _, in := range inputs { @@ -144,7 +153,7 @@ func buildSyscallSnapshots(inputs []syscallSnapshotInput, elapsed time.Duration) } return cmp.Compare(a.Name, b.Name) }) - return result + return result, nil } func (s *syscallStats) updateMinMax(duration uint64) { |
