summaryrefslogtreecommitdiff
path: root/internal/tui/flamegraph
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-05 22:27:06 +0200
committerPaul Buetow <paul@buetow.org>2026-03-05 22:27:06 +0200
commit270c4b422cfc5e7588b7045276588e9f043f85e3 (patch)
tree86b9b90f4154a95268f3391d29a23982f25f8025 /internal/tui/flamegraph
parent6f678299369d46b40aa412c7340eca9b18fc4dd1 (diff)
task 354: wire dashboard flame tab to LiveTrie
Diffstat (limited to 'internal/tui/flamegraph')
-rw-r--r--internal/tui/flamegraph/model.go40
-rw-r--r--internal/tui/flamegraph/model_test.go21
2 files changed, 59 insertions, 2 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
diff --git a/internal/tui/flamegraph/model_test.go b/internal/tui/flamegraph/model_test.go
index 42729bb..1e472ae 100644
--- a/internal/tui/flamegraph/model_test.go
+++ b/internal/tui/flamegraph/model_test.go
@@ -1,6 +1,9 @@
package flamegraph
-import "testing"
+import (
+ coreflamegraph "ior/internal/flamegraph"
+ "testing"
+)
func TestNewModelDefaults(t *testing.T) {
m := NewModel(nil)
@@ -29,3 +32,19 @@ func TestSetViewportAndDarkMode(t *testing.T) {
t.Fatalf("expected dark mode to be disabled")
}
}
+
+func TestRefreshFromLiveTrieTracksVersionAndSnapshot(t *testing.T) {
+ trie := coreflamegraph.NewLiveTrie([]string{"comm", "path"}, "count")
+ m := NewModel(trie)
+
+ if changed := m.RefreshFromLiveTrie(); !changed {
+ t.Fatalf("expected first refresh to load baseline snapshot")
+ }
+ if m.snapshot == nil {
+ t.Fatalf("expected snapshot to be populated after refresh")
+ }
+
+ if changed := m.RefreshFromLiveTrie(); changed {
+ t.Fatalf("expected no refresh when version is unchanged")
+ }
+}