Add --env for benchmark environment overrides

This commit is contained in:
David Peter authored and David Peter committed 2026-10-07 22:32:37 +02:00
1 parent 067ee70f20
commit 6dddb02d73
12 files changed
+292 -15

No files matched your search

+8 -6
View File
@@ -18,15 +18,13 @@ pub struct BenchmarkResult {
/// regardless of any custom name.
pub command: String,
/// The custom name after parameter substitution, if it differs from `command`.
/// For example, `--command-name="wait {duration}s"` with `duration=1`
/// produces `Some("wait 1s")`. Without a custom name, or when the expanded
/// name equals `command`, this is `None`.
/// The custom or automatically generated name after parameter substitution,
/// if it differs from `command`. Automatic names include environment overrides.
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
/// The custom name (or `command`), followed by parameters not used in the
/// command template, in command-line order. For example, `sleep {duration}`
/// The name, followed by parameters not used in the command or environment
/// templates, in command-line order. For example, `sleep {duration}`
/// with `duration=1`, `branch=main`, and the custom name `wait {duration}s`
/// produces `wait 1s (branch = main)`. Without the custom name, this is
/// `sleep 1 (branch = main)`. Used in summaries and table exports.
@@ -40,6 +38,10 @@ pub struct BenchmarkResult {
/// Parameter values for this benchmark
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
pub parameters: BTreeMap<String, Parameter>,
/// Explicit environment overrides after parameter substitution.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
pub environment: BTreeMap<String, String>,
}
impl BenchmarkResult {
+1
View File
@@ -215,6 +215,7 @@ impl Executor for ShellExecutor<'_> {
) -> Result<Measurement> {
let on_windows_cmd = cfg!(windows) && *self.shell == Shell::Default("cmd.exe");
let mut command_builder = self.shell.command();
command_builder.envs(command.get_environment());
command_builder.arg(if on_windows_cmd { "/C" } else { "-c" });
// Windows needs special treatment for its behavior on parsing cmd arguments
+7 -1
View File
@@ -61,8 +61,9 @@ impl<'a> Benchmark<'a> {
output_policy: &CommandOutputPolicy,
iteration: executor::BenchmarkIteration,
) -> Result<Measurement> {
let command = command.clone().with_environment_from(self.command);
self.executor
.run_intermediate_command_and_measure(command, iteration, output_policy)
.run_intermediate_command_and_measure(&command, iteration, output_policy)
.map_err(|error| {
let hint = if cfg!(windows) {
"Append ' || exit /b 0' to the command if this failure can be ignored."
@@ -443,6 +444,11 @@ impl<'a> Benchmark<'a> {
Ok(BenchmarkResult {
command,
name,
environment: self
.command
.get_environment()
.map(|(name, value)| (name.to_owned(), value))
.collect(),
display_name: self.command.get_name_with_unused_parameters(),
measurements,
parameters: self