diff --git a/src/benchmark/executor.rs b/src/benchmark/executor.rs index 2780df0..b32d80a 100644 --- a/src/benchmark/executor.rs +++ b/src/benchmark/executor.rs @@ -1,10 +1,9 @@ use std::process::{ExitStatus, Stdio}; use crate::command::Command; -use crate::execute::execute_and_measure; use crate::options::{CmdFailureAction, CommandOutputPolicy, Options, OutputStyleOption, Shell}; use crate::output::progress_bar::get_progress_bar; -use crate::timer::wallclocktimer::WallClockTimer; +use crate::timer::{execute_and_measure, wall_clock_timer::WallClockTimer}; use crate::util::randomized_environment_offset; use crate::util::units::Second; diff --git a/src/execute.rs b/src/execute.rs deleted file mode 100644 index 7d8487e..0000000 --- a/src/execute.rs +++ /dev/null @@ -1,47 +0,0 @@ -use std::process::{Command, ExitStatus}; - -use anyhow::{Context, Result}; - -/// Used to indicate the result of running a command -#[derive(Debug, Copy, Clone)] -pub struct ExecuteResult { - /// The amount of user time the process used - pub user_time: f64, - - /// The amount of cpu time the process used - pub system_time: f64, - - /// The exit status of the process - pub status: ExitStatus, -} - -/// Execute the given command and return a timing summary -#[cfg(not(windows))] -pub fn execute_and_measure(mut command: Command, error_message: &str) -> Result { - let cpu_timer = crate::timer::unix_timer::CPUTimer::start(); - let status = command - .status() - .with_context(|| error_message.to_string())?; - let (user_time, system_time) = cpu_timer.stop(); - - Ok(ExecuteResult { - user_time, - system_time, - status, - }) -} - -/// Execute the given command and return a timing summary -#[cfg(windows)] -pub fn execute_and_measure(mut command: Command, error_message: &str) -> Result { - let mut child = command.spawn().with_context(|| error_message.to_string())?; - let cpu_timer = crate::timer::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, - }) -} diff --git a/src/main.rs b/src/main.rs index 9b58f3e..fcd2ae9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,6 @@ pub mod app; pub mod benchmark; pub mod command; pub mod error; -pub mod execute; pub mod export; pub mod options; pub mod outlier_detection; diff --git a/src/timer/mod.rs b/src/timer/mod.rs index fe6a178..473a0eb 100644 --- a/src/timer/mod.rs +++ b/src/timer/mod.rs @@ -1,15 +1,19 @@ -use crate::util::units::Second; - -pub mod wallclocktimer; +pub mod wall_clock_timer; #[cfg(windows)] -pub mod windows_timer; +mod windows_timer; #[cfg(not(windows))] -pub mod unix_timer; +mod unix_timer; + +use crate::util::units::Second; + +use std::process::{Command, ExitStatus}; + +use anyhow::{Context, Result}; #[derive(Debug, Copy, Clone)] -pub struct CPUTimes { +struct CPUTimes { /// Total amount of time spent executing in user mode pub user_usec: i64, @@ -17,11 +21,46 @@ pub struct CPUTimes { pub system_usec: i64, } +/// Used to indicate the result of running a command #[derive(Debug, Copy, Clone)] -pub struct CPUInterval { - /// Total amount of time spent executing in user mode - pub user: Second, +pub struct ExecuteResult { + /// The amount of user time the process used + pub user_time: Second, - /// Total amount of time spent executing in kernel mode - pub system: Second, + /// The amount of cpu time the process used + pub system_time: Second, + + /// The exit status of the process + pub status: ExitStatus, +} + +/// Execute the given command and return a timing summary +#[cfg(not(windows))] +pub fn execute_and_measure(mut command: Command, error_message: &str) -> Result { + let cpu_timer = self::unix_timer::CPUTimer::start(); + let status = command + .status() + .with_context(|| error_message.to_string())?; + let (user_time, system_time) = cpu_timer.stop(); + + Ok(ExecuteResult { + user_time, + system_time, + status, + }) +} + +/// Execute the given command and return a timing summary +#[cfg(windows)] +pub fn execute_and_measure(mut command: Command, error_message: &str) -> Result { + let mut child = command.spawn().with_context(|| error_message.to_string())?; + 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, + }) } diff --git a/src/timer/unix_timer.rs b/src/timer/unix_timer.rs index ae3b62c..1b812b3 100644 --- a/src/timer/unix_timer.rs +++ b/src/timer/unix_timer.rs @@ -2,9 +2,18 @@ use std::mem; -use crate::timer::{CPUInterval, CPUTimes}; +use crate::timer::CPUTimes; use crate::util::units::Second; +#[derive(Debug, Copy, Clone)] +pub struct CPUInterval { + /// Total amount of time spent executing in user mode + pub user: Second, + + /// Total amount of time spent executing in kernel mode + pub system: Second, +} + pub struct CPUTimer { start_cpu: CPUTimes, } diff --git a/src/timer/wallclocktimer.rs b/src/timer/wall_clock_timer.rs similarity index 100% rename from src/timer/wallclocktimer.rs rename to src/timer/wall_clock_timer.rs