Skip to content

Commit

Permalink
Move Stats::submit to solana-runtime (solana-labs#686)
Browse files Browse the repository at this point in the history
* Move Stats::submit to solana-runtime

* fmt

* rename Stats to LoadedProgramStats

* move submit_loaded_programs_stats to bank::metricss and rename it to report_loaded_programs_stats

* add new log method to LoadedProgramStats and move some code there

* fix unused import

* reload stats in LoadedProgramStats::log

* remove old import
  • Loading branch information
kevinheavey authored Apr 17, 2024
1 parent 37fbd33 commit 8edc6cc
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 33 deletions.
33 changes: 8 additions & 25 deletions program-runtime/src/loaded_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ pub struct LoadedProgram {

/// Global cache statistics for [ProgramCache].
#[derive(Debug, Default)]
pub struct Stats {
pub struct LoadedProgramStats {
/// a program was already in the cache
pub hits: AtomicU64,
/// a program was not found and loaded instead
Expand All @@ -202,9 +202,11 @@ pub struct Stats {
pub empty_entries: AtomicU64,
}

impl Stats {
/// Logs the measurement values
pub fn submit(&self, slot: Slot) {
impl LoadedProgramStats {
pub fn reset(&mut self) {
*self = LoadedProgramStats::default();
}
pub fn log(&self) {
let hits = self.hits.load(Ordering::Relaxed);
let misses = self.misses.load(Ordering::Relaxed);
let evictions: u64 = self.evictions.values().sum();
Expand All @@ -216,21 +218,6 @@ impl Stats {
let prunes_orphan = self.prunes_orphan.load(Ordering::Relaxed);
let prunes_environment = self.prunes_environment.load(Ordering::Relaxed);
let empty_entries = self.empty_entries.load(Ordering::Relaxed);
datapoint_info!(
"loaded-programs-cache-stats",
("slot", slot, i64),
("hits", hits, i64),
("misses", misses, i64),
("evictions", evictions, i64),
("reloads", reloads, i64),
("insertions", insertions, i64),
("lost_insertions", lost_insertions, i64),
("replace_entry", replacements, i64),
("one_hit_wonders", one_hit_wonders, i64),
("prunes_orphan", prunes_orphan, i64),
("prunes_environment", prunes_environment, i64),
("empty_entries", empty_entries, i64),
);
debug!(
"Loaded Programs Cache Stats -- Hits: {}, Misses: {}, Evictions: {}, Reloads: {}, Insertions: {} Lost-Insertions: {}, Replacements: {}, One-Hit-Wonders: {}, Prunes-Orphan: {}, Prunes-Environment: {}, Empty: {}",
hits, misses, evictions, reloads, insertions, lost_insertions, replacements, one_hit_wonders, prunes_orphan, prunes_environment, empty_entries
Expand All @@ -254,10 +241,6 @@ impl Stats {
);
}
}

pub fn reset(&mut self) {
*self = Stats::default();
}
}

/// Time measurements for loading a single [LoadedProgram].
Expand Down Expand Up @@ -613,7 +596,7 @@ pub struct ProgramCache<FG: ForkGraph> {
/// List of loaded programs which should be recompiled before the next epoch (but don't have to).
pub programs_to_recompile: Vec<(Pubkey, Arc<LoadedProgram>)>,
/// Statistics counters
pub stats: Stats,
pub stats: LoadedProgramStats,
/// Reference to the block store
pub fork_graph: Option<Arc<RwLock<FG>>>,
/// Coordinates TX batches waiting for others to complete their task during cooperative loading
Expand Down Expand Up @@ -758,7 +741,7 @@ impl<FG: ForkGraph> ProgramCache<FG> {
environments: ProgramRuntimeEnvironments::default(),
upcoming_environments: None,
programs_to_recompile: Vec::default(),
stats: Stats::default(),
stats: LoadedProgramStats::default(),
fork_graph: None,
loading_task_waiter: Arc::new(LoadingTaskWaiter::default()),
}
Expand Down
16 changes: 9 additions & 7 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1360,13 +1360,15 @@ impl Bank {
},
);

parent
.transaction_processor
.program_cache
.read()
.unwrap()
.stats
.submit(parent.slot());
report_loaded_programs_stats(
&parent
.transaction_processor
.program_cache
.read()
.unwrap()
.stats,
parent.slot(),
);

new.transaction_processor
.program_cache
Expand Down
37 changes: 36 additions & 1 deletion runtime/src/bank/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use {
crate::bank::Bank,
solana_program_runtime::loaded_programs::LoadedProgramStats,
solana_sdk::clock::{Epoch, Slot},
std::sync::atomic::{AtomicU64, Ordering::Relaxed},
std::sync::atomic::{
AtomicU64,
Ordering::{self, Relaxed},
},
};

pub(crate) struct NewEpochTimings {
Expand Down Expand Up @@ -199,3 +203,34 @@ pub(crate) fn report_partitioned_reward_metrics(bank: &Bank, timings: RewardsSto
("post_capitalization", timings.post_capitalization, i64),
);
}

/// Logs the measurement values
pub(crate) fn report_loaded_programs_stats(stats: &LoadedProgramStats, slot: Slot) {
let hits = stats.hits.load(Ordering::Relaxed);
let misses = stats.misses.load(Ordering::Relaxed);
let evictions: u64 = stats.evictions.values().sum();
let reloads = stats.reloads.load(Ordering::Relaxed);
let insertions = stats.insertions.load(Ordering::Relaxed);
let lost_insertions = stats.lost_insertions.load(Ordering::Relaxed);
let replacements = stats.replacements.load(Ordering::Relaxed);
let one_hit_wonders = stats.one_hit_wonders.load(Ordering::Relaxed);
let prunes_orphan = stats.prunes_orphan.load(Ordering::Relaxed);
let prunes_environment = stats.prunes_environment.load(Ordering::Relaxed);
let empty_entries = stats.empty_entries.load(Ordering::Relaxed);
datapoint_info!(
"loaded-programs-cache-stats",
("slot", slot, i64),
("hits", hits, i64),
("misses", misses, i64),
("evictions", evictions, i64),
("reloads", reloads, i64),
("insertions", insertions, i64),
("lost_insertions", lost_insertions, i64),
("replace_entry", replacements, i64),
("one_hit_wonders", one_hit_wonders, i64),
("prunes_orphan", prunes_orphan, i64),
("prunes_environment", prunes_environment, i64),
("empty_entries", empty_entries, i64),
);
stats.log();
}

0 comments on commit 8edc6cc

Please sign in to comment.