diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/obnam-benchmark.rs | 5 | ||||
-rw-r--r-- | src/client.rs | 16 | ||||
-rw-r--r-- | src/result.rs | 46 |
3 files changed, 62 insertions, 5 deletions
diff --git a/src/bin/obnam-benchmark.rs b/src/bin/obnam-benchmark.rs index f079d75..5df2aeb 100644 --- a/src/bin/obnam-benchmark.rs +++ b/src/bin/obnam-benchmark.rs @@ -1,6 +1,6 @@ use log::{debug, error, info}; use obnam_benchmark::junk::junk; -use obnam_benchmark::result::Result; +use obnam_benchmark::result::SuiteMeasurements; use obnam_benchmark::specification::Specification; use obnam_benchmark::suite::Suite; use std::fs::File; @@ -71,7 +71,8 @@ impl Run { info!("running benchmarks from {}", self.spec.display()); let spec = Specification::from_file(&self.spec)?; let mut suite = Suite::new()?; - let mut result = Result::default(); + let obnam_version = obnam_benchmark::client::ObnamClient::version()?; + let mut result = SuiteMeasurements::new(obnam_version)?; for step in spec.steps().iter() { result.push(suite.execute(step)?); } diff --git a/src/client.rs b/src/client.rs index fb25009..97b4c61 100644 --- a/src/client.rs +++ b/src/client.rs @@ -39,6 +39,22 @@ impl ObnamClient { }) } + pub fn version() -> Result<String, ObnamClientError> { + let output = Command::new("obnam") + .arg("--version") + .output() + .map_err(ObnamClientError::Run)?; + if output.status.code() != Some(0) { + eprintln!("{}", String::from_utf8_lossy(&output.stdout)); + eprintln!("{}", String::from_utf8_lossy(&output.stderr)); + std::process::exit(1); + } + + let v = String::from_utf8_lossy(&output.stdout); + let v = v.strip_suffix('\n').or(Some(&v)).unwrap().to_string(); + Ok(v) + } + pub fn run(&self, args: &[&str]) -> Result<String, ObnamClientError> { let output = Command::new("obnam") .arg("--config") diff --git a/src/result.rs b/src/result.rs index 9e4119b..4a0277e 100644 --- a/src/result.rs +++ b/src/result.rs @@ -1,8 +1,18 @@ +use chrono::prelude::*; +use git_testament::{git_testament, render_testament}; use serde::Serialize; -#[derive(Debug, Default, Serialize)] -pub struct Result { +git_testament!(TESTAMENT); + +#[derive(Debug, Serialize)] +pub struct SuiteMeasurements { measurements: Vec<OpMeasurements>, + obnam_version: String, + obnam_benchmark_version: String, + benchmark_started: String, + hostname: String, + host_cpus: usize, + host_ram: u64, } #[derive(Debug, Serialize)] @@ -33,7 +43,37 @@ pub enum Operation { CompareManiests, } -impl Result { +#[derive(Debug, thiserror::Error)] +pub enum SuiteMeasurementsError { + #[error("failed to get CPU info: {0}")] + CpuInfo(procfs::ProcError), + + #[error("failed to get RAM info: {0}")] + MemInfo(procfs::ProcError), + + #[error("failed to get hostname: {0}")] + Hostname(nix::Error), +} + +impl SuiteMeasurements { + pub fn new(obnam_version: 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]; + let hostname = + nix::unistd::gethostname(&mut buf).map_err(SuiteMeasurementsError::Hostname)?; + let hostname = hostname.to_string_lossy(); + Ok(Self { + measurements: vec![], + obnam_version, + obnam_benchmark_version: render_testament!(TESTAMENT), + benchmark_started: Utc::now().to_string(), + hostname: hostname.to_string(), + host_ram: mem.mem_total, + host_cpus: cpu.num_cores(), + }) + } + pub fn push(&mut self, m: OpMeasurements) { self.measurements.push(m); } |