use std::time::Duration;
use clap::Parser;
use indicatif::{
HumanBytes, HumanCount, MultiProgress, ParallelProgressIterator, ProgressBar, ProgressStyle,
};
use metrics_procession::recorder::ProcessionRecorder;
use rayon::iter::{IntoParallelIterator, ParallelIterator};
#[derive(Debug, Parser)]
#[clap(about)]
struct Args {
#[clap(default_value_t = 4096)]
count: u64,
}
fn main() {
let Args { count } = Args::parse();
let recorder = ProcessionRecorder::default();
metrics::set_global_recorder(recorder.clone()).unwrap();
let mpg = MultiProgress::new();
let pg = mpg.add(ProgressBar::new(count * (u16::MAX as u64)).with_style(
ProgressStyle::with_template("[{eta}] {bar:40.cyan/blue} {per_sec} {percent}%").unwrap(),
));
let pg2 = mpg.add(
ProgressBar::new_spinner()
.with_style(ProgressStyle::with_template("[{elapsed}] {msg}").unwrap())
.with_message("getting started"),
);
pg2.enable_steady_tick(Duration::from_millis(500));
let mut ttl = 0;
for i in 0..count {
(0..=u16::MAX)
.into_par_iter()
.progress_with(pg.clone())
.for_each(|i| {
metrics::counter!("some-counter", "with-a-label" => format!("{}", i % 4096))
.increment(1);
});
ttl += u16::MAX as u64;
pg2.set_message(format!(
"{} events take up {} space in memory ({}/event)",
HumanCount((i + 1) * (u16::MAX as u64)),
HumanBytes(recorder.memory_size() as u64),
HumanBytes(recorder.memory_size() as u64 / ttl),
));
}
pg2.abandon();
std::thread::sleep(Duration::from_secs(15));
}