diff --git a/canbench-bin/src/lib.rs b/canbench-bin/src/lib.rs index af02a48..b08d749 100644 --- a/canbench-bin/src/lib.rs +++ b/canbench-bin/src/lib.rs @@ -27,15 +27,8 @@ pub fn run_benchmarks( persist: bool, results_file: &PathBuf, verbose: bool, - custom_drun_path: Option, ) { - let drun_path = match custom_drun_path { - Some(custom_drun_path) => custom_drun_path, - None => { - maybe_download_drun(verbose); - download_drun_path() - } - }; + maybe_download_drun(verbose); let current_results = match results_file::read(results_file) { Ok(current_results) => current_results, @@ -62,7 +55,7 @@ pub fn run_benchmarks( println!("---------------------------------------------------"); println!(); - let result = run_benchmark(canister_wasm_path, drun_path.clone(), bench_fn); + let result = run_benchmark(canister_wasm_path, bench_fn); print_benchmark(bench_fn, &result, current_results.get(bench_fn)); results.insert(bench_fn.to_string(), result); @@ -98,7 +91,7 @@ fn canbench_dir() -> PathBuf { } // Path to drun. -fn download_drun_path() -> PathBuf { +fn drun_path() -> PathBuf { canbench_dir().join("drun") } @@ -107,7 +100,7 @@ fn maybe_download_drun(verbose: bool) { const DRUN_LINUX_SHA: &str = "182b800a7979e1e3e516e54e4b9980e5407ced7464c0b3aec9ff7af6e9e69a1b"; const DRUN_MAC_SHA: &str = "8e0d0758d5a5c6f367e2c374dc7eae0106c7f46a3457f81018af6d5159d2dad4"; - if download_drun_path().exists() { + if drun_path().exists() { // Drun found. Verify that it's the version we expect it to be. let expected_sha = match env::consts::OS { "linux" => DRUN_LINUX_SHA, @@ -115,7 +108,7 @@ fn maybe_download_drun(verbose: bool) { _ => panic!("only linux and macos are currently supported."), }; - let drun_sha = sha256::try_digest(download_drun_path()).unwrap(); + let drun_sha = sha256::try_digest(drun_path()).unwrap(); if drun_sha == expected_sha { // Shas match. No need to download drun. @@ -153,20 +146,20 @@ fn download_drun(verbose: bool) { .expect("Failed to download drun"); let mut decoder = GzDecoder::new(&drun_compressed[..]); - let mut file = File::create(download_drun_path()).expect("Failed to create drun file"); + let mut file = File::create(drun_path()).expect("Failed to create drun file"); std::io::copy(&mut decoder, &mut file).expect("Failed to write drun file"); // Make the file executable. Command::new("chmod") .arg("+x") - .arg(download_drun_path()) + .arg(drun_path()) .status() .unwrap(); } // Runs the given benchmark. -fn run_benchmark(canister_wasm_path: &Path, drun_path: PathBuf, bench_fn: &str) -> BenchResult { +fn run_benchmark(canister_wasm_path: &Path, bench_fn: &str) -> BenchResult { // drun is used for running the benchmark. // First, we create a temporary file with steps for drun to execute the benchmark. let mut temp_file = tempfile::Builder::new().tempfile().unwrap(); @@ -182,7 +175,7 @@ query rwlgt-iiaaa-aaaaa-aaaaa-cai {}{} \"DIDL\x00\x00\"", .unwrap(); // Run the benchmark with drun. - let drun_output = Command::new(drun_path) + let drun_output = Command::new(drun_path()) .args(vec![ temp_file.into_temp_path().to_str().unwrap(), "--instruction-limit", diff --git a/canbench-bin/src/main.rs b/canbench-bin/src/main.rs index f607d18..6dedd7e 100644 --- a/canbench-bin/src/main.rs +++ b/canbench-bin/src/main.rs @@ -22,25 +22,25 @@ struct Args { // If provided, use the specified configuration file instead of the default one. #[clap(long, value_parser = value_parser!(PathBuf))] - cfg_file_path: Option, + cfg_path: Option, } fn main() { let args = Args::parse(); - let cfg_file_path = args - .cfg_file_path + let cfg_path = args + .cfg_path .unwrap_or_else(|| PathBuf::from(CFG_FILE_NAME)); // Read and parse the configuration file. - let mut file = match File::open(cfg_file_path.clone()) { + let mut file = match File::open(cfg_path.clone()) { Ok(file) => file, Err(err) => { match err.kind() { std::io::ErrorKind::NotFound => { - eprintln!("canbench yml not found at {:?}", cfg_file_path) + eprintln!("canbench yml not found at {:?}", cfg_path) } - other => println!("Error while opening `{:?}`: {}", cfg_file_path, other), + other => println!("Error while opening `{:?}`: {}", cfg_path, other), } std::process::exit(1); @@ -61,8 +61,6 @@ fn main() { .unwrap_or(&DEFAULT_RESULTS_FILE.to_string()), ); - let custom_drun_path = cfg.get("drun_path").map(PathBuf::from); - // Build the canister if a build command is specified. if let Some(build_cmd) = cfg.get("build_cmd") { assert!( @@ -83,6 +81,5 @@ fn main() { args.persist, &results_path, !args.less_verbose, - custom_drun_path, ); } diff --git a/canbench-bin/tests/utils.rs b/canbench-bin/tests/utils.rs index 772b464..500d60a 100644 --- a/canbench-bin/tests/utils.rs +++ b/canbench-bin/tests/utils.rs @@ -108,7 +108,7 @@ impl BenchTest { // If a custom file name is provided, supply the path to the config file as an argument. if let Some(custom_cfg_file_name) = self.custom_cfg_file_name { - cmd_args.push("--cfg-file-path".to_string()); + cmd_args.push("--cfg-path".to_string()); cmd_args.push( dir_path .join(custom_cfg_file_name)