Skip to content
Myr

Move wall clock timer into 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 e001530 · Browse files · 2 files+30 added−30 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+30 added−30 removed

  • other:+30 added−30 removed

2 files+30 added−30 removed

modified:src/benchmark/executor.rs+5 added-5 removed
1 unmodified line
23use crate::command::Command;4use crate::options::{CmdFailureAction, Options, OutputStyleOption, Shell};5use crate::output::progress_bar::get_progress_bar;6use crate::timer::{execute_and_measure, wall_clock_timer::WallClockTimer};6use crate::timer::execute_and_measure;7use crate::util::randomized_environment_offset;8use crate::util::units::Second;910use super::timing_result::TimingResult;
65 unmodified lines
76 )77 .arg(if cfg!(windows) { "/C" } else { "-c" })78 .arg(command.get_command_line());7980 let wallclock_timer = WallClockTimer::start();80 let result = execute_and_measure(command_builder)81 .with_context(|| format!("Failed to run command '{}'", command.get_command_line()))?;83 let mut time_real = wallclock_timer.stop();8285 let mut time_user = result.user_time;86 let mut time_system = result.system_time;83 let mut time_real = result.time_real;8485 let mut time_user = result.time_user;86 let mut time_system = result.time_system;8788 if command_failure_action.unwrap_or(self.options.command_failure_action)89 == CmdFailureAction::RaiseError90 && !result.status.success()91 {
155 unmodified lines
modified:src/timer/mod.rs+25 added-25 removed
1pub mod wall_clock_timer;1mod wall_clock_timer;23#[cfg(windows)]4mod windows_timer;56#[cfg(not(windows))]7mod unix_timer;89use crate::util::units::Second;10use wall_clock_timer::WallClockTimer;1112use std::process::{Command, ExitStatus};1314use anyhow::Result;
9 unmodified lines
2425/// Used to indicate the result of running a command26#[derive(Debug, Copy, Clone)]27pub struct ExecuteResult {27 /// The amount of user time the process used28 pub user_time: Second,28 pub time_real: Second,29 pub time_user: Second,30 pub time_system: Second,3130 /// The amount of cpu time the process used31 pub system_time: Second,3232 /// The exit status of the process33 pub status: ExitStatus,34}3536/// Execute the given command and return a timing summary38#[cfg(not(windows))]37pub fn execute_and_measure(mut command: Command) -> Result<ExecuteResult> {40 let cpu_timer = self::unix_timer::CPUTimer::start();41 let status = command.status()?;42 let (user_time, system_time) = cpu_timer.stop();38 let wallclock_timer = WallClockTimer::start();3944 Ok(ExecuteResult {45 user_time,46 system_time,47 status,48 })49}40 #[cfg(not(windows))]41 let ((time_user, time_system), status) = {42 let cpu_timer = self::unix_timer::CPUTimer::start();43 let status = command.status()?;44 (cpu_timer.stop(), status)45 };4651/// Execute the given command and return a timing summary52#[cfg(windows)]53pub 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()?;47 #[cfg(windows)]48 let ((time_user, time_system), status) = {49 let mut child = command.spawn()?;50 let cpu_timer = self::windows_timer::CPUTimer::start_for_process(&child);51 let status = child.wait()?;5258 let (user_time, system_time) = cpu_timer.stop();53 (cpu_timer.stop(), status)54 };5556 let time_real = wallclock_timer.stop();5758 Ok(ExecuteResult {60 user_time,61 system_time,59 time_real,60 time_user,61 time_system,62 status,63 })64}