summaryrefslogtreecommitdiff
path: root/internal/tui/dashboard/nonio.go
blob: 42069a2ae53478c2aeea39d63c604367ad254538 (plain)
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
package dashboard

import (
	"fmt"
	"strconv"

	"ior/internal/statsengine"
	common "ior/internal/tui/common"
	"ior/internal/types"
)

func renderNonIO(snap *statsengine.Snapshot, width, height int) string {
	return renderNonIOWithOffset(snap, width, height, 0, 0)
}

func renderNonIOWithOffset(snap *statsengine.Snapshot, width, height, offset, selectedCol int) string {
	if snap == nil {
		return "Non-IO: waiting for stats..."
	}

	rowsData := nonIOFamilies(snap.Families())
	columns, rows := nonIOTableData(rowsData, width)
	if len(rows) == 0 {
		return "Non-IO: no data"
	}
	return renderSelectableTable(
		columns,
		rows,
		height,
		offset,
		selectedCol,
		"families excluding file/fd",
	)
}

func nonIOTableData(families []statsengine.FamilySnapshot, width int) ([]common.TableColumn, [][]string) {
	columns := nonIOColumns(width)
	if width < 130 {
		return columns, nonIORowsCompact(families)
	}
	return columns, nonIORowsFull(families)
}

func nonIOColumns(width int) []common.TableColumn {
	if width < 130 {
		return []common.TableColumn{
			{Title: "Family", Width: 10},
			{Title: "Count", Width: 7},
			{Title: "Rate/s", Width: 7},
			{Title: "Avg", Width: 8},
			{Title: "Bytes", Width: 8},
			{Title: "Errors", Width: 6},
		}
	}

	return []common.TableColumn{
		{Title: "Family", Width: 12},
		{Title: "Count", Width: 8},
		{Title: "Rate/s", Width: 8},
		{Title: "Avg", Width: 9},
		{Title: "Min", Width: 9},
		{Title: "Max", Width: 9},
		{Title: "Total", Width: 10},
		{Title: "Bytes", Width: 10},
		{Title: "Errors", Width: 8},
	}
}

func nonIORowsFull(families []statsengine.FamilySnapshot) [][]string {
	rows := make([][]string, 0, len(families))
	for _, f := range families {
		rows = append(rows, []string{
			f.Name,
			strconv.FormatUint(f.Count, 10),
			fmt.Sprintf("%.1f", f.RatePerSec),
			formatDurationNs(f.LatencyMeanNs),
			formatDurationUintNs(f.LatencyMinNs),
			formatDurationUintNs(f.LatencyMaxNs),
			formatDurationUintNs(f.TotalLatencyNs),
			formatBytes(float64(f.Bytes)),
			strconv.FormatUint(f.Errors, 10),
		})
	}
	return rows
}

func nonIORowsCompact(families []statsengine.FamilySnapshot) [][]string {
	rows := make([][]string, 0, len(families))
	for _, f := range families {
		rows = append(rows, []string{
			f.Name,
			strconv.FormatUint(f.Count, 10),
			fmt.Sprintf("%.1f", f.RatePerSec),
			formatDurationNs(f.LatencyMeanNs),
			formatBytes(float64(f.Bytes)),
			strconv.FormatUint(f.Errors, 10),
		})
	}
	return rows
}

// isFileSyscallFamily reports whether family belongs to file-system/fd views.
// This is a dashboard presentation concept: the Non-IO tab excludes FS families.
func isFileSyscallFamily(family types.SyscallFamily) bool {
	return family == types.FamilyFS
}

// isNonIOSyscallFamily reports whether family should appear in the Non-IO tab.
// This is a dashboard grouping policy kept out of the core stats/types packages.
func isNonIOSyscallFamily(family types.SyscallFamily) bool {
	return family != "" && !isFileSyscallFamily(family)
}

// nonIOFamilies filters family snapshot rows to those outside the FS family.
func nonIOFamilies(all []statsengine.FamilySnapshot) []statsengine.FamilySnapshot {
	rows := make([]statsengine.FamilySnapshot, 0, len(all))
	for _, row := range all {
		if isNonIOSyscallFamily(row.Family) {
			rows = append(rows, row)
		}
	}
	return rows
}

// nonIOFamiliesCount returns the number of non-FS family rows.
func nonIOFamiliesCount(all []statsengine.FamilySnapshot) int {
	count := 0
	for _, row := range all {
		if isNonIOSyscallFamily(row.Family) {
			count++
		}
	}
	return count
}