From bc08351a0a419c0879f29c4722722ff09b6f0590 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 23 Jun 2021 15:49:28 +0000 Subject: [PATCH] capture sort time in hash calculation (#18118) (#18153) (cherry picked from commit d3ee73e151dfe445dbad601cf2a139d64b269392) Co-authored-by: Jeff Washington (jwash) <75863576+jeffwashington@users.noreply.github.com> --- runtime/src/accounts_db.rs | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index d039df241f..6de80f878f 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -4817,6 +4817,7 @@ impl AccountsDb { stats.num_snapshot_storage = storage.slot_count(); let mismatch_found = AtomicU64::new(0); let range = bin_range.end - bin_range.start; + let sort_time = AtomicU64::new(0); let result: Vec>> = Self::scan_account_storage_no_bank( accounts_cache_and_ancestors, @@ -4864,9 +4865,15 @@ impl AccountsDb { } accum[pubkey_to_bin_index].push(source_item); }, - Self::sort_slot_storage_scan, + |x| { + let (result, timing) = Self::sort_slot_storage_scan(x); + sort_time.fetch_add(timing, Ordering::Relaxed); + result + }, ); + stats.sort_time_total_us += sort_time.load(Ordering::Relaxed); + if check_hash && mismatch_found.load(Ordering::Relaxed) > 0 { warn!( "{} mismatched account hash(es) found", @@ -4883,15 +4890,24 @@ impl AccountsDb { fn sort_slot_storage_scan( accum: Vec>, - ) -> Vec> { - accum - .into_par_iter() - .map(|mut items| { - // sort_by vs unstable because slot and write_version are already in order - items.sort_by(AccountsHash::compare_two_hash_entries); - items - }) - .collect() + ) -> (Vec>, u64) { + let time = AtomicU64::new(0); + ( + accum + .into_par_iter() + .map(|mut items| { + let mut sort_time = Measure::start("sort"); + { + // sort_by vs unstable because slot and write_version are already in order + items.sort_by(AccountsHash::compare_two_hash_entries); + } + sort_time.stop(); + time.fetch_add(sort_time.as_us(), Ordering::Relaxed); + items + }) + .collect(), + time.load(Ordering::Relaxed), + ) } // modeled after get_accounts_delta_hash