diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-18 09:24:22 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-18 09:24:22 +0200 |
| commit | dbb98cd8dbd70dd92b8a541653e64c45b18348fa (patch) | |
| tree | f2faa385564a4700c608bcf8f2ffc638c1c0bd27 /internal/tui/tui.go | |
| parent | 630ea0ff27b8e9ff9287eaaf67660845406a19a6 (diff) | |
refactor: split TraceRuntimeBindings into RuntimePublisher and RuntimeState (task 427/ISP)
TraceRuntimeBindings mixed 4 setter methods (injecting data into TUI) with
4 getter methods (reading persistent TUI-owned state), violating ISP.
Split into two focused interfaces:
- RuntimePublisher: SetDashboardSnapshotSource, SetEventStreamSource,
SetLiveTrie, SetProbeManager — the write/inject side
- RuntimeState: StreamBuffer, Recorder, StreamSequencer, FilterEpoch
— the read/persistent-state side
TraceRuntimeBindings now embeds both, preserving all existing call sites.
RuntimePublisherFromContext() added so callers that only inject data do not
see the getter surface. Three such callers are narrowed: setupBPFModule,
tuiTestFlamesStarter, tuiTestLiveFlamesStarter.
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'internal/tui/tui.go')
| -rw-r--r-- | internal/tui/tui.go | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/internal/tui/tui.go b/internal/tui/tui.go index 432fc14..252e722 100644 --- a/internal/tui/tui.go +++ b/internal/tui/tui.go @@ -58,19 +58,31 @@ type ProbeManager interface { ActiveCount() (int, int) } -// TraceRuntimeBindings allows a trace starter to publish runtime dependencies -// (snapshot source, stream source, probe manager) into the active TUI model. -type TraceRuntimeBindings interface { +// RuntimePublisher is the write side of the TUI runtime contract. +// A trace starter calls these methods to inject live data into the active TUI. +type RuntimePublisher interface { SetDashboardSnapshotSource(source SnapshotSource) SetEventStreamSource(source eventstream.Source) SetLiveTrie(liveTrie flamegraphtui.LiveTrieSource) SetProbeManager(manager ProbeManager) +} + +// RuntimeState is the read side of the TUI runtime contract. +// A trace starter calls these methods to obtain persistent state owned by the TUI. +type RuntimeState interface { StreamBuffer() eventstream.Source Recorder() *parquet.Recorder StreamSequencer() *eventstream.Sequencer FilterEpoch() uint64 } +// TraceRuntimeBindings composes RuntimePublisher and RuntimeState so a trace +// starter can both inject live data and read persistent TUI-owned state. +type TraceRuntimeBindings interface { + RuntimePublisher + RuntimeState +} + type runtimeBindingsContextKey struct{} type traceFiltersContextKey struct{} @@ -200,8 +212,9 @@ func (r *runtimeBindings) resetDashboardSnapshotSource() *statsengine.Snapshot { return nil } -// RuntimeBindingsFromContext returns model-scoped trace bindings when the -// context was created by the TUI. +// RuntimeBindingsFromContext returns the full TraceRuntimeBindings when the +// context was created by the TUI. Use RuntimePublisherFromContext when only +// write access is needed. func RuntimeBindingsFromContext(ctx context.Context) (TraceRuntimeBindings, bool) { bindings, ok := ctx.Value(runtimeBindingsContextKey{}).(TraceRuntimeBindings) if !ok || bindings == nil { @@ -210,6 +223,17 @@ func RuntimeBindingsFromContext(ctx context.Context) (TraceRuntimeBindings, bool return bindings, true } +// RuntimePublisherFromContext returns only the RuntimePublisher side of the +// TUI bindings. Use this when the caller only injects data and does not need +// to read persistent TUI state. +func RuntimePublisherFromContext(ctx context.Context) (RuntimePublisher, bool) { + bindings, ok := ctx.Value(runtimeBindingsContextKey{}).(RuntimePublisher) + if !ok || bindings == nil { + return nil, false + } + return bindings, true +} + // ContextWithRuntimeBindings stores trace runtime bindings on the context. func ContextWithRuntimeBindings(ctx context.Context, bindings TraceRuntimeBindings) context.Context { return context.WithValue(ctx, runtimeBindingsContextKey{}, bindings) |
