Skip to content
Myr

Move custom functionality to executor

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 f822455 · Browse files · 2 files+21 added−44 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+21 added−44 removed

  • other:+21 added−44 removed

2 files+21 added−44 removed

modified:src/benchmark/executor.rs+15 added-1 removed
3 unmodified lines
4use crate::execute::execute_and_measure;5use crate::options::{CmdFailureAction, CommandOutputPolicy, Options, OutputStyleOption, Shell};6use crate::output::progress_bar::get_progress_bar;7use crate::timer::wallclocktimer::WallClockTimer;8use crate::util::randomized_environment_offset;9use crate::util::units::Second;1011use super::timing_result::TimingResult;12
55 unmodified lines
68 CommandOutputPolicy::Discard => (Stdio::null(), Stdio::null()),69 CommandOutputPolicy::Forward => (Stdio::inherit(), Stdio::inherit()),70 };7172 let mut command_builder = self.shell.command();73 command_builder74 .arg(if cfg!(windows) { "/C" } else { "-c" })75 .arg(command.get_command_line())76 .env(77 "HYPERFINE_RANDOMIZED_ENVIRONMENT_OFFSET",78 randomized_environment_offset::value(),79 )80 .stdin(Stdio::null())81 .stdout(stdout)82 .stderr(stderr);83 let error_message = format!("Failed to run command '{}'", command.get_command_line());8485 let wallclock_timer = WallClockTimer::start();72 let result = execute_and_measure(stdout, stderr, &command.get_command_line(), self.shell)?;86 let result = execute_and_measure(command_builder, &error_message)?;87 let mut time_real = wallclock_timer.stop();8889 let mut time_user = result.user_time;90 let mut time_system = result.system_time;
160 unmodified lines
modified:src/execute.rs+6 added-43 removed
1use std::process::{ExitStatus, Stdio};1use std::process::{Command, ExitStatus};23use crate::options::Shell;4use crate::util::randomized_environment_offset;53use anyhow::{Context, Result};45/// Used to indicate the result of running a command6#[derive(Debug, Copy, Clone)]
9 unmodified lines
16}1718/// Execute the given command and return a timing summary19#[cfg(not(windows))]23pub fn execute_and_measure(24 stdout: Stdio,25 stderr: Stdio,26 command: &str,27 shell: &Shell,28) -> Result<ExecuteResult> {20pub fn execute_and_measure(mut command: Command, error_message: &str) -> Result<ExecuteResult> {21 let cpu_timer = crate::timer::unix_timer::CPUTimer::start();3031 let status = shell22 let status = command32 .command()33 .arg("-c")34 .arg(command)35 .env(36 "HYPERFINE_RANDOMIZED_ENVIRONMENT_OFFSET",37 randomized_environment_offset::value(),38 )39 .stdin(Stdio::null())40 .stdout(stdout)41 .stderr(stderr)23 .status()43 .with_context(|| format!("Failed to run command '{}'", command))?;4424 .with_context(|| error_message.to_string())?;25 let (user_time, system_time) = cpu_timer.stop();2627 Ok(ExecuteResult {28 user_time,
3 unmodified lines
32}3334/// Execute the given command and return a timing summary35#[cfg(windows)]56pub fn execute_and_measure(57 stdout: Stdio,58 stderr: Stdio,59 command: &str,60 shell: &Shell,61) -> Result<ExecuteResult> {62 let mut child = shell63 .command()64 .arg("/C")65 .arg(command)66 .env(67 "HYPERFINE_RANDOMIZED_ENVIRONMENT_OFFSET",68 randomized_environment_offset::value(),69 )70 .stdin(Stdio::null())71 .stdout(stdout)72 .stderr(stderr)73 .spawn()74 .with_context(|| format!("Failed to run command '{}'", command))?;36pub fn execute_and_measure(mut command: Command, error_message: &str) -> Result<ExecuteResult> {37 let mut child = command.spawn().with_context(|| error_message.to_string())?;38 let cpu_timer = crate::timer::windows_timer::CPUTimer::start_for_process(&child);39 let status = child.wait()?;4041 let (user_time, system_time) = cpu_timer.stop();
6 unmodified lines