Skip to content

Commit 7951bc8

Browse files
committed
Pass exemplar timestamp explicitly
This is a bit more expensive when you don't pass it: ``` histogram without exemplars time: [3.1824 ns 3.2017 ns 3.2235 ns] change: [-3.6414% +0.1893% +3.1022%] (p = 0.92 > 0.05) No change in performance detected. histogram with exemplars (no exemplar passed) time: [6.2238 ns 6.2487 ns 6.2770 ns] change: [+7.5129% +8.3245% +9.0265%] (p = 0.00 < 0.05) Performance has regressed. histogram with exemplars (some exemplar passed) time: [70.907 ns 71.667 ns 72.493 ns] change: [+1.4206% +2.3509% +3.3463%] (p = 0.00 < 0.05) Performance has regressed. ``` It should amortize as one passes the same timestamp in multiple observations.
1 parent 93db069 commit 7951bc8

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

benches/exemplars.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn exemplars(c: &mut Criterion) {
1919
let histogram = HistogramWithExemplars::<Exemplar>::new(BUCKETS.into_iter().copied());
2020

2121
b.iter(|| {
22-
histogram.observe(1.0, None);
22+
histogram.observe(1.0, None, None);
2323
});
2424
});
2525

@@ -28,7 +28,7 @@ pub fn exemplars(c: &mut Criterion) {
2828
let exemplar = vec![("TraceID".to_owned(), "deadfeed".to_owned())];
2929

3030
b.iter(|| {
31-
histogram.observe(1.0, Some(exemplar.clone()));
31+
histogram.observe(1.0, Some(exemplar.clone()), None);
3232
});
3333
});
3434
}

src/metrics/exemplar.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ impl<S> HistogramWithExemplars<S> {
250250

251251
/// Observe the given value, optionally providing a label set and thus
252252
/// setting the [`Exemplar`] value.
253-
pub fn observe(&self, v: f64, label_set: Option<S>) {
253+
pub fn observe(&self, v: f64, label_set: Option<S>, timestamp: Option<SystemTime>) {
254254
let mut inner = self.inner.write();
255255
let bucket = inner.histogram.observe_and_bucket(v);
256256
if let (Some(bucket), Some(label_set)) = (bucket, label_set) {
@@ -259,7 +259,7 @@ impl<S> HistogramWithExemplars<S> {
259259
Exemplar {
260260
label_set,
261261
value: v,
262-
time: SystemTime::now(),
262+
time: timestamp.unwrap_or_else(SystemTime::now),
263263
},
264264
);
265265
}

0 commit comments

Comments
 (0)