Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add offset command line option to store-histogram #3296

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 35 additions & 13 deletions accounts-db/store-histogram/src/main.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -31,19 +31,31 @@ fn get_stars(x: usize, max: usize, width: usize) -> String {
s
}

fn calc(info: &[(usize, usize)], bin_widths: Vec<usize>) {
fn is_parsable<T>(string: String) -> Result<(), String>
where
T: FromStr,
T::Err: Display,
{
string
.parse::<T>()
.map(|_| ())
.map_err(|err| format!("error parsing '{string}': {err}"))
}

fn calc(info: &[(usize, usize)], bin_widths: Vec<usize>, 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!(
"outside of epoch: {}",
info.iter()
.filter(|x| x.0 < max_inclusive - 432_000)
.filter(|x| x.0 < max_inclusive - outside_slot)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is no longer an "epoch".
Maybe change it to something like "ancient boundary"?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed.

Copy link

@HaoranYi HaoranYi Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this print says "how many slots are there beyond ancient boundary"? How about this?

Suggested change
.filter(|x| x.0 < max_inclusive - outside_slot)
eprintln!(
"ancient boundary: {}, num_of_slots_beyond_ancient_bondary: {}", outside_slot,
info.iter()
.filter(|x| x.0 < max_inclusive - outside_slot).count()
):

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

.count()
);

Expand Down Expand Up @@ -130,9 +142,6 @@ fn calc(info: &[(usize, usize)], bin_widths: Vec<usize>) {
eprintln!("...");
}
let bin = &bins[i];
if bin.slot_min == 432_000 {
eprintln!("------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
}
let offset = format!("{:8}", bin.slot_min);

if i == 0 {
Expand Down Expand Up @@ -190,6 +199,9 @@ fn calc(info: &[(usize, usize)], bin_widths: Vec<usize>) {
s2 = format!("{s2}{s}");
});
eprintln!("{s2}");
if bin.slot_min < outside_slot && outside_slot <= bin.slot_max {
eprintln!("{}", String::from_utf8(vec![b'-'; 168]).unwrap());
}
}
}

Expand Down Expand Up @@ -237,9 +249,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::<i64>)
.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() {
Expand All @@ -263,15 +284,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);
Expand Down Expand Up @@ -302,8 +323,9 @@ pub mod tests {
.into_iter()
.map(|(slot, size)| (max - slot + base, size))
.collect::<Vec<_>>();
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);
}
}
Loading