use core::sync::atomic::Ordering;
use portable_atomic::AtomicU64;
pub(crate) static FUSED: AtomicU64 = AtomicU64::new(0);
pub(crate) static CHUNK_KEYS: AtomicU64 = AtomicU64::new(0);
pub(crate) static KEY_BYTES: AtomicU64 = AtomicU64::new(0);
pub(crate) static NEW_BYTES: AtomicU64 = AtomicU64::new(0);
pub(crate) static SLICES: AtomicU64 = AtomicU64::new(0);
pub(crate) static REFS_UP: AtomicU64 = AtomicU64::new(0);
pub(crate) static REFS_DOWN: AtomicU64 = AtomicU64::new(0);
#[inline]
pub(crate) fn add(counter: &AtomicU64, by: usize) {
counter.fetch_add(by as u64, Ordering::Relaxed);
}
#[derive(Clone, Copy, Debug, Default)]
pub struct Counts {
pub fused: u64,
pub chunk_keys: u64,
pub key_bytes: u64,
pub new_bytes: u64,
pub slices: u64,
pub refs_up: u64,
pub refs_down: u64,
}
impl Counts {
#[must_use]
pub fn now() -> Self {
let read = |counter: &AtomicU64| counter.load(Ordering::Relaxed);
Self {
fused: read(&FUSED),
chunk_keys: read(&CHUNK_KEYS),
key_bytes: read(&KEY_BYTES),
new_bytes: read(&NEW_BYTES),
slices: read(&SLICES),
refs_up: read(&REFS_UP),
refs_down: read(&REFS_DOWN),
}
}
#[must_use]
pub fn since(self, before: Self) -> Self {
Self {
fused: self.fused - before.fused,
chunk_keys: self.chunk_keys - before.chunk_keys,
key_bytes: self.key_bytes - before.key_bytes,
new_bytes: self.new_bytes - before.new_bytes,
slices: self.slices - before.slices,
refs_up: self.refs_up - before.refs_up,
refs_down: self.refs_down - before.refs_down,
}
}
}