summaryrefslogtreecommitdiff
path: root/src/result.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/result.rs')
-rw-r--r--src/result.rs46
1 files changed, 43 insertions, 3 deletions
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);
}