diff --git a/accounts-db/store-histogram/src/main.rs b/accounts-db/store-histogram/src/main.rs index f1fea98a8f79c8..64bab0bd39422c 100644 --- a/accounts-db/store-histogram/src/main.rs +++ b/accounts-db/store-histogram/src/main.rs @@ -1,7 +1,7 @@ #![allow(clippy::arithmetic_side_effects)] use { - clap::{crate_description, crate_name, value_t_or_exit, App, Arg}, - std::{fs, path::PathBuf}, + clap::{crate_description, crate_name, value_t, value_t_or_exit, App, Arg}, + std::{fmt::Display, fs, path::PathBuf, str::FromStr}, }; struct Bin { @@ -31,19 +31,32 @@ fn get_stars(x: usize, max: usize, width: usize) -> String { s } -fn calc(info: &[(usize, usize)], bin_widths: Vec) { +fn is_parsable(string: String) -> Result<(), String> +where + T: FromStr, + T::Err: Display, +{ + string + .parse::() + .map(|_| ()) + .map_err(|err| format!("error parsing '{string}': {err}")) +} + +fn calc(info: &[(usize, usize)], bin_widths: Vec, offset: i64) { let mut info = info.to_owned(); info.sort(); let min = info.first().unwrap().0; let max_inclusive = info.last().unwrap().0; + let outside_slot = 432_000 - offset as usize; eprintln!("storages: {}", info.len()); eprintln!("lowest slot: {min}"); eprintln!("highest slot: {max_inclusive}"); eprintln!("slot range: {}", max_inclusive - min + 1); + eprintln!("ancient boundary: {}", outside_slot); eprintln!( - "outside of epoch: {}", + "number of slots beyond ancient bondary: {}", info.iter() - .filter(|x| x.0 < max_inclusive - 432_000) + .filter(|x| x.0 < max_inclusive - outside_slot) .count() ); @@ -54,14 +67,36 @@ fn calc(info: &[(usize, usize)], bin_widths: Vec) { } else { bin_widths[i + 1] }; - let abin = Bin { - slot_min: bin_widths[i], - slot_max: next, - count: 0, - min_size: usize::MAX, - max_size: 0, - sum_size: 0, - avg: 0, + let abin = if bin_widths[i] < outside_slot && outside_slot < next { + let abin = Bin { + slot_min: bin_widths[i], + slot_max: outside_slot, + count: 0, + min_size: usize::MAX, + max_size: 0, + sum_size: 0, + avg: 0, + }; + bins.push(abin); + Bin { + slot_min: outside_slot, + slot_max: next, + count: 0, + min_size: usize::MAX, + max_size: 0, + sum_size: 0, + avg: 0, + } + } else { + Bin { + slot_min: bin_widths[i], + slot_max: next, + count: 0, + min_size: usize::MAX, + max_size: 0, + sum_size: 0, + avg: 0, + } }; bins.push(abin); } @@ -130,8 +165,8 @@ fn calc(info: &[(usize, usize)], bin_widths: Vec) { eprintln!("..."); } let bin = &bins[i]; - if bin.slot_min == 432_000 { - eprintln!("------------------------------------------------------------------------------------------------------------------------------------------------------------------------"); + if bin.slot_min == outside_slot { + eprintln!("{}", String::from_utf8(vec![b'-'; 168]).unwrap()); } let offset = format!("{:8}", bin.slot_min); @@ -237,9 +272,18 @@ fn main() { .value_name("PATH") .help("ledger path"), ) + .arg( + Arg::with_name("offset") + .long("offset") + .takes_value(true) + .value_name("SLOT-OFFSET") + .validator(is_parsable::) + .help("ancient offset"), + ) .get_matches(); let ledger = value_t_or_exit!(matches, "ledger", String); + let offset = value_t!(matches, "offset", i64).unwrap_or(100_000); let path: PathBuf = [&ledger, "accounts", "run"].iter().collect(); if path.is_dir() { @@ -263,15 +307,15 @@ fn main() { } } eprintln!("======== Normal Histogram"); - calc(&info, normal_bin_widths()); + calc(&info, normal_bin_widths(), offset); eprintln!("========"); eprintln!("\n======== Normal Ancient Histogram"); - calc(&info, normal_ancient()); + calc(&info, normal_ancient(), offset); eprintln!("========"); eprintln!("\n======== Normal Ancient 10K Histogram"); - calc(&info, normal_10k()); + calc(&info, normal_10k(), offset); eprintln!("========"); } else { panic!("couldn't read folder: {path:?}, {:?}", dir); @@ -302,8 +346,9 @@ pub mod tests { .into_iter() .map(|(slot, size)| (max - slot + base, size)) .collect::>(); - calc(&info, normal_bin_widths()); - calc(&info, normal_ancient()); - calc(&info, normal_10k()); + let offset = 100_000i64; + calc(&info, normal_bin_widths(), offset); + calc(&info, normal_ancient(), offset); + calc(&info, normal_10k(), offset); } }