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/tui | |
| 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/tui')
| -rw-r--r-- | internal/tui/dashboard/model.go | 13 | ||||
| -rw-r--r-- | internal/tui/tui.go | 17 | ||||
| -rw-r--r-- | internal/tui/tui_test.go | 13 |
3 files changed, 31 insertions, 12 deletions
diff --git a/internal/tui/dashboard/model.go b/internal/tui/dashboard/model.go index 8a3c5d4..cc2a052 100644 --- a/internal/tui/dashboard/model.go +++ b/internal/tui/dashboard/model.go @@ -874,11 +874,18 @@ func (m Model) maxProcessesRows() int { return m.snapshotOrZero().ProcessesCount() } +// snapshot returns the latest engine snapshot, or nil if the engine is nil or +// returns an error. Errors are silently dropped here because the dashboard +// renders the last successful snapshot on transient failures. func (m Model) snapshot() *statsengine.Snapshot { if m.engine == nil { return nil } - return m.engine.Snapshot() + snap, err := m.engine.Snapshot() + if err != nil { + return nil + } + return snap } func (m Model) snapshotOrZero() statsengine.Snapshot { @@ -893,10 +900,12 @@ func (m *Model) resetBaselineCmd() tea.Cmd { m.liveTrie.Reset() } + // Errors from Snapshot are silently dropped here; the dashboard will + // continue to display the last successful snapshot. var snap *statsengine.Snapshot if resettable, ok := m.engine.(resettableSnapshotSource); ok { resettable.Reset() - snap = resettable.Snapshot() + snap, _ = resettable.Snapshot() } else { snap = m.snapshot() } diff --git a/internal/tui/tui.go b/internal/tui/tui.go index eee4252..2cebaf2 100644 --- a/internal/tui/tui.go +++ b/internal/tui/tui.go @@ -225,6 +225,9 @@ func (r *runtimeBindings) advanceFilterEpoch() uint64 { return r.filterEpoch.Add(1) } +// resetDashboardSnapshotSource resets the dashboard snapshot source if it +// implements the resettable interface, then returns a fresh snapshot. Errors +// from Snapshot are silently dropped since callers handle a nil snapshot. func (r *runtimeBindings) resetDashboardSnapshotSource() *statsengine.Snapshot { src := r.dashboardSnapshotSource() if src == nil { @@ -232,10 +235,11 @@ func (r *runtimeBindings) resetDashboardSnapshotSource() *statsengine.Snapshot { } if resettable, ok := src.(interface { Reset() - Snapshot() *statsengine.Snapshot + Snapshot() (*statsengine.Snapshot, error) }); ok { resettable.Reset() - return resettable.Snapshot() + snap, _ := resettable.Snapshot() + return snap } return nil } @@ -1216,13 +1220,16 @@ type lateBoundDashboardSource struct { runtime *runtimeBindings } -func (s lateBoundDashboardSource) Snapshot() *statsengine.Snapshot { +// Snapshot returns a point-in-time dashboard snapshot from the underlying +// source, or (nil, nil) when no source is available. Errors are forwarded to +// the caller so they can decide how to handle a failed snapshot build. +func (s lateBoundDashboardSource) Snapshot() (*statsengine.Snapshot, error) { if s.runtime == nil { - return nil + return nil, nil } source := s.runtime.dashboardSnapshotSource() if source == nil { - return nil + return nil, nil } return source.Snapshot() } diff --git a/internal/tui/tui_test.go b/internal/tui/tui_test.go index 5f007e4..d76ccde 100644 --- a/internal/tui/tui_test.go +++ b/internal/tui/tui_test.go @@ -459,8 +459,8 @@ type fakeDashboardSource struct { snap *statsengine.Snapshot } -func (f fakeDashboardSource) Snapshot() *statsengine.Snapshot { - return f.snap +func (f fakeDashboardSource) Snapshot() (*statsengine.Snapshot, error) { + return f.snap, nil } type fakeResettableDashboardSource struct { @@ -468,8 +468,8 @@ type fakeResettableDashboardSource struct { resetCalls int } -func (f *fakeResettableDashboardSource) Snapshot() *statsengine.Snapshot { - return f.snap +func (f *fakeResettableDashboardSource) Snapshot() (*statsengine.Snapshot, error) { + return f.snap, nil } func (f *fakeResettableDashboardSource) Reset() { @@ -484,7 +484,10 @@ func TestDashboardRefreshPicksLateBoundSource(t *testing.T) { want := &statsengine.Snapshot{TotalSyscalls: 77} runtime.SetDashboardSnapshotSource(fakeDashboardSource{snap: want}) - got := source.Snapshot() + got, err := source.Snapshot() + if err != nil { + t.Fatalf("unexpected snapshot error: %v", err) + } if got != want { t.Fatalf("expected late-bound source to use latest runtime source") } |
