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/histogram.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/histogram.go')
| -rw-r--r-- | internal/statsengine/histogram.go | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/internal/statsengine/histogram.go b/internal/statsengine/histogram.go index 42460ea..4a5e3b4 100644 --- a/internal/statsengine/histogram.go +++ b/internal/statsengine/histogram.go @@ -47,12 +47,18 @@ func (h *histogram) Increment(durationNs uint64) { h.total++ } +// Snapshot returns a HistogramSnapshot of the current histogram state. +// It panics on build error, which should never happen for a valid histogram. func (h *histogram) Snapshot() HistogramSnapshot { if h == nil { return NewHistogramSnapshot(0, nil) } - return buildHistogramSnapshot(h.snapshotInputs()) + snap, err := buildHistogramSnapshot(h.snapshotInputs()) + if err != nil { + panic("buildHistogramSnapshot: " + err.Error()) + } + return snap } func (h *histogram) snapshotInputs() histogramSnapshotInput { @@ -65,7 +71,10 @@ func (h *histogram) snapshotInputs() histogramSnapshotInput { } } -func buildHistogramSnapshot(in histogramSnapshotInput) HistogramSnapshot { +// buildHistogramSnapshot converts a histogramSnapshotInput into a +// HistogramSnapshot. The error return is reserved for future validation; +// currently this function always succeeds. +func buildHistogramSnapshot(in histogramSnapshotInput) (HistogramSnapshot, error) { buckets := make([]HistogramBucketSnapshot, 0, histogramBucketCount) for i := 0; i < histogramBucketCount; i++ { lower, upper := histogramBucketRange(i) @@ -77,7 +86,7 @@ func buildHistogramSnapshot(in histogramSnapshotInput) HistogramSnapshot { }) } - return NewHistogramSnapshot(in.total, buckets) + return NewHistogramSnapshot(in.total, buckets), nil } func histogramBucketIndex(durationNs uint64) int { |
