diff --git a/src/benchmark/benchmark_result.rs b/src/benchmark/benchmark_result.rs index 69de16c..27d41a4 100644 --- a/src/benchmark/benchmark_result.rs +++ b/src/benchmark/benchmark_result.rs @@ -2,6 +2,15 @@ use std::collections::BTreeMap; use serde::Serialize; +/// Parameter value and whether it was used in the command line template +#[derive(Debug, Default, Clone, Serialize, PartialEq)] +#[serde(transparent)] +pub struct Parameter { + pub value: String, + #[serde(skip)] + pub is_unused: bool, +} + /// Set of values that will be exported. // NOTE: `serde` is used for JSON serialization, but not for CSV serialization due to the // `parameters` map. Update `src/hyperfine/export/csv.rs` with new fields, as appropriate. @@ -49,5 +58,5 @@ pub struct BenchmarkResult { /// Parameter values for this benchmark #[serde(skip_serializing_if = "BTreeMap::is_empty")] - pub parameters: BTreeMap, + pub parameters: BTreeMap, } diff --git a/src/benchmark/mod.rs b/src/benchmark/mod.rs index a45f9a0..ecf1302 100644 --- a/src/benchmark/mod.rs +++ b/src/benchmark/mod.rs @@ -19,7 +19,7 @@ use crate::output::warnings::{OutlierWarningOptions, Warnings}; use crate::parameter::ParameterNameAndValue; use crate::quantity::{byte, const_time_from_seconds, ratio, second, FormatQuantity, Time, Zero}; use crate::util::exit_code::extract_exit_code; -use benchmark_result::BenchmarkResult; +use benchmark_result::{BenchmarkResult, Parameter}; use measurement::{Measurement, Measurements}; use anyhow::{anyhow, Result}; @@ -474,7 +474,15 @@ impl<'a> Benchmark<'a> { .command .get_parameters() .iter() - .map(|(name, value)| (name.to_string(), value.to_string())) + .map(|(name, value)| { + ( + name.to_string(), + Parameter { + value: value.to_string(), + is_unused: self.command.is_parameter_unused(name), + }, + ) + }) .collect(), }) } diff --git a/src/export/csv.rs b/src/export/csv.rs index f471178..331b52e 100644 --- a/src/export/csv.rs +++ b/src/export/csv.rs @@ -53,7 +53,7 @@ impl Exporter for CsvExporter { fields.push(Cow::Owned(format!("{f:.CSV_PRECISION$}").into_bytes())) } for v in res.parameters.values() { - fields.push(Cow::Borrowed(v.as_bytes())) + fields.push(Cow::Borrowed(v.value.as_bytes())) } writer.write_record(fields)?; } @@ -64,6 +64,7 @@ impl Exporter for CsvExporter { #[test] fn test_csv() { + use crate::benchmark::benchmark_result::Parameter; use std::collections::BTreeMap; let exporter = CsvExporter::default(); @@ -83,8 +84,20 @@ fn test_csv() { exit_codes: vec![Some(0), Some(0), Some(0)], parameters: { let mut params = BTreeMap::new(); - params.insert("foo".into(), "one".into()); - params.insert("bar".into(), "two".into()); + params.insert( + "foo".into(), + Parameter { + value: "one".into(), + is_unused: false, + }, + ); + params.insert( + "bar".into(), + Parameter { + value: "two".into(), + is_unused: false, + }, + ); params }, }, @@ -103,8 +116,20 @@ fn test_csv() { exit_codes: vec![Some(0), Some(0), Some(0)], parameters: { let mut params = BTreeMap::new(); - params.insert("foo".into(), "one".into()); - params.insert("bar".into(), "seven".into()); + params.insert( + "foo".into(), + Parameter { + value: "one".into(), + is_unused: false, + }, + ); + params.insert( + "bar".into(), + Parameter { + value: "seven".into(), + is_unused: false, + }, + ); params }, },