Optionally disable metrics in pagecache itself
use std::iter::repeat;
use std::sync::atomic::AtomicUsize;
-use std::sync::atomic::Ordering::{Acquire, Relaxed};
use std::time::{Duration, Instant};
+#[cfg(feature = "no_metrics")]
+use std::marker::PhantomData;
+
+#[cfg(not(feature = "no_metrics"))]
+use std::sync::atomic::Ordering::{Acquire, Relaxed};
+
use historian::Histo;
lazy_static! {
@@ -12,8 +17,13 @@ lazy_static! {
}
pub(crate) fn clock() -> f64 {
+ if cfg!(feature = "no_metrics") {
+ 0.
+ } else {
let u = uptime();
- (u.as_secs() * 1_000_000_000) as f64 + f64::from(u.subsec_nanos())
+ (u.as_secs() * 1_000_000_000) as f64
+ + f64::from(u.subsec_nanos())
+ }
}
// not correct, since it starts counting at the first observance...
@@ -22,13 +32,20 @@ fn uptime() -> Duration {
static ref START: Instant = Instant::now();
}
+ if cfg!(feature = "no_metrics") {
+ Duration::new(0, 0)
+ } else {
START.elapsed()
}
+}
/// Measure the duration of an event, and call `Histo::measure()`.
pub(crate) struct Measure<'h> {
- histo: &'h Histo,
start: f64,
+ #[cfg(not(feature = "no_metrics"))]
+ histo: &'h Histo,
+ #[cfg(feature = "no_metrics")]
+ _pd: PhantomData<&'h ()>,
}
impl<'h> Measure<'h> {
@@ -36,6 +53,9 @@ impl<'h> Measure<'h> {
#[inline(always)]
pub(crate) fn new(histo: &'h Histo) -> Measure<'h> {
Measure {
+ #[cfg(feature = "no_metrics")]
+ _pd: PhantomData,
+ #[cfg(not(feature = "no_metrics"))]
histo,
start: clock(),
}
@@ -45,6 +65,7 @@ impl<'h> Measure<'h> {
impl<'h> Drop for Measure<'h> {
#[inline(always)]
fn drop(&mut self) {
+ #[cfg(not(feature = "no_metrics"))]
self.histo.measure(clock() - self.start);
}
}
@@ -52,6 +73,7 @@ impl<'h> Drop for Measure<'h> {
/// Measure the time spent on calling a given function in a given `Histo`.
#[inline(always)]
pub(crate) fn measure<F: FnOnce() -> R, R>(histo: &Histo, f: F) -> R {
+ #[cfg(not(feature = "no_metrics"))]
let _measure = Measure::new(histo);
f()
}
@@ -84,6 +106,7 @@ pub struct Metrics {
pub accountant_hold: Histo,
}
+#[cfg(not(feature = "no_metrics"))]
impl Metrics {
pub fn tree_looped(&self) {
self.tree_loops.fetch_add(1, Relaxed);
@@ -193,3 +216,12 @@ impl Metrics {
]);
}
}
+
+#[cfg(feature = "no_metrics")]
+impl Metrics {
+ pub fn tree_looped(&self) {}
+
+ pub fn log_looped(&self) {}
+
+ pub fn print_profile(&self) {}
+}
