diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-05 22:27:06 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-05 22:27:06 +0200 |
| commit | 270c4b422cfc5e7588b7045276588e9f043f85e3 (patch) | |
| tree | 86b9b90f4154a95268f3391d29a23982f25f8025 /internal/tui/flamegraph/model.go | |
| parent | 6f678299369d46b40aa412c7340eca9b18fc4dd1 (diff) | |
task 354: wire dashboard flame tab to LiveTrie
Diffstat (limited to 'internal/tui/flamegraph/model.go')
| -rw-r--r-- | internal/tui/flamegraph/model.go | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/internal/tui/flamegraph/model.go b/internal/tui/flamegraph/model.go index dd77201..ac9b5af 100644 --- a/internal/tui/flamegraph/model.go +++ b/internal/tui/flamegraph/model.go @@ -1,6 +1,8 @@ package flamegraph import ( + "encoding/json" + "fmt" "image/color" coreflamegraph "ior/internal/flamegraph" common "ior/internal/tui/common" @@ -88,10 +90,46 @@ func (m Model) Update(tea.Msg) (tea.Model, tea.Cmd) { // View renders the flamegraph viewport. func (m Model) View() tea.View { - content := common.PanelStyle.Render("Flame: model scaffold") + content := "Flame: waiting for data..." + if m.snapshot != nil { + content = fmt.Sprintf("Flame: live snapshot v%d", m.lastVersion) + } + content = common.PanelStyle.Render(content) return tea.NewView(content) } +// SetLiveTrie updates the data source used by the flamegraph model. +func (m *Model) SetLiveTrie(liveTrie *coreflamegraph.LiveTrie) { + m.liveTrie = liveTrie + m.lastVersion = 0 + m.snapshot = nil +} + +// RefreshFromLiveTrie loads a new snapshot when the source version changes. +func (m *Model) RefreshFromLiveTrie() bool { + if m.liveTrie == nil { + return false + } + version := m.liveTrie.Version() + if version == m.lastVersion && m.snapshot != nil { + return false + } + + payload, version := m.liveTrie.SnapshotJSON() + var snapshot snapshotNode + if err := json.Unmarshal(payload, &snapshot); err != nil { + return false + } + m.snapshot = &snapshot + m.lastVersion = version + return true +} + +// LastVersion returns the latest snapshot version loaded into the model. +func (m Model) LastVersion() uint64 { + return m.lastVersion +} + // SetViewport updates model render dimensions. func (m *Model) SetViewport(width, height int) { m.width = width |
