mirror of
https://github.com/sharkdp/hyperfine.git
synced 2024-11-05 05:25:30 +03:00
Move wall clock timer into execute_and_measure
This commit is contained in:
parent
e001530f61
commit
55f0ef6637
@ -3,7 +3,7 @@ use std::process::{ExitStatus, Stdio};
|
|||||||
use crate::command::Command;
|
use crate::command::Command;
|
||||||
use crate::options::{CmdFailureAction, Options, OutputStyleOption, Shell};
|
use crate::options::{CmdFailureAction, Options, OutputStyleOption, Shell};
|
||||||
use crate::output::progress_bar::get_progress_bar;
|
use crate::output::progress_bar::get_progress_bar;
|
||||||
use crate::timer::{execute_and_measure, wall_clock_timer::WallClockTimer};
|
use crate::timer::execute_and_measure;
|
||||||
use crate::util::randomized_environment_offset;
|
use crate::util::randomized_environment_offset;
|
||||||
use crate::util::units::Second;
|
use crate::util::units::Second;
|
||||||
|
|
||||||
@ -77,13 +77,13 @@ impl<'a> Executor for ShellExecutor<'a> {
|
|||||||
.arg(if cfg!(windows) { "/C" } else { "-c" })
|
.arg(if cfg!(windows) { "/C" } else { "-c" })
|
||||||
.arg(command.get_command_line());
|
.arg(command.get_command_line());
|
||||||
|
|
||||||
let wallclock_timer = WallClockTimer::start();
|
|
||||||
let result = execute_and_measure(command_builder)
|
let result = execute_and_measure(command_builder)
|
||||||
.with_context(|| format!("Failed to run command '{}'", command.get_command_line()))?;
|
.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;
|
let mut time_real = result.time_real;
|
||||||
let mut time_system = result.system_time;
|
|
||||||
|
let mut time_user = result.time_user;
|
||||||
|
let mut time_system = result.time_system;
|
||||||
|
|
||||||
if command_failure_action.unwrap_or(self.options.command_failure_action)
|
if command_failure_action.unwrap_or(self.options.command_failure_action)
|
||||||
== CmdFailureAction::RaiseError
|
== CmdFailureAction::RaiseError
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
pub mod wall_clock_timer;
|
mod wall_clock_timer;
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
mod windows_timer;
|
mod windows_timer;
|
||||||
@ -7,6 +7,7 @@ mod windows_timer;
|
|||||||
mod unix_timer;
|
mod unix_timer;
|
||||||
|
|
||||||
use crate::util::units::Second;
|
use crate::util::units::Second;
|
||||||
|
use wall_clock_timer::WallClockTimer;
|
||||||
|
|
||||||
use std::process::{Command, ExitStatus};
|
use std::process::{Command, ExitStatus};
|
||||||
|
|
||||||
@ -24,41 +25,40 @@ struct CPUTimes {
|
|||||||
/// Used to indicate the result of running a command
|
/// Used to indicate the result of running a command
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub struct ExecuteResult {
|
pub struct ExecuteResult {
|
||||||
/// The amount of user time the process used
|
pub time_real: Second,
|
||||||
pub user_time: Second,
|
pub time_user: Second,
|
||||||
|
pub time_system: Second,
|
||||||
/// The amount of cpu time the process used
|
|
||||||
pub system_time: Second,
|
|
||||||
|
|
||||||
/// The exit status of the process
|
/// The exit status of the process
|
||||||
pub status: ExitStatus,
|
pub status: ExitStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Execute the given command and return a timing summary
|
/// Execute the given command and return a timing summary
|
||||||
#[cfg(not(windows))]
|
|
||||||
pub fn execute_and_measure(mut command: Command) -> Result<ExecuteResult> {
|
pub fn execute_and_measure(mut command: Command) -> Result<ExecuteResult> {
|
||||||
let cpu_timer = self::unix_timer::CPUTimer::start();
|
let wallclock_timer = WallClockTimer::start();
|
||||||
let status = command.status()?;
|
|
||||||
let (user_time, system_time) = cpu_timer.stop();
|
#[cfg(not(windows))]
|
||||||
|
let ((time_user, time_system), status) = {
|
||||||
|
let cpu_timer = self::unix_timer::CPUTimer::start();
|
||||||
|
let status = command.status()?;
|
||||||
|
(cpu_timer.stop(), status)
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
let ((time_user, time_system), status) = {
|
||||||
|
let mut child = command.spawn()?;
|
||||||
|
let cpu_timer = self::windows_timer::CPUTimer::start_for_process(&child);
|
||||||
|
let status = child.wait()?;
|
||||||
|
|
||||||
|
(cpu_timer.stop(), status)
|
||||||
|
};
|
||||||
|
|
||||||
|
let time_real = wallclock_timer.stop();
|
||||||
|
|
||||||
Ok(ExecuteResult {
|
Ok(ExecuteResult {
|
||||||
user_time,
|
time_real,
|
||||||
system_time,
|
time_user,
|
||||||
status,
|
time_system,
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Execute the given command and return a timing summary
|
|
||||||
#[cfg(windows)]
|
|
||||||
pub fn execute_and_measure(mut command: Command) -> Result<ExecuteResult> {
|
|
||||||
let mut child = command.spawn()?;
|
|
||||||
let cpu_timer = self::windows_timer::CPUTimer::start_for_process(&child);
|
|
||||||
let status = child.wait()?;
|
|
||||||
|
|
||||||
let (user_time, system_time) = cpu_timer.stop();
|
|
||||||
Ok(ExecuteResult {
|
|
||||||
user_time,
|
|
||||||
system_time,
|
|
||||||
status,
|
status,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user