Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
add metric for collecting storages (#17527) (#17675)
Browse files Browse the repository at this point in the history
(cherry picked from commit 72bb271)

# Conflicts:
#	runtime/src/accounts_db.rs
#	runtime/src/snapshot_utils.rs

Co-authored-by: Jeff Washington (jwash) <75863576+jeffwashington@users.noreply.github.com>
  • Loading branch information
mergify[bot] and jeffwashington authored Jun 3, 2021
1 parent eb1a04a commit a00fbbf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
30 changes: 24 additions & 6 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -5950,8 +5958,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));
}
Expand All @@ -5966,8 +5979,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));
}
Expand Down
7 changes: 7 additions & 0 deletions runtime/src/accounts_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ 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) {
let total_time_us = self.scan_time_total_us
+ 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",
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions runtime/src/snapshot_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,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();
Expand Down

0 comments on commit a00fbbf

Please sign in to comment.