summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-26 22:40:43 +0300
committerPaul Buetow <paul@buetow.org>2026-05-26 22:40:43 +0300
commit5533d521ae2183342771ace001624c89e75a994f (patch)
treecd9c21a570c9089f118624be1df2bc4aaec02480 /internal
parent66332e4012e3cfad79f9309a4fd7937f5ccf0d26 (diff)
flamegraph: plumb HeightTotal through tuiFrame layout (task to)
Diffstat (limited to 'internal')
-rw-r--r--internal/tui/flamegraph/model.go42
-rw-r--r--internal/tui/flamegraph/renderer.go33
2 files changed, 47 insertions, 28 deletions
diff --git a/internal/tui/flamegraph/model.go b/internal/tui/flamegraph/model.go
index 065a78a..b1f3f1e 100644
--- a/internal/tui/flamegraph/model.go
+++ b/internal/tui/flamegraph/model.go
@@ -216,15 +216,16 @@ type Model struct {
// tuiFrame stores one terminal flamegraph frame cell.
type tuiFrame struct {
- Name string
- Col int
- Row int
- Width int
- Total uint64
- Percent float64
- Fill color.Color
- Depth int
- Path string
+ Name string
+ Col int
+ Row int
+ Width int
+ Total uint64
+ HeightTotal uint64
+ Percent float64
+ Fill color.Color
+ Depth int
+ Path string
}
// NewModel constructs a flamegraph tab model with default state.
@@ -944,7 +945,7 @@ func isCycleMetricKey(msg tea.KeyPressMsg) bool {
return keyString(msg) == "b"
}
func isToggleHeightKey(msg tea.KeyPressMsg) bool { return keyString(msg) == "v" }
-func isHelpToggleKey(msg tea.KeyPressMsg) bool { return keyString(msg) == "?" }
+func isHelpToggleKey(msg tea.KeyPressMsg) bool { return keyString(msg) == "?" }
func isZoomInKey(msg tea.KeyPressMsg, keys flameKeyMap) bool {
return key.Matches(msg, keys.ZoomIn) || msg.Code == tea.KeyEnter || strings.EqualFold(keyString(msg), "enter")
@@ -1127,8 +1128,10 @@ func applyZoomLineage(frames []tuiFrame, snapshot *snapshotNode, zoomPath string
path := strings.Join(parts[:depth+1], pathSeparator)
node := findNodeByPath(snapshot, path)
total := uint64(0)
+ heightTotal := uint64(0)
if node != nil {
total = snapshotTotal(node)
+ heightTotal = snapshotHeightTotal(node)
}
percent := 0.0
if rootTotal > 0 {
@@ -1136,15 +1139,16 @@ func applyZoomLineage(frames []tuiFrame, snapshot *snapshotNode, zoomPath string
}
name := parts[depth]
out = append(out, tuiFrame{
- Name: name,
- Col: 0,
- Row: depth,
- Width: width,
- Total: total,
- Percent: percent,
- Fill: terminalFrameColor(name),
- Depth: depth,
- Path: path,
+ Name: name,
+ Col: 0,
+ Row: depth,
+ Width: width,
+ Total: total,
+ HeightTotal: heightTotal,
+ Percent: percent,
+ Fill: terminalFrameColor(name),
+ Depth: depth,
+ Path: path,
})
}
return out
diff --git a/internal/tui/flamegraph/renderer.go b/internal/tui/flamegraph/renderer.go
index 361feb2..3a35de9 100644
--- a/internal/tui/flamegraph/renderer.go
+++ b/internal/tui/flamegraph/renderer.go
@@ -54,15 +54,16 @@ func collectTerminalLayout(out *[]tuiFrame, node *snapshotNode, rootTotal uint64
name := frameName(node.Name, depth)
*out = append(*out, tuiFrame{
- Name: name,
- Col: col,
- Row: depth,
- Width: span,
- Total: total,
- Percent: 100 * float64(total) / float64(rootTotal),
- Fill: terminalFrameColor(name),
- Depth: depth,
- Path: path,
+ Name: name,
+ Col: col,
+ Row: depth,
+ Width: span,
+ Total: total,
+ HeightTotal: snapshotHeightTotal(node),
+ Percent: 100 * float64(total) / float64(rootTotal),
+ Fill: terminalFrameColor(name),
+ Depth: depth,
+ Path: path,
})
if len(node.Children) == 0 {
@@ -158,6 +159,20 @@ func snapshotTotal(node *snapshotNode) uint64 {
return total
}
+func snapshotHeightTotal(node *snapshotNode) uint64 {
+ if node == nil {
+ return 0
+ }
+ total := uint64(0)
+ for _, child := range node.Children {
+ total += snapshotHeightTotal(child)
+ }
+ if node.HeightTotal > total {
+ return node.HeightTotal
+ }
+ return total
+}
+
func frameName(name string, depth int) string {
if name != "" {
return name