Skip to content

Commit a175b3b

Browse files
committed
Fix histogram bucket counts (fixes #1079)
1 parent 3c2edd2 commit a175b3b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

crates/trc/src/atomics/histogram.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use std::sync::atomic::{AtomicU64, Ordering};
88

99
use crate::MetricType;
1010

11-
use super::array::AtomicU64Array;
11+
use super::array::AtomicU32Array;
1212

1313
pub struct AtomicHistogram<const N: usize> {
1414
id: MetricType,
15-
buckets: AtomicU64Array<N>,
15+
buckets: AtomicU32Array<N>,
1616
upper_bounds: [u64; N],
1717
sum: AtomicU64,
1818
count: AtomicU64,
@@ -23,7 +23,7 @@ pub struct AtomicHistogram<const N: usize> {
2323
impl<const N: usize> AtomicHistogram<N> {
2424
pub const fn new(id: MetricType, upper_bounds: [u64; N]) -> Self {
2525
Self {
26-
buckets: AtomicU64Array::new(),
26+
buckets: AtomicU32Array::new(),
2727
upper_bounds,
2828
sum: AtomicU64::new(0),
2929
count: AtomicU64::new(0),
@@ -41,7 +41,7 @@ impl<const N: usize> AtomicHistogram<N> {
4141

4242
for (idx, upper_bound) in self.upper_bounds.iter().enumerate() {
4343
if value < *upper_bound {
44-
self.buckets.add(idx, value);
44+
self.buckets.add(idx, 1);
4545
return;
4646
}
4747
}
@@ -93,13 +93,13 @@ impl<const N: usize> AtomicHistogram<N> {
9393
self.buckets
9494
.inner()
9595
.iter()
96-
.map(|bucket| bucket.load(Ordering::Relaxed))
96+
.map(|bucket| bucket.load(Ordering::Relaxed) as u64)
9797
}
9898

9999
pub fn buckets_vec(&self) -> Vec<u64> {
100100
let mut vec = Vec::with_capacity(N);
101101
for bucket in self.buckets.inner().iter() {
102-
vec.push(bucket.load(Ordering::Relaxed));
102+
vec.push(bucket.load(Ordering::Relaxed) as u64);
103103
}
104104
vec
105105
}

0 commit comments

Comments
 (0)