1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
package flamegraph
import (
"fmt"
"strings"
common "ior/internal/tui/common"
"charm.land/lipgloss/v2"
)
func (m *Model) togglePause() {
m.paused = !m.paused
}
func (m *Model) resetBaseline() {
if m.liveTrie != nil {
m.liveTrie.Reset()
}
m.zoomRoot = nil
m.zoomPath = ""
m.zoomStack = nil
m.selectedIdx = 0
m.snapshot = nil
m.globalTotal = 0
m.frames = nil
m.targetFrames = nil
m.searchQuery = ""
m.matchIndices = make(map[int]bool)
m.filterVisible = make(map[int]bool)
m.subtreeSet = make(map[int]bool)
m.hasNavigableSnapshot = false
m.statusMessage = "Baseline reset"
}
func (m *Model) cycleFieldOrder() {
if len(m.fieldPresets) == 0 {
return
}
m.fieldIndex = (m.fieldIndex + 1) % len(m.fieldPresets)
nextPreset := m.fieldPresets[m.fieldIndex]
if m.liveTrie != nil {
if err := m.liveTrie.Reconfigure(nextPreset); err != nil {
m.statusMessage = "Field order error: " + err.Error()
return
}
}
m.zoomRoot = nil
m.zoomPath = ""
m.zoomStack = nil
m.selectedIdx = 0
m.snapshot = nil
m.globalTotal = 0
m.frames = nil
m.targetFrames = nil
m.matchIndices = make(map[int]bool)
m.filterVisible = make(map[int]bool)
m.subtreeSet = make(map[int]bool)
m.hasNavigableSnapshot = false
m.statusMessage = "Order: " + strings.Join(nextPreset, "/")
}
func (m *Model) toggleHelp() {
m.showHelp = !m.showHelp
}
func (m Model) toolbarLine() string {
state := lipgloss.NewStyle().Foreground(common.ColorPrimary).Render("[LIVE]")
if m.paused {
state = lipgloss.NewStyle().Foreground(common.ColorDanger).Bold(true).Render("[PAUSED]")
}
order := m.currentFieldPresetLabel()
line := fmt.Sprintf("%s | view:%s | o:order(%s) | /:search | enter:zoom | u/esc:undo | r:reset | space/p:pause", state, compactFramePath(m.currentRootPath()), order)
if m.searchQuery != "" {
line += " | filter:" + m.searchQuery
}
if m.statusMessage != "" {
line += " | " + m.statusMessage
}
if m.lastKeyDebug != "" {
line += " | " + m.lastKeyDebug
}
width := m.width
if width <= 0 {
width = 80
}
return padOrTrim(line, width)
}
func (m Model) helpOverlay() string {
width := m.width
if width <= 0 {
width = 80
}
help := "Flame help: j/k depth h/l sibling enter zoom u/backspace/esc undo / search n/N matches space/p pause r reset baseline o order ? help"
return common.HelpBarStyle.Width(width).Render(padOrTrim(help, width))
}
func (m Model) selectionStatusLine() string {
width := m.width
if width <= 0 {
width = 80
}
mode := "LIVE"
if m.paused {
mode = "PAUSED"
}
if len(m.frames) == 0 {
line := fmt.Sprintf("[%s] sel:none | arrows/hjkl navigate | enter zoom | / filter", mode)
return common.HelpBarStyle.Width(width).Render(padOrTrim(line, width))
}
selIdx := m.selectedIdx
if selIdx < 0 || selIdx >= len(m.frames) {
selIdx = 0
}
frame := m.frames[selIdx]
systemShare := frame.Percent
if m.globalTotal > 0 {
systemShare = percentOfTotal(frame.Total, m.globalTotal)
}
line := fmt.Sprintf("[%s] sel:%d/%d %s | path:%s | depth:%d | total:%d | %.2f%% system",
mode, selIdx+1, len(m.frames), frame.Name, compactFramePath(frame.Path), frame.Depth, frame.Total, systemShare)
if m.searchQuery != "" {
line += " | filter:" + m.searchQuery
}
return common.HelpBarStyle.Width(width).Render(padOrTrim(line, width))
}
func (m Model) currentFieldPresetLabel() string {
if len(m.fieldPresets) == 0 {
return "n/a"
}
idx := m.fieldIndex
if idx < 0 {
idx = 0
}
if idx >= len(m.fieldPresets) {
idx = len(m.fieldPresets) - 1
}
return strings.Join(m.fieldPresets[idx], "/")
}
|