Skip to content

Commit

Permalink
Revert drun path changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonz-dfinity committed Mar 19, 2024
1 parent 885e928 commit a942704
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
25 changes: 9 additions & 16 deletions canbench-bin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,8 @@ pub fn run_benchmarks(
persist: bool,
results_file: &PathBuf,
verbose: bool,
custom_drun_path: Option<PathBuf>,
) {
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,
Expand All @@ -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);
Expand Down Expand Up @@ -98,7 +91,7 @@ fn canbench_dir() -> PathBuf {
}

// Path to drun.
fn download_drun_path() -> PathBuf {
fn drun_path() -> PathBuf {
canbench_dir().join("drun")
}

Expand All @@ -107,15 +100,15 @@ 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,
"macos" => DRUN_MAC_SHA,
_ => 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.
Expand Down Expand Up @@ -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();
Expand All @@ -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",
Expand Down
15 changes: 6 additions & 9 deletions canbench-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,
cfg_path: Option<PathBuf>,
}

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);
Expand All @@ -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!(
Expand All @@ -83,6 +81,5 @@ fn main() {
args.persist,
&results_path,
!args.less_verbose,
custom_drun_path,
);
}
2 changes: 1 addition & 1 deletion canbench-bin/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a942704

Please sign in to comment.