Further simplify execute_and_measure
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Peter · committed by David Peter · parent 0ffc6d7 · Browse files · 2 files·+8 added−10 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+8 added−10 removed
- other:+8 added−10 removed
Provenance
- Commit
e1da8ba- Tree
8add247- Author
David Peter <mail@david-peter.de>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
0ffc6d7
2 files changed+8 added−10 removed
modified:src/benchmark/executor.rs+3 added-3 removed
7 unmodified lines8 use crate::util::units::Second;9 10 use super::timing_result::TimingResult;11 12-use anyhow::{bail, Result};12+use anyhow::{bail, Context, Result};13 use statistical::mean;14 15 pub trait Executor {16 /// Run the given command and measure the execution time61 unmodified lines78 )79 .stdin(Stdio::null())80 .stdout(stdout)81 .stderr(stderr);82- let error_message = format!("Failed to run command '{}'", command.get_command_line());82 83 let wallclock_timer = WallClockTimer::start();85- let result = execute_and_measure(command_builder, &error_message)?;84+ let result = execute_and_measure(command_builder)85+ .with_context(|| format!("Failed to run command '{}'", command.get_command_line()))?;86 let mut time_real = wallclock_timer.stop();87 88 let mut time_user = result.user_time;89 let mut time_system = result.system_time;160 unmodified linesmodified:src/timer/mod.rs+5 added-7 removed
8 unmodified lines9 use crate::util::units::Second;10 11 use std::process::{Command, ExitStatus};12 13-use anyhow::{Context, Result};13+use anyhow::Result;14 15 #[derive(Debug, Copy, Clone)]16 struct CPUTimes {17 /// Total amount of time spent executing in user mode17 unmodified lines35 }36 37 /// Execute the given command and return a timing summary38 #[cfg(not(windows))]39-pub fn execute_and_measure(mut command: Command, error_message: &str) -> Result<ExecuteResult> {39+pub fn execute_and_measure(mut command: Command) -> Result<ExecuteResult> {40 let cpu_timer = self::unix_timer::CPUTimer::start();41- let status = command42- .status()43- .with_context(|| error_message.to_string())?;41+ let status = command.status()?;42 let (user_time, system_time) = cpu_timer.stop();43 44 Ok(ExecuteResult {45 user_time,3 unmodified lines49 }50 51 /// Execute the given command and return a timing summary52 #[cfg(windows)]55-pub fn execute_and_measure(mut command: Command, error_message: &str) -> Result<ExecuteResult> {56- let mut child = command.spawn().with_context(|| error_message.to_string())?;53+pub fn execute_and_measure(mut command: Command) -> Result<ExecuteResult> {54+ let mut child = command.spawn()?;55 let cpu_timer = self::windows_timer::CPUTimer::start_for_process(&child);56 let status = child.wait()?;57 58 let (user_time, system_time) = cpu_timer.stop();6 unmodified lines