use std::{sync::atomic::Ordering, time::Instant};
use atomic_float::AtomicF64;
pub static STAT_APPLY_SECS: StatCounter = StatCounter {
counter: AtomicF64::new(0.0),
};
pub static STAT_SMT_GET_SECS: StatCounter = StatCounter {
counter: AtomicF64::new(0.0),
};
pub static STAT_SMT_INSERT_SECS: StatCounter = StatCounter {
counter: AtomicF64::new(0.0),
};
pub static STAT_MELVM_RUNTIME_SECS: StatCounter = StatCounter {
counter: AtomicF64::new(0.0),
};
pub static STAT_MELPOW_SECS: StatCounter = StatCounter {
counter: AtomicF64::new(0.0),
};
pub struct StatCounter {
counter: AtomicF64,
}
impl StatCounter {
pub fn value(&self) -> f64 {
self.counter.load(Ordering::Relaxed)
}
pub(crate) fn incr(&self, delta: f64) {
self.counter.fetch_add(delta, Ordering::Relaxed);
}
pub(crate) fn timer_secs(&self, name: &'static str) -> StatTimer<'_> {
StatTimer {
r: self,
_name: name,
start: Instant::now(),
}
}
}
#[allow(unused)]
pub struct StatTimer<'a> {
r: &'a StatCounter,
_name: &'static str,
start: Instant,
}
impl<'a> Drop for StatTimer<'a> {
fn drop(&mut self) {
self.r.incr(self.start.elapsed().as_secs_f64())
}
}