diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-24 08:49:57 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-24 08:49:57 +0200 |
| commit | 13a81c7fdbaab8ef650a7487270abb6776f0b4cd (patch) | |
| tree | 111a76dfb4516a62ed166b2a4486214f1034929d /internal/tui/dashboard/processes.go | |
| parent | e5116514c33b2fce6ce2fc7904d6720c5236221f (diff) | |
tui: add dashboard processes table tab
Diffstat (limited to 'internal/tui/dashboard/processes.go')
| -rw-r--r-- | internal/tui/dashboard/processes.go | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/internal/tui/dashboard/processes.go b/internal/tui/dashboard/processes.go new file mode 100644 index 0000000..d229c10 --- /dev/null +++ b/internal/tui/dashboard/processes.go @@ -0,0 +1,75 @@ +package dashboard + +import ( + "fmt" + "ior/internal/flags" + "ior/internal/statsengine" + "strconv" + "strings" + + "github.com/charmbracelet/bubbles/table" +) + +func renderProcesses(snap *statsengine.Snapshot, width, height int) string { + return renderProcessesWithOffset(snap, width, height, 0) +} + +func renderProcessesWithOffset(snap *statsengine.Snapshot, width, height, offset int) string { + if snap == nil { + return "Processes: waiting for stats..." + } + + rows := processRows(snap.Processes()) + if len(rows) == 0 { + return "Processes: no data" + } + + columns := []table.Column{ + {Title: "PID", Width: 8}, + {Title: "Comm", Width: 18}, + {Title: "Syscalls", Width: 10}, + {Title: "Rate/s", Width: 8}, + {Title: "Total Bytes", Width: 12}, + {Title: "Avg Latency", Width: 12}, + } + + tbl := table.New( + table.WithColumns(columns), + table.WithRows(rows), + table.WithFocused(true), + ) + tbl.SetHeight(syscallTableHeight(height)) + tbl.SetWidth(tableWidth(width)) + tbl.SetCursor(clampOffset(offset, len(rows))) + + out := tbl.View() + if flags.Get().PidFilter > 0 { + out += "\n" + "Note: this tab is most useful with All PIDs." + } + return out +} + +func processRows(processes []statsengine.ProcessSnapshot) []table.Row { + rows := make([]table.Row, 0, len(processes)) + for _, p := range processes { + rows = append(rows, table.Row{ + strconv.FormatUint(uint64(p.PID), 10), + truncateText(p.Comm, 18), + strconv.FormatUint(p.Syscalls, 10), + fmt.Sprintf("%.1f", p.RatePerSec), + formatBytes(float64(p.Bytes)), + formatDurationNs(p.AvgLatencyNs), + }) + } + return rows +} + +func truncateText(value string, limit int) string { + if len(value) <= limit { + return value + } + if limit <= 3 { + return value[:limit] + } + return strings.TrimSpace(value[:limit-3]) + "..." +} |
