use core::cell::Cell;
#[cfg_attr(docsrs, doc(cfg(feature = "stats")))]
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq)]
#[non_exhaustive]
pub struct ArenaStats {
pub normal_local_chunks_allocated: u64,
pub oversized_local_chunks_allocated: u64,
pub normal_shared_chunks_allocated: u64,
pub oversized_shared_chunks_allocated: u64,
pub total_bytes_allocated: u64,
pub wasted_tail_bytes: u64,
pub relocations: u64,
}
#[derive(Debug, Default)]
pub struct StatsStorage {
pub normal_local_chunks_allocated: Cell<u64>,
pub oversized_local_chunks_allocated: Cell<u64>,
pub normal_shared_chunks_allocated: Cell<u64>,
pub oversized_shared_chunks_allocated: Cell<u64>,
pub total_bytes_allocated: Cell<u64>,
pub wasted_tail_bytes: Cell<u64>,
pub relocations: Cell<u64>,
}
impl StatsStorage {
#[inline]
#[must_use]
pub fn snapshot(&self) -> ArenaStats {
ArenaStats {
normal_local_chunks_allocated: self.normal_local_chunks_allocated.get(),
oversized_local_chunks_allocated: self.oversized_local_chunks_allocated.get(),
normal_shared_chunks_allocated: self.normal_shared_chunks_allocated.get(),
oversized_shared_chunks_allocated: self.oversized_shared_chunks_allocated.get(),
total_bytes_allocated: self.total_bytes_allocated.get(),
wasted_tail_bytes: self.wasted_tail_bytes.get(),
relocations: self.relocations.get(),
}
}
#[inline]
pub fn add(field: &Cell<u64>, delta: u64) {
field.set(field.get() + delta);
}
}
macro_rules! bump_stat {
($inner:expr, $field:ident, $delta:expr) => {{
$crate::arena_stats::StatsStorage::add(&$inner.stats.$field, $delta);
}};
}
pub(crate) use bump_stat;