diff --git a/src/benchmark/executor.rs b/src/benchmark/executor.rs index b32d80a..44eada9 100644 --- a/src/benchmark/executor.rs +++ b/src/benchmark/executor.rs @@ -9,7 +9,7 @@ use crate::util::units::Second; use super::timing_result::TimingResult; -use anyhow::{bail, Result}; +use anyhow::{bail, Context, Result}; use statistical::mean; pub trait Executor { @@ -79,10 +79,10 @@ impl<'a> Executor for ShellExecutor<'a> { .stdin(Stdio::null()) .stdout(stdout) .stderr(stderr); - let error_message = format!("Failed to run command '{}'", command.get_command_line()); let wallclock_timer = WallClockTimer::start(); - let result = execute_and_measure(command_builder, &error_message)?; + let result = execute_and_measure(command_builder) + .with_context(|| format!("Failed to run command '{}'", command.get_command_line()))?; let mut time_real = wallclock_timer.stop(); let mut time_user = result.user_time; diff --git a/src/timer/mod.rs b/src/timer/mod.rs index 473a0eb..1b42225 100644 --- a/src/timer/mod.rs +++ b/src/timer/mod.rs @@ -10,7 +10,7 @@ use crate::util::units::Second; use std::process::{Command, ExitStatus}; -use anyhow::{Context, Result}; +use anyhow::Result; #[derive(Debug, Copy, Clone)] struct CPUTimes { @@ -36,11 +36,9 @@ pub struct ExecuteResult { /// Execute the given command and return a timing summary #[cfg(not(windows))] -pub fn execute_and_measure(mut command: Command, error_message: &str) -> Result { +pub fn execute_and_measure(mut command: Command) -> Result { let cpu_timer = self::unix_timer::CPUTimer::start(); - let status = command - .status() - .with_context(|| error_message.to_string())?; + let status = command.status()?; let (user_time, system_time) = cpu_timer.stop(); Ok(ExecuteResult { @@ -52,8 +50,8 @@ pub fn execute_and_measure(mut command: Command, error_message: &str) -> Result< /// Execute the given command and return a timing summary #[cfg(windows)] -pub fn execute_and_measure(mut command: Command, error_message: &str) -> Result { - let mut child = command.spawn().with_context(|| error_message.to_string())?; +pub fn execute_and_measure(mut command: Command) -> Result { + let mut child = command.spawn()?; let cpu_timer = self::windows_timer::CPUTimer::start_for_process(&child); let status = child.wait()?;