diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-12 23:09:00 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-12 23:09:00 +0300 |
| commit | fa439f7f6f145b4a47aeb107619e9efbd07bc9d8 (patch) | |
| tree | cb8590c4a4c808c30bc94e867b98599a54ab8f90 /internal/runtime | |
| parent | 15338e6d4253fc8f4871a68ddcc41c6e3ce58220 (diff) | |
split LiveTrieSource into Snapshotter and Configurator (ISP)
Applies the Interface Segregation Principle to LiveTrieSource in both
internal/runtime and internal/tui/flamegraph. The monolithic interface is
replaced by two focused sub-interfaces — Snapshotter (read-only: Version,
SnapshotJSON, SnapshotTree) and Configurator (mutating: Fields, CountField,
Reconfigure, SetCountField, Reset) — which LiveTrieSource then embeds so all
existing consumers continue to compile unchanged. The buildSnapshotMsg helper
is narrowed to Snapshotter since it only reads snapshot data, preventing
accidental mutation from the background goroutine.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/runtime')
| -rw-r--r-- | internal/runtime/runtime.go | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/internal/runtime/runtime.go b/internal/runtime/runtime.go index a9e959a..5e6f2a4 100644 --- a/internal/runtime/runtime.go +++ b/internal/runtime/runtime.go @@ -42,19 +42,46 @@ type SnapshotSource interface { Snapshot() *statsengine.Snapshot } -// LiveTrieSource is the minimal flamegraph-trie contract needed by the tracing -// engine and the flamegraph TUI model. It mirrors the interface defined in -// internal/tui/flamegraph but lives here so the core package need not import -// that TUI sub-package. Both interfaces are satisfied by *flamegraph.LiveTrie. -type LiveTrieSource interface { +// Snapshotter is the read-only subset of the trie contract used by consumers +// that only need to poll the version and retrieve snapshot data. It mirrors the +// Snapshotter interface in internal/tui/flamegraph but lives here so the core +// package need not import that TUI sub-package. +// *flamegraph.LiveTrie satisfies this interface. +type Snapshotter interface { + // Version returns the monotonically-increasing snapshot generation counter. + Version() uint64 + // SnapshotJSON serialises the current trie to JSON for external consumers. + SnapshotJSON() ([]byte, uint64) + // SnapshotTree returns a ready-to-render snapshot tree without a JSON round-trip. + SnapshotTree() (*flamegraph.SnapshotNode, uint64) +} + +// Configurator is the write/mutating subset of the trie contract used by +// consumers that need to change field layout, metric, or reset the baseline. +// It mirrors the Configurator interface in internal/tui/flamegraph but lives +// here so the core package need not import that TUI sub-package. +// *flamegraph.LiveTrie satisfies this interface. +type Configurator interface { + // Fields returns the current ordered list of grouping fields. Fields() []string + // CountField returns the active aggregation metric name. CountField() string + // Reconfigure replaces the grouping fields and resets accumulated data. Reconfigure([]string) error + // SetCountField changes the active aggregation metric and starts a fresh baseline. SetCountField(string) error + // Reset clears all accumulated data, starting a new baseline. Reset() - Version() uint64 - SnapshotJSON() ([]byte, uint64) - SnapshotTree() (*flamegraph.SnapshotNode, uint64) +} + +// LiveTrieSource is the full flamegraph-trie contract needed by the tracing +// engine and the flamegraph TUI model. It embeds Snapshotter (read-only +// snapshot access) and Configurator (mutating operations) so each can be used +// independently where a narrower interface suffices. Both interfaces are +// satisfied by *flamegraph.LiveTrie. +type LiveTrieSource interface { + Snapshotter + Configurator } // ProbeManager exposes runtime probe controls to the TUI probes modal. |
