pub mod genesis_state;
pub mod record;
pub mod stats;
pub mod weight_params;
pub use record::BenchRecord;
pub use stats::{StatSelect, Stats};
pub use weight_params::WeightParams;
use clap::Args;
use rand::prelude::*;
use sc_sysinfo::gather_sysinfo;
use serde::Serialize;
#[derive(Clone, Copy)]
pub struct UnderscoreHelper;
impl handlebars::HelperDef for UnderscoreHelper {
fn call<'reg: 'rc, 'rc>(
&self,
h: &handlebars::Helper,
_: &handlebars::Handlebars,
_: &handlebars::Context,
_rc: &mut handlebars::RenderContext,
out: &mut dyn handlebars::Output,
) -> handlebars::HelperResult {
use handlebars::JsonRender;
let param = h.param(0).unwrap();
let underscore_param = underscore(param.value().render());
out.write(&underscore_param)?;
Ok(())
}
}
fn underscore<Number>(i: Number) -> String
where
Number: std::string::ToString,
{
let mut s = String::new();
let i_str = i.to_string();
let a = i_str.chars().rev().enumerate();
for (idx, val) in a {
if idx != 0 && idx % 3 == 0 {
s.insert(0, '_');
}
s.insert(0, val);
}
s
}
pub fn new_rng(seed: Option<u64>) -> (impl rand::Rng, u64) {
let seed = seed.unwrap_or(rand::thread_rng().gen::<u64>());
(rand_pcg::Pcg64::seed_from_u64(seed), seed)
}
pub fn check_build_profile() -> Result<(), String> {
if cfg!(build_profile = "debug") {
Err("Detected a `debug` profile".into())
} else if !cfg!(build_opt_level = "3") {
Err("The optimization level is not set to 3".into())
} else {
Ok(())
}
}
#[derive(Debug, Default, Serialize, Clone, PartialEq, Args)]
#[command(rename_all = "kebab-case")]
pub struct HostInfoParams {
#[arg(long)]
pub hostname_override: Option<String>,
#[arg(long, default_value = "<UNKNOWN>")]
pub hostname_fallback: String,
#[arg(long, default_value = "<UNKNOWN>")]
pub cpuname_fallback: String,
}
impl HostInfoParams {
pub fn hostname(&self) -> String {
self.hostname_override
.clone()
.or(gethostname::gethostname().into_string().ok())
.unwrap_or(self.hostname_fallback.clone())
}
pub fn cpuname(&self) -> String {
gather_sysinfo().cpu.unwrap_or(self.cpuname_fallback.clone())
}
}