diff options
| author | Kamen Mladenov <kamen@syndamia.com> | 2025-04-29 17:13:41 +0300 |
|---|---|---|
| committer | Kamen Mladenov <kamen@syndamia.com> | 2025-05-02 15:32:54 +0300 |
| commit | 2f8b3b399a68abe59d4169dc74c105f151869062 (patch) | |
| tree | f484c052f3d6cf2e4352f986323f02c80c3bd4ed | |
| parent | 43b6a714dd8a674d1ac969015d45b4c43177f146 (diff) | |
| download | zkVMs-benchmarks-2f8b3b399a68abe59d4169dc74c105f151869062.tar zkVMs-benchmarks-2f8b3b399a68abe59d4169dc74c105f151869062.tar.gz zkVMs-benchmarks-2f8b3b399a68abe59d4169dc74c105f151869062.zip | |
feat(zkvms_guest_io): Allow output to be emmited into a file
| -rw-r--r-- | zkvms_guest_io/src/main.rs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/zkvms_guest_io/src/main.rs b/zkvms_guest_io/src/main.rs index 4510d34..04d33d1 100644 --- a/zkvms_guest_io/src/main.rs +++ b/zkvms_guest_io/src/main.rs @@ -1,6 +1,8 @@ use clap::Parser; use std::process::{Command, Stdio}; use json::{object, parse, JsonValue, Null}; +use std::io::{Error, Write}; +use std::fs::{read_to_string, OpenOptions}; /// A CLI tool for running and benchmarking a guest program inside all /// supported zkVMs. @@ -17,6 +19,14 @@ struct Cli { /// Make one failiure stop the entire process #[arg(short, long)] fail_propagation: bool, + + /// Put the resultant output into a file of the given path + #[arg(short = 'o', long)] + metrics_output: Option<String>, + + /// Append the resultant output to the given file, instead of replacing it + #[arg(short, long)] + append: bool, } fn run_command(zkvm_guest_command: &str, operation: &str) -> Result<std::process::Output, Error> { @@ -97,5 +107,24 @@ fn main() { runs["benchmarking"].push(run); } - println!("{}", runs.dump()); + if let Some(path) = cli.metrics_output { + let mut outfile = match OpenOptions::new() + .write(true) + .create(true) + .append(cli.append) + .truncate(!cli.append) + .open(&path) + { + Ok(file) => file, + Err(e) => { + panic!("Failed to open file: {}", e); + } + }; + + if let Err(e) = writeln!(outfile, "{}", runs.dump()) { + panic!("Failed to write output: {}", e); + } + } else { + println!("{}", runs.dump()); + } } |
