From 72bb271a944f9b5de232464c7ea10033f65ec890 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" <75863576+jeffwashington@users.noreply.github.com> Date: Tue, 1 Jun 2021 13:17:49 -0500 Subject: [PATCH] add metric for collecting storages (#17527) --- runtime/src/accounts_db.rs | 30 ++++++++++++++++++++++++------ runtime/src/accounts_hash.rs | 7 +++++++ runtime/src/snapshot_utils.rs | 1 + 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index a45a008d3f..85814f9803 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -4244,11 +4244,19 @@ impl AccountsDb { check_hash: bool, ) -> Result<(Hash, u64), BankHashVerificationError> { if !use_index { + let mut time = Measure::start("collect"); let combined_maps = self.get_snapshot_storages(slot); + time.stop(); + + let timings = HashStats { + collect_snapshots_us: time.as_us(), + ..HashStats::default() + }; Self::calculate_accounts_hash_without_index( &combined_maps, Some(&self.thread_pool_clean), + timings, check_hash, ) } else { @@ -4365,10 +4373,10 @@ impl AccountsDb { pub fn calculate_accounts_hash_without_index( storages: &[SnapshotStorage], thread_pool: Option<&ThreadPool>, + mut stats: HashStats, check_hash: bool, ) -> Result<(Hash, u64), BankHashVerificationError> { - let scan_and_hash = || { - let mut stats = HashStats::default(); + let mut scan_and_hash = move || { // When calculating hashes, it is helpful to break the pubkeys found into bins based on the pubkey value. // More bins means smaller vectors to sort, copy, etc. const PUBKEY_BINS_FOR_CALCULATING_HASHES: usize = 64; @@ -5951,8 +5959,13 @@ pub mod tests { solana_logger::setup(); let (storages, _size, _slot_expected) = sample_storage(); - let result = - AccountsDb::calculate_accounts_hash_without_index(&storages, None, false).unwrap(); + let result = AccountsDb::calculate_accounts_hash_without_index( + &storages, + None, + HashStats::default(), + false, + ) + .unwrap(); let expected_hash = Hash::from_str("GKot5hBsd81kMupNCXHaqbhv3huEbxAFMLnpcX2hniwn").unwrap(); assert_eq!(result, (expected_hash, 0)); } @@ -5967,8 +5980,13 @@ pub mod tests { item.hash }); let sum = raw_expected.iter().map(|item| item.lamports).sum(); - let result = - AccountsDb::calculate_accounts_hash_without_index(&storages, None, false).unwrap(); + let result = AccountsDb::calculate_accounts_hash_without_index( + &storages, + None, + HashStats::default(), + false, + ) + .unwrap(); assert_eq!(result, (expected_hash, sum)); } diff --git a/runtime/src/accounts_hash.rs b/runtime/src/accounts_hash.rs index 86d46b39cc..61958ccf47 100644 --- a/runtime/src/accounts_hash.rs +++ b/runtime/src/accounts_hash.rs @@ -28,6 +28,7 @@ pub struct HashStats { pub hash_total: usize, pub unreduced_entries: usize, pub num_snapshot_storage: usize, + pub collect_snapshots_us: u64, } impl HashStats { fn log(&mut self) { @@ -35,6 +36,7 @@ impl HashStats { + self.zeros_time_total_us + self.hash_time_total_us + self.sort_time_total_us + + self.collect_snapshots_us + self.flatten_time_total_us; datapoint_info!( "calculate_accounts_hash_without_index", @@ -45,6 +47,11 @@ impl HashStats { ("hash_total", self.hash_total, i64), ("flatten", self.flatten_time_total_us, i64), ("unreduced_entries", self.unreduced_entries as i64, i64), + ( + "collect_snapshots_us", + self.collect_snapshots_us as i64, + i64 + ), ( "num_snapshot_storage", self.num_snapshot_storage as i64, diff --git a/runtime/src/snapshot_utils.rs b/runtime/src/snapshot_utils.rs index 2e2bef40b9..d98edf3593 100644 --- a/runtime/src/snapshot_utils.rs +++ b/runtime/src/snapshot_utils.rs @@ -1002,6 +1002,7 @@ pub fn process_accounts_package_pre( let (hash, lamports) = AccountsDb::calculate_accounts_hash_without_index( &accounts_package.storages, thread_pool, + crate::accounts_hash::HashStats::default(), false, ) .unwrap();