From 8f15eb79af7cba799a0f1286f277bd49353b5ca3 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 16 Jan 2022 11:21:34 +0200 Subject: feat: allow report to write to named file Sponsored-by: author --- src/bin/obnam-benchmark.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/bin/obnam-benchmark.rs b/src/bin/obnam-benchmark.rs index 8b75229..db04d0a 100644 --- a/src/bin/obnam-benchmark.rs +++ b/src/bin/obnam-benchmark.rs @@ -182,6 +182,10 @@ impl Steps { #[derive(Debug, StructOpt)] struct Report { + /// File where to write the report. Stdout by default. + #[structopt(short, long, parse(from_os_str))] + output: Option, + /// Names of the results file for which to produce a report. #[structopt(parse(from_os_str))] filenames: Vec, @@ -190,11 +194,16 @@ struct Report { impl Report { fn run(&self) -> anyhow::Result<()> { info!("Reporting results"); - let mut report = Reporter::default(); + let mut reporter = Reporter::default(); for filename in self.filenames.iter() { - report.push(SuiteMeasurements::from_file(filename)?); + reporter.push(SuiteMeasurements::from_file(filename)?); + } + if let Some(output) = &self.output { + let mut file = File::create(output)?; + reporter.write(&mut file)?; + } else { + reporter.write(&mut std::io::stdout())?; } - report.write(&mut std::io::stdout())?; Ok(()) } } -- cgit v1.2.1 From 5936dc5b6999ed4c70da9dac20b6f8f6717cdd15 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 16 Jan 2022 11:22:10 +0200 Subject: fix: return actual version from result file Sponsored-by: author --- src/result.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/result.rs b/src/result.rs index cce5d2d..a7558ec 100644 --- a/src/result.rs +++ b/src/result.rs @@ -109,10 +109,7 @@ impl SuiteMeasurements { } pub fn obnam_version(&self) -> &str { - self.obnam_version - .strip_prefix("obnam-backup ") - .or(Some("")) - .unwrap() + &self.obnam_version } pub fn push(&mut self, m: OpMeasurements) { -- cgit v1.2.1 From 8c799a2161d57f1b0f965ade59a8b7e690660cbe Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 16 Jan 2022 12:00:50 +0200 Subject: feat: record Obnam commit, if building from git; fix version report Sponsored-by: author --- src/bin/obnam-benchmark.rs | 3 ++- src/builder.rs | 11 +++++------ src/report.rs | 22 +++++++++++++++++++++- src/result.rs | 11 ++++++++++- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/bin/obnam-benchmark.rs b/src/bin/obnam-benchmark.rs index db04d0a..37972f5 100644 --- a/src/bin/obnam-benchmark.rs +++ b/src/bin/obnam-benchmark.rs @@ -90,8 +90,9 @@ impl Run { let spec = Specification::from_file(&self.spec)?; let builder = ObnamBuilder::new(&self.obnam)?; let obnam_version = builder.version()?; + let obnam_commit = builder.commit(); let mut suite = Suite::new(&builder)?; - let mut result = SuiteMeasurements::new(obnam_version)?; + let mut result = SuiteMeasurements::new(obnam_version, obnam_commit)?; for step in spec.steps().iter() { result.push(suite.execute(step)?); } diff --git a/src/builder.rs b/src/builder.rs index 2de2085..ac414c7 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -4,7 +4,6 @@ use std::str::FromStr; use tempfile::{tempdir, TempDir}; const OBNAM_URL: &str = "https://gitlab.com/obnam/obnam.git"; -const COMMIT_DIGITS: usize = 7; #[derive(Debug, Clone)] pub enum WhichObnam { @@ -73,7 +72,7 @@ impl ObnamBuilder { tempdir, client, server, - commit: Some(commit[..COMMIT_DIGITS].to_string()), + commit: Some(commit), } } }; @@ -81,10 +80,6 @@ impl ObnamBuilder { } pub fn version(&self) -> Result { - if let Some(commit) = &self.commit { - return Ok(commit.to_string()); - } - let binary = self.client_binary(); let output = Command::new(binary) .arg("--version") @@ -101,6 +96,10 @@ impl ObnamBuilder { Ok(v) } + pub fn commit(&self) -> Option { + self.commit.clone() + } + pub fn client_binary(&self) -> &Path { &self.client } diff --git a/src/report.rs b/src/report.rs index 0538760..297195d 100644 --- a/src/report.rs +++ b/src/report.rs @@ -3,6 +3,8 @@ use std::collections::HashSet; use std::io::Write; use std::iter::FromIterator; +const COMMIT_DIGITS: usize = 7; + #[derive(Debug, Default)] pub struct Reporter { results: Vec, @@ -109,6 +111,7 @@ impl Reporter { .enumerate() .map(|(i, _)| format!("step {}", i)) .collect(); + headings.insert(0, "Commit".to_string()); headings.insert(0, "Version".to_string()); for h in headings.iter() { write!(f, "| {}", h)?; @@ -129,7 +132,8 @@ impl Reporter { r: &SuiteMeasurements, durations: &[u128], ) -> Result<(), std::io::Error> { - write!(f, "| {}", r.obnam_version())?; + write!(f, "| {}", pretty_version(r.obnam_version()))?; + write!(f, "| {}", pretty_commit(r.obnam_commit()))?; for ms in durations.iter() { write!(f, "| {}", ms)?; } @@ -162,3 +166,19 @@ impl Reporter { .filter(move |r| r.hostname() == hostname) } } + +fn pretty_version(v: &str) -> String { + if let Some(v) = v.strip_prefix("obnam-backup ") { + v.to_string() + } else { + v.to_string() + } +} + +fn pretty_commit(c: Option<&str>) -> String { + if let Some(c) = c { + c[..COMMIT_DIGITS].to_string() + } else { + "".to_string() + } +} diff --git a/src/result.rs b/src/result.rs index a7558ec..f72c2f4 100644 --- a/src/result.rs +++ b/src/result.rs @@ -12,6 +12,7 @@ git_testament!(TESTAMENT); pub struct SuiteMeasurements { measurements: Vec, obnam_version: String, + obnam_commit: Option, obnam_benchmark_version: String, benchmark_started: String, hostname: String, @@ -66,7 +67,10 @@ pub enum SuiteMeasurementsError { } impl SuiteMeasurements { - pub fn new(obnam_version: String) -> Result { + pub fn new( + obnam_version: String, + obnam_commit: Option, + ) -> Result { let cpu = procfs::CpuInfo::new().map_err(SuiteMeasurementsError::CpuInfo)?; let mem = procfs::Meminfo::new().map_err(SuiteMeasurementsError::MemInfo)?; let mut buf = [0u8; 1024]; @@ -76,6 +80,7 @@ impl SuiteMeasurements { Ok(Self { measurements: vec![], obnam_version, + obnam_commit, obnam_benchmark_version: render_testament!(TESTAMENT), benchmark_started: Utc::now().format("%Y-%m-%dT%H%M%S").to_string(), hostname: hostname.to_string(), @@ -112,6 +117,10 @@ impl SuiteMeasurements { &self.obnam_version } + pub fn obnam_commit(&self) -> Option<&str> { + self.obnam_commit.as_deref() + } + pub fn push(&mut self, m: OpMeasurements) { self.measurements.push(m); } -- cgit v1.2.1