summaryrefslogtreecommitdiff
path: root/internal/statsengine/process.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-18 20:54:35 +0200
committerPaul Buetow <paul@buetow.org>2026-03-18 20:54:35 +0200
commitcd554b0af706b5f62b4e1bfde04091052b4aac61 (patch)
treee6d02f1c2a1da27da17386e8832c2d4a3e699cdf /internal/statsengine/process.go
parentb421b2232351049277ee4ad5b31367bb2b6779bb (diff)
cleanup
Diffstat (limited to 'internal/statsengine/process.go')
-rw-r--r--internal/statsengine/process.go25
1 files changed, 16 insertions, 9 deletions
diff --git a/internal/statsengine/process.go b/internal/statsengine/process.go
index b00a4bb..3bfd019 100644
--- a/internal/statsengine/process.go
+++ b/internal/statsengine/process.go
@@ -1,7 +1,8 @@
package statsengine
import (
- "sort"
+ "cmp"
+ "slices"
"time"
"ior/internal/event"
@@ -115,14 +116,14 @@ func buildProcessSnapshots(inputs []processSnapshotInput, elapsed time.Duration)
for _, in := range inputs {
result = append(result, in.toSnapshot(rateDiv))
}
- sort.Slice(result, func(i, j int) bool {
- if result[i].Syscalls != result[j].Syscalls {
- return result[i].Syscalls > result[j].Syscalls
+ slices.SortFunc(result, func(a, b ProcessSnapshot) int {
+ if a.Syscalls != b.Syscalls {
+ return cmp.Compare(b.Syscalls, a.Syscalls)
}
- if result[i].Bytes != result[j].Bytes {
- return result[i].Bytes > result[j].Bytes
+ if a.Bytes != b.Bytes {
+ return cmp.Compare(b.Bytes, a.Bytes)
}
- return result[i].PID < result[j].PID
+ return cmp.Compare(a.PID, b.PID)
})
return result
}
@@ -136,8 +137,14 @@ func (a *processAccumulator) compactIfNeeded() {
for _, stats := range a.byPID {
ordered = append(ordered, stats)
}
- sort.Slice(ordered, func(i, j int) bool {
- return betterProcessRank(ordered[i], ordered[j])
+ slices.SortFunc(ordered, func(a, b *processStats) int {
+ if betterProcessRank(a, b) {
+ return -1
+ }
+ if betterProcessRank(b, a) {
+ return 1
+ }
+ return 0
})
if len(ordered) > a.topN {
ordered = ordered[:a.topN]