summaryrefslogtreecommitdiff
path: root/internal/statsengine/histogram.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/histogram.go
parent0d4ef22478a470d86ce907beedcaa726d0d46c73 (diff)
statsengine: build snapshots outside engine mutex
Diffstat (limited to 'internal/statsengine/histogram.go')
-rw-r--r--internal/statsengine/histogram.go23
1 files changed, 21 insertions, 2 deletions
diff --git a/internal/statsengine/histogram.go b/internal/statsengine/histogram.go
index 550efe0..42460ea 100644
--- a/internal/statsengine/histogram.go
+++ b/internal/statsengine/histogram.go
@@ -7,6 +7,11 @@ type histogram struct {
total uint64
}
+type histogramSnapshotInput struct {
+ counts [histogramBucketCount]uint64
+ total uint64
+}
+
var histogramBoundariesNs = [histogramBucketCount - 1]uint64{
1_000,
10_000,
@@ -47,6 +52,20 @@ func (h *histogram) Snapshot() HistogramSnapshot {
return NewHistogramSnapshot(0, nil)
}
+ return buildHistogramSnapshot(h.snapshotInputs())
+}
+
+func (h *histogram) snapshotInputs() histogramSnapshotInput {
+ if h == nil {
+ return histogramSnapshotInput{}
+ }
+ return histogramSnapshotInput{
+ counts: h.counts,
+ total: h.total,
+ }
+}
+
+func buildHistogramSnapshot(in histogramSnapshotInput) HistogramSnapshot {
buckets := make([]HistogramBucketSnapshot, 0, histogramBucketCount)
for i := 0; i < histogramBucketCount; i++ {
lower, upper := histogramBucketRange(i)
@@ -54,11 +73,11 @@ func (h *histogram) Snapshot() HistogramSnapshot {
Label: histogramLabels[i],
LowerNs: lower,
UpperNs: upper,
- Count: h.counts[i],
+ Count: in.counts[i],
})
}
- return NewHistogramSnapshot(h.total, buckets)
+ return NewHistogramSnapshot(in.total, buckets)
}
func histogramBucketIndex(durationNs uint64) int {