diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-25 10:21:43 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-25 10:21:43 +0200 |
| commit | 0f9a4a6c95d8e706ea837a3e685c2d1d81e7459d (patch) | |
| tree | 2b6141a12321d17e5a36bdfad4e4d4786ddfe01a /internal/tui | |
| parent | 559c5cb10b654cceda62b2afa12068a575a83530 (diff) | |
Add directory-level file aggregation helper
Diffstat (limited to 'internal/tui')
| -rw-r--r-- | internal/tui/dashboard/files.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/internal/tui/dashboard/files.go b/internal/tui/dashboard/files.go index faade8d..dc3ed10 100644 --- a/internal/tui/dashboard/files.go +++ b/internal/tui/dashboard/files.go @@ -3,11 +3,25 @@ package dashboard import ( "fmt" "ior/internal/statsengine" + "path/filepath" + "sort" "strconv" "github.com/charmbracelet/bubbles/table" ) +type DirSnapshot struct { + Dir string + + Accesses uint64 + BytesRead uint64 + BytesWritten uint64 + + AvgLatencyNs float64 + MaxLatencyNs uint64 + FileCount uint64 +} + func renderFiles(snap *statsengine.Snapshot, width, height int) string { return renderFilesWithOffset(snap, width, height, 0) } @@ -87,3 +101,42 @@ func truncatePathMiddle(path string, limit int) string { } return path[:head] + "..." + path[len(path)-tail:] } + +func aggregateFilesByDir(files []statsengine.FileSnapshot) []DirSnapshot { + if len(files) == 0 { + return nil + } + + dirs := make(map[string]DirSnapshot, len(files)) + weightedLatency := make(map[string]float64, len(files)) + for _, f := range files { + dir := filepath.Dir(f.Path) + s := dirs[dir] + s.Dir = dir + s.Accesses += f.Accesses + s.BytesRead += f.BytesRead + s.BytesWritten += f.BytesWritten + if f.MaxLatencyNs > s.MaxLatencyNs { + s.MaxLatencyNs = f.MaxLatencyNs + } + s.FileCount++ + weightedLatency[dir] += f.AvgLatencyNs * float64(f.Accesses) + dirs[dir] = s + } + + out := make([]DirSnapshot, 0, len(dirs)) + for dir, s := range dirs { + if s.Accesses > 0 { + s.AvgLatencyNs = weightedLatency[dir] / float64(s.Accesses) + } + out = append(out, s) + } + + sort.Slice(out, func(i, j int) bool { + if out[i].Accesses != out[j].Accesses { + return out[i].Accesses > out[j].Accesses + } + return out[i].Dir < out[j].Dir + }) + return out +} |
