From 3b4aad9df17639e25d8c77a700bb45c79649fba9 Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Sat, 8 Jan 2022 16:45:02 -0700 Subject: [PATCH] bank: fix executor cache metrics --- runtime/src/bank.rs | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 87f4c291d9..52e71a2589 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -249,24 +249,32 @@ mod executor_cache { #[derive(Debug, Default)] pub struct Stats { - pub hits: u64, - pub misses: u64, + pub hits: AtomicU64, + pub misses: AtomicU64, pub evictions: HashMap, + pub insertions: AtomicU64, + pub replacements: AtomicU64, } impl Stats { pub fn submit(&self, slot: Slot) { + let hits = self.hits.load(Relaxed); + let misses = self.misses.load(Relaxed); + let insertions = self.insertions.load(Relaxed); + let replacements = self.replacements.load(Relaxed); let evictions: u64 = self.evictions.values().sum(); datapoint_info!( "bank-executor-cache-stats", ("slot", slot, i64), - ("hits", self.hits, i64), - ("misses", self.misses, i64), + ("hits", hits, i64), + ("misses", misses, i64), ("evictions", evictions, i64), + ("insertions", insertions, i64), + ("replacements", replacements, i64), ); debug!( - "Executor Cache Stats -- Hits: {}, Misses: {}, Evictions: {}", - self.hits, self.misses, evictions + "Executor Cache Stats -- Hits: {}, Misses: {}, Evictions: {}, Insertions: {}, Replacements: {}", + hits, misses, evictions, insertions, replacements, ); if log_enabled!(log::Level::Trace) && !self.evictions.is_empty() { let mut evictions = self.evictions.iter().collect::>(); @@ -378,10 +386,14 @@ impl CachedExecutors { } fn get(&self, pubkey: &Pubkey) -> Option> { - self.executors.get(pubkey).map(|entry| { + if let Some(entry) = self.executors.get(pubkey) { + self.stats.hits.fetch_add(1, Relaxed); entry.epoch_count.fetch_add(1, Relaxed); - entry.executor.clone() - }) + Some(entry.executor.clone()) + } else { + self.stats.misses.fetch_add(1, Relaxed); + None + } } fn put(&mut self, executors: &[(&Pubkey, Arc)]) { @@ -389,12 +401,12 @@ impl CachedExecutors { .iter() .filter_map(|(key, executor)| { if let Some(mut entry) = self.executors.remove(key) { - saturating_add_assign!(self.stats.hits, 1); + self.stats.replacements.fetch_add(1, Relaxed); entry.executor = executor.clone(); let _ = self.executors.insert(**key, entry); None } else { - saturating_add_assign!(self.stats.misses, 1); + self.stats.insertions.fetch_add(1, Relaxed); Some((*key, executor)) } })