#[derive(Clone, Copy)]
pub(crate) enum C {
Turn,
EmptyTurn,
Lead,
Handoff,
Park,
Taken,
}
#[cfg(feature = "diagnostics")]
static COUNTERS: [std::sync::atomic::AtomicU64; 9] = [const { std::sync::atomic::AtomicU64::new(0) }; 9];
#[inline]
pub(crate) fn bump(c: C) {
#[cfg(feature = "diagnostics")]
COUNTERS[c as usize].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
#[cfg(not(feature = "diagnostics"))]
let _ = c;
}
#[cfg(feature = "diagnostics")]
#[inline]
pub(crate) fn idle(ns: u64) {
COUNTERS[6].fetch_add(ns, std::sync::atomic::Ordering::Relaxed);
}
#[cfg(feature = "diagnostics")]
#[inline]
pub(crate) fn parked(ns: u64) {
COUNTERS[7].fetch_add(ns, std::sync::atomic::Ordering::Relaxed);
}
#[cfg(feature = "diagnostics")]
#[inline]
pub(crate) fn relock(ns: u64) {
COUNTERS[8].fetch_add(ns, std::sync::atomic::Ordering::Relaxed);
}
#[cfg(feature = "diagnostics")]
#[derive(Debug, Clone, Copy, Default)]
pub struct Snapshot {
pub turns: u64,
pub empty_turns: u64,
pub leads: u64,
pub handoffs: u64,
pub parks: u64,
pub taken: u64,
pub idle_ns: u64,
pub parked_ns: u64,
pub relock_ns: u64,
}
#[cfg(feature = "diagnostics")]
pub fn snapshot() -> Snapshot {
let g = |i: usize| COUNTERS[i].load(std::sync::atomic::Ordering::Relaxed);
Snapshot { turns: g(0), empty_turns: g(1), leads: g(2), handoffs: g(3), parks: g(4), taken: g(5), idle_ns: g(6), parked_ns: g(7), relock_ns: g(8) }
}
#[cfg(feature = "diagnostics")]
pub fn reset() {
for c in &COUNTERS {
c.store(0, std::sync::atomic::Ordering::Relaxed);
}
}