diff options
| -rw-r--r-- | internal/tui/dashboard/model.go | 11 | ||||
| -rw-r--r-- | internal/tui/eventstream/model.go | 12 | ||||
| -rw-r--r-- | internal/tui/flamegraph/model.go | 18 | ||||
| -rw-r--r-- | internal/tui/tui.go | 18 |
4 files changed, 37 insertions, 22 deletions
diff --git a/internal/tui/dashboard/model.go b/internal/tui/dashboard/model.go index 10d8b49..d10a91a 100644 --- a/internal/tui/dashboard/model.go +++ b/internal/tui/dashboard/model.go @@ -4,7 +4,6 @@ import ( "strings" "time" - coreflamegraph "ior/internal/flamegraph" "ior/internal/statsengine" common "ior/internal/tui/common" "ior/internal/tui/eventstream" @@ -41,7 +40,7 @@ type Model struct { engine SnapshotSource latest *statsengine.Snapshot - liveTrie *coreflamegraph.LiveTrie + liveTrie flamegraphtui.LiveTrieSource width int height int @@ -62,12 +61,12 @@ type Model struct { } // NewModel creates a dashboard model with default refresh cadence. -func NewModel(engine SnapshotSource, streamSource *eventstream.RingBuffer) Model { +func NewModel(engine SnapshotSource, streamSource eventstream.Source) Model { return NewModelWithConfig(engine, streamSource, defaultRefreshMs, common.Keys) } // NewModelWithConfig creates a dashboard model with explicit refresh and keys. -func NewModelWithConfig(engine SnapshotSource, streamSource *eventstream.RingBuffer, refreshMs int, keys common.KeyMap) Model { +func NewModelWithConfig(engine SnapshotSource, streamSource eventstream.Source, refreshMs int, keys common.KeyMap) Model { if refreshMs <= 0 { refreshMs = defaultRefreshMs } @@ -362,12 +361,12 @@ func (m Model) BlocksGlobalShortcuts(msg tea.KeyPressMsg) bool { } // SetStreamSource updates the live stream source used by the stream tab. -func (m *Model) SetStreamSource(source *eventstream.RingBuffer) { +func (m *Model) SetStreamSource(source eventstream.Source) { m.streamModel.SetSource(source) } // SetLiveTrie updates the live trie source used by the flamegraph tab. -func (m *Model) SetLiveTrie(liveTrie *coreflamegraph.LiveTrie) { +func (m *Model) SetLiveTrie(liveTrie flamegraphtui.LiveTrieSource) { m.liveTrie = liveTrie m.flamegraphModel.SetLiveTrie(liveTrie) if m.width > 0 && m.height > 0 { diff --git a/internal/tui/eventstream/model.go b/internal/tui/eventstream/model.go index 3e31203..12aff4d 100644 --- a/internal/tui/eventstream/model.go +++ b/internal/tui/eventstream/model.go @@ -24,8 +24,14 @@ const ( streamColumnCount ) +// Source is the minimal stream buffer contract needed by the stream model. +type Source interface { + Len() int + Snapshot() []StreamEvent +} + type Model struct { - source *RingBuffer + source Source allEvents []StreamEvent filtered []StreamEvent @@ -71,7 +77,7 @@ type fdTraceViewState struct { offset int } -func NewModel(source *RingBuffer) Model { +func NewModel(source Source) Model { m := Model{ source: source, filterModal: NewFilterModal(), @@ -122,7 +128,7 @@ func (m *Model) SetFooterVisible(visible bool) { } // SetSource updates the backing ring buffer and refreshes visible rows. -func (m *Model) SetSource(source *RingBuffer) { +func (m *Model) SetSource(source Source) { m.source = source m.Refresh() } diff --git a/internal/tui/flamegraph/model.go b/internal/tui/flamegraph/model.go index c4973fb..cc208ae 100644 --- a/internal/tui/flamegraph/model.go +++ b/internal/tui/flamegraph/model.go @@ -9,7 +9,6 @@ import ( "strings" "time" - coreflamegraph "ior/internal/flamegraph" common "ior/internal/tui/common" "charm.land/bubbles/v2/key" @@ -28,6 +27,17 @@ type animTickMsg struct{} const animFrameDuration = 33 * time.Millisecond +// LiveTrieSource is the minimal trie contract needed by the flamegraph TUI model. +type LiveTrieSource interface { + Fields() []string + CountField() string + Reconfigure([]string) error + SetCountField(string) error + Reset() + Version() uint64 + SnapshotJSON() ([]byte, uint64) +} + type zoomState struct { path string previousSelectedIdx int @@ -61,7 +71,7 @@ func defaultFlameKeyMap() flameKeyMap { // Model is the Bubble Tea model for the TUI flamegraph tab. type Model struct { - liveTrie *coreflamegraph.LiveTrie + liveTrie LiveTrieSource lastVersion uint64 snapshot *snapshotNode globalTotal uint64 @@ -113,7 +123,7 @@ type tuiFrame struct { } // NewModel constructs a flamegraph tab model with default state. -func NewModel(liveTrie *coreflamegraph.LiveTrie) Model { +func NewModel(liveTrie LiveTrieSource) Model { searchInput := textinput.New() searchInput.Prompt = "/" searchInput.CharLimit = 0 @@ -316,7 +326,7 @@ func (m Model) View() tea.View { } // SetLiveTrie updates the data source used by the flamegraph model. -func (m *Model) SetLiveTrie(liveTrie *coreflamegraph.LiveTrie) { +func (m *Model) SetLiveTrie(liveTrie LiveTrieSource) { m.liveTrie = liveTrie m.syncFieldPresetToTrie() m.syncCountFieldToTrie() diff --git a/internal/tui/tui.go b/internal/tui/tui.go index fb9229f..4051508 100644 --- a/internal/tui/tui.go +++ b/internal/tui/tui.go @@ -11,13 +11,13 @@ import ( coreexport "ior/internal/export" "ior/internal/flags" - coreflamegraph "ior/internal/flamegraph" "ior/internal/probemanager" "ior/internal/statsengine" common "ior/internal/tui/common" dashboardui "ior/internal/tui/dashboard" "ior/internal/tui/eventstream" tuiexport "ior/internal/tui/export" + flamegraphtui "ior/internal/tui/flamegraph" "ior/internal/tui/messages" "ior/internal/tui/pidpicker" "ior/internal/tui/probes" @@ -58,8 +58,8 @@ type ProbeManager interface { // (snapshot source, stream source, probe manager) into the active TUI model. type TraceRuntimeBindings interface { SetDashboardSnapshotSource(source SnapshotSource) - SetEventStreamSource(source *eventstream.RingBuffer) - SetLiveTrie(liveTrie *coreflamegraph.LiveTrie) + SetEventStreamSource(source eventstream.Source) + SetLiveTrie(liveTrie flamegraphtui.LiveTrieSource) SetProbeManager(manager ProbeManager) } @@ -70,8 +70,8 @@ type runtimeBindings struct { mu sync.RWMutex snapshotSource SnapshotSource - streamSource *eventstream.RingBuffer - liveTrieSource *coreflamegraph.LiveTrie + streamSource eventstream.Source + liveTrieSource flamegraphtui.LiveTrieSource probeManager ProbeManager } @@ -90,13 +90,13 @@ func (r *runtimeBindings) SetDashboardSnapshotSource(source SnapshotSource) { r.mu.Unlock() } -func (r *runtimeBindings) SetEventStreamSource(source *eventstream.RingBuffer) { +func (r *runtimeBindings) SetEventStreamSource(source eventstream.Source) { r.mu.Lock() r.streamSource = source r.mu.Unlock() } -func (r *runtimeBindings) SetLiveTrie(liveTrie *coreflamegraph.LiveTrie) { +func (r *runtimeBindings) SetLiveTrie(liveTrie flamegraphtui.LiveTrieSource) { r.mu.Lock() r.liveTrieSource = liveTrie r.mu.Unlock() @@ -114,13 +114,13 @@ func (r *runtimeBindings) dashboardSnapshotSource() SnapshotSource { return r.snapshotSource } -func (r *runtimeBindings) eventStreamSource() *eventstream.RingBuffer { +func (r *runtimeBindings) eventStreamSource() eventstream.Source { r.mu.RLock() defer r.mu.RUnlock() return r.streamSource } -func (r *runtimeBindings) liveTrie() *coreflamegraph.LiveTrie { +func (r *runtimeBindings) liveTrie() flamegraphtui.LiveTrieSource { r.mu.RLock() defer r.mu.RUnlock() return r.liveTrieSource |
