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
Provenance
- Commit
55f0ef6- Tree
e441943- Author
David Peter <mail@david-peter.de>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
e001530
2 files changed+30 added−30 removed
modified:src/benchmark/executor.rs+5 added-5 removed
1 unmodified line2 3 use crate::command::Command;4 use crate::options::{CmdFailureAction, Options, OutputStyleOption, Shell};5 use crate::output::progress_bar::get_progress_bar;6-use crate::timer::{execute_and_measure, wall_clock_timer::WallClockTimer};6+use crate::timer::execute_and_measure;7 use crate::util::randomized_environment_offset;8 use crate::util::units::Second;9 10 use super::timing_result::TimingResult;65 unmodified lines76 )77 .arg(if cfg!(windows) { "/C" } else { "-c" })78 .arg(command.get_command_line());79 80- 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();82 85- let mut time_user = result.user_time;86- let mut time_system = result.system_time;83+ let mut time_real = result.time_real;84 85+ let mut time_user = result.time_user;86+ let mut time_system = result.time_system;87+88 if command_failure_action.unwrap_or(self.options.command_failure_action)89 == CmdFailureAction::RaiseError90 && !result.status.success()91 {155 unmodified linesmodified:src/timer/mod.rs+25 added-25 removed
1-pub mod wall_clock_timer;1+mod wall_clock_timer;2 3 #[cfg(windows)]4 mod windows_timer;5 6 #[cfg(not(windows))]7 mod unix_timer;8 9 use crate::util::units::Second;10+use wall_clock_timer::WallClockTimer;11 12 use std::process::{Command, ExitStatus};13 14 use anyhow::Result;9 unmodified lines24 25 /// Used to indicate the result of running a command26 #[derive(Debug, Copy, Clone)]27 pub 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,31 30- /// The amount of cpu time the process used31- pub system_time: Second,32-32 /// The exit status of the process33 pub status: ExitStatus,34 }35 36 /// Execute the given command and return a timing summary38-#[cfg(not(windows))]37 pub 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();39 44- 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+ };46 51-/// Execute the given command and return a timing summary52-#[cfg(windows)]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()?;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()?;52 58- let (user_time, system_time) = cpu_timer.stop();53+ (cpu_timer.stop(), status)54+ };55+56+ let time_real = wallclock_timer.stop();57+58 Ok(ExecuteResult {60- user_time,61- system_time,59+ time_real,60+ time_user,61+ time_system,62 status,63 })64 }