summaryrefslogtreecommitdiff
path: root/internal/statsengine/filerank.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-24 12:12:31 +0200
committerPaul Buetow <paul@buetow.org>2026-02-24 12:12:31 +0200
commit610d91472b3b37010130f33bd835c23e859caf56 (patch)
tree48cc2cb7e425c69135095ad748389afd0192c4d1 /internal/statsengine/filerank.go
parent0d4ef22478a470d86ce907beedcaa726d0d46c73 (diff)
statsengine: build snapshots outside engine mutex
Diffstat (limited to 'internal/statsengine/filerank.go')
-rw-r--r--internal/statsengine/filerank.go37
1 files changed, 33 insertions, 4 deletions
diff --git a/internal/statsengine/filerank.go b/internal/statsengine/filerank.go
index 9054ff7..6e8f27f 100644
--- a/internal/statsengine/filerank.go
+++ b/internal/statsengine/filerank.go
@@ -26,6 +26,15 @@ type fileRankStats struct {
heapIndex int
}
+type fileSnapshotInput struct {
+ path string
+ accesses uint64
+ bytesRead uint64
+ bytesWritten uint64
+ totalLatency uint64
+ maxLatency uint64
+}
+
type fileRankHeap []*fileRankStats
func newFileRanker() *fileRanker {
@@ -87,18 +96,38 @@ func (r *fileRanker) Snapshot() []FileSnapshot {
return nil
}
- out := make([]FileSnapshot, 0, len(r.topHeap))
+ return buildFileSnapshots(r.snapshotInputs())
+}
+
+func (r *fileRanker) snapshotInputs() []fileSnapshotInput {
+ if r == nil {
+ return nil
+ }
+ inputs := make([]fileSnapshotInput, 0, len(r.topHeap))
for _, stats := range r.topHeap {
- out = append(out, stats.snapshot())
+ inputs = append(inputs, fileSnapshotInput{
+ path: stats.path,
+ accesses: stats.accesses,
+ bytesRead: stats.bytesRead,
+ bytesWritten: stats.bytesWritten,
+ totalLatency: stats.totalLatency,
+ maxLatency: stats.maxLatency,
+ })
}
+ return inputs
+}
+func buildFileSnapshots(inputs []fileSnapshotInput) []FileSnapshot {
+ out := make([]FileSnapshot, 0, len(inputs))
+ for _, in := range inputs {
+ out = append(out, in.toSnapshot())
+ }
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].Path < out[j].Path
})
-
return out
}
@@ -153,7 +182,7 @@ func (r *fileRanker) compactIfNeeded() {
r.byPath = kept
}
-func (s *fileRankStats) snapshot() FileSnapshot {
+func (s fileSnapshotInput) toSnapshot() FileSnapshot {
avg := 0.0
if s.accesses > 0 {
avg = float64(s.totalLatency) / float64(s.accesses)