summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-01-16 10:02:03 +0000
committerLars Wirzenius <liw@liw.fi>2022-01-16 10:02:03 +0000
commit93584ec7e8b774c19d6b9c2ebc64a4513a961d96 (patch)
tree7ff13c1cd7e04b47a6aa20c22953605bcb05d34e
parent1ad4e5d867cf9b040de48371cce55bdb3ad001ea (diff)
parent8c799a2161d57f1b0f965ade59a8b7e690660cbe (diff)
downloadobnam-benchmark-93584ec7e8b774c19d6b9c2ebc64a4513a961d96.tar.gz
Merge branch 'fix-version-column' into 'main'
feat: allow report to write to named file See merge request obnam/obnam-benchmark!13
-rw-r--r--src/bin/obnam-benchmark.rs18
-rw-r--r--src/builder.rs11
-rw-r--r--src/report.rs22
-rw-r--r--src/result.rs16
4 files changed, 51 insertions, 16 deletions
diff --git a/src/bin/obnam-benchmark.rs b/src/bin/obnam-benchmark.rs
index 8b75229..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)?);
}
@@ -182,6 +183,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<PathBuf>,
+
/// Names of the results file for which to produce a report.
#[structopt(parse(from_os_str))]
filenames: Vec<PathBuf>,
@@ -190,11 +195,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(())
}
}
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<String, ObnamBuilderError> {
- 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<String> {
+ 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<SuiteMeasurements>,
@@ -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 cce5d2d..f72c2f4 100644
--- a/src/result.rs
+++ b/src/result.rs
@@ -12,6 +12,7 @@ git_testament!(TESTAMENT);
pub struct SuiteMeasurements {
measurements: Vec<OpMeasurements>,
obnam_version: String,
+ obnam_commit: Option<String>,
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<Self, SuiteMeasurementsError> {
+ pub fn new(
+ obnam_version: String,
+ obnam_commit: Option<String>,
+ ) -> Result<Self, SuiteMeasurementsError> {
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(),
@@ -109,10 +114,11 @@ impl SuiteMeasurements {
}
pub fn obnam_version(&self) -> &str {
- self.obnam_version
- .strip_prefix("obnam-backup ")
- .or(Some(""))
- .unwrap()
+ &self.obnam_version
+ }
+
+ pub fn obnam_commit(&self) -> Option<&str> {
+ self.obnam_commit.as_deref()
}
pub fn push(&mut self, m: OpMeasurements) {