summaryrefslogtreecommitdiff
path: root/src/bin/obnam-benchmark.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/obnam-benchmark.rs')
-rw-r--r--src/bin/obnam-benchmark.rs23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/bin/obnam-benchmark.rs b/src/bin/obnam-benchmark.rs
index 5df2aeb..41118cb 100644
--- a/src/bin/obnam-benchmark.rs
+++ b/src/bin/obnam-benchmark.rs
@@ -4,6 +4,7 @@ use obnam_benchmark::result::SuiteMeasurements;
use obnam_benchmark::specification::Specification;
use obnam_benchmark::suite::Suite;
use std::fs::File;
+use std::io::Write;
use std::path::PathBuf;
use std::process::exit;
use structopt::StructOpt;
@@ -61,9 +62,14 @@ struct Run {
#[structopt(parse(from_os_str))]
spec: PathBuf,
- /// Name of file where the results will be written.
+ /// Name of file where the results will be written. Default is
+ /// stdout.
#[structopt(long, parse(from_os_str))]
- output: PathBuf,
+ output: Option<PathBuf>,
+
+ /// Construct output filename from benchmark run metadata.
+ #[structopt(short, long)]
+ auto: bool,
}
impl Run {
@@ -76,9 +82,16 @@ impl Run {
for step in spec.steps().iter() {
result.push(suite.execute(step)?);
}
- debug!("writing results to {}", self.output.display());
- let output = File::create(&self.output)?;
- serde_json::to_writer_pretty(&output, &result)?;
+
+ let output = serde_json::to_string_pretty(&result)?;
+ if let Some(filename) = &self.output {
+ std::fs::write(filename, output)?
+ } else if self.auto {
+ let filename = format!("{}_{}.json", result.hostname(), result.timestamp());
+ std::fs::write(filename, output)?
+ } else {
+ std::io::stdout().write_all(output.as_bytes())?;
+ };
Ok(())
}
}