summaryrefslogtreecommitdiff
path: root/internal/statsengine/process.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-13 14:41:28 +0300
committerPaul Buetow <paul@buetow.org>2026-05-13 14:41:28 +0300
commitde3405c275898c8cd528a636dbd40e1b685cfaa5 (patch)
tree53711959800677aa694e18331476add24a21b8ef /internal/statsengine/process.go
parentd392eebe5bd127e1573734321b0cabaad4182d7c (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/process.go')
-rw-r--r--internal/statsengine/process.go15
1 files changed, 12 insertions, 3 deletions
diff --git a/internal/statsengine/process.go b/internal/statsengine/process.go
index b7eb6e7..a52be38 100644
--- a/internal/statsengine/process.go
+++ b/internal/statsengine/process.go
@@ -84,12 +84,18 @@ func (a *processAccumulator) Add(pair *event.Pair) {
a.compactIfNeeded()
}
+// Snapshot returns a slice of ProcessSnapshots for all tracked processes.
+// It panics on build error, which should never happen for a valid accumulator.
func (a *processAccumulator) Snapshot(elapsed time.Duration) []ProcessSnapshot {
if a == nil {
return nil
}
- return buildProcessSnapshots(a.snapshotInputs(), elapsed)
+ snap, err := buildProcessSnapshots(a.snapshotInputs(), elapsed)
+ if err != nil {
+ panic("buildProcessSnapshots: " + err.Error())
+ }
+ return snap
}
func (a *processAccumulator) snapshotInputs() []processSnapshotInput {
@@ -110,7 +116,10 @@ func (a *processAccumulator) snapshotInputs() []processSnapshotInput {
return inputs
}
-func buildProcessSnapshots(inputs []processSnapshotInput, elapsed time.Duration) []ProcessSnapshot {
+// buildProcessSnapshots converts raw process accumulator inputs into sorted
+// ProcessSnapshot slices. The error return is reserved for future validation;
+// currently this function always succeeds.
+func buildProcessSnapshots(inputs []processSnapshotInput, elapsed time.Duration) ([]ProcessSnapshot, error) {
rateDiv := elapsed.Seconds()
result := make([]ProcessSnapshot, 0, len(inputs))
for _, in := range inputs {
@@ -125,7 +134,7 @@ func buildProcessSnapshots(inputs []processSnapshotInput, elapsed time.Duration)
}
return cmp.Compare(a.PID, b.PID)
})
- return result
+ return result, nil
}
func (a *processAccumulator) compactIfNeeded() {