use std::fmt::Debug;
pub trait ARCacheWriteStat<K> {
fn cache_clear(&mut self) {}
fn cache_read(&mut self) {}
fn cache_hit(&mut self) {}
fn include(&mut self, _k: &K) {}
fn include_haunted(&mut self, k: &K) {
self.include(k)
}
fn modify(&mut self, _k: &K) {}
fn ghost_frequent_revive(&mut self, _k: &K) {}
fn ghost_recent_revive(&mut self, _k: &K) {}
fn evict_from_recent(&mut self, _k: &K) {}
fn evict_from_frequent(&mut self, _k: &K) {}
fn p_weight(&mut self, _p: u64) {}
fn shared_max(&mut self, _i: u64) {}
fn freq(&mut self, _i: u64) {}
fn recent(&mut self, _i: u64) {}
fn all_seen_keys(&mut self, _i: u64) {}
}
pub trait ARCacheReadStat {
fn cache_read(&mut self) {}
fn cache_local_hit(&mut self) {}
fn cache_main_hit(&mut self) {}
fn include(&mut self) {}
fn failed_include(&mut self) {}
fn local_include(&mut self) {}
}
impl<K> ARCacheWriteStat<K> for () {}
impl ARCacheReadStat for () {}
#[derive(Debug)]
pub struct TraceStat {}
impl<K> ARCacheWriteStat<K> for TraceStat
where
K: Debug,
{
fn include(&mut self, k: &K) {
tracing::trace!(?k, "include");
}
fn include_haunted(&mut self, k: &K) {
tracing::trace!(?k, "include_haunted");
}
fn modify(&mut self, k: &K) {
tracing::trace!(?k, "modify");
}
fn ghost_frequent_revive(&mut self, k: &K) {
tracing::trace!(?k, "ghost_frequent_revive");
}
fn ghost_recent_revive(&mut self, k: &K) {
tracing::trace!(?k, "ghost_recent_revive");
}
fn evict_from_recent(&mut self, k: &K) {
tracing::trace!(?k, "evict_from_recent");
}
fn evict_from_frequent(&mut self, k: &K) {
tracing::trace!(?k, "evict_from_frequent");
}
}
#[derive(Debug, Default)]
pub struct WriteCountStat {
pub read_ops: u64,
pub read_hits: u64,
pub p_weight: u64,
pub shared_max: u64,
pub freq: u64,
pub recent: u64,
pub all_seen_keys: u64,
}
impl<K> ARCacheWriteStat<K> for WriteCountStat {
fn cache_clear(&mut self) {
self.read_ops = 0;
self.read_hits = 0;
}
fn cache_read(&mut self) {
self.read_ops += 1;
}
fn cache_hit(&mut self) {
self.read_hits += 1;
}
fn p_weight(&mut self, p: u64) {
self.p_weight = p;
}
fn shared_max(&mut self, i: u64) {
self.shared_max = i;
}
fn freq(&mut self, i: u64) {
self.freq = i;
}
fn recent(&mut self, i: u64) {
self.recent = i;
}
fn all_seen_keys(&mut self, i: u64) {
self.all_seen_keys = i;
}
}
#[derive(Debug, Default, Clone)]
pub struct ReadCountStat {
pub read_ops: u64,
pub local_hit: u64,
pub main_hit: u64,
pub include: u64,
pub failed_include: u64,
pub local_include: u64,
}
impl ARCacheReadStat for ReadCountStat {
fn cache_read(&mut self) {
self.read_ops += 1;
}
fn cache_local_hit(&mut self) {
self.local_hit += 1;
}
fn cache_main_hit(&mut self) {
self.main_hit += 1;
}
fn include(&mut self) {
self.include += 1;
}
fn failed_include(&mut self) {
self.failed_include += 1;
}
fn local_include(&mut self) {
self.local_include += 1;
}
}