mod.rs (hyperfine-1.14.0) | : | mod.rs (hyperfine-1.15.0) | ||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
use std::os::unix::io::AsRawFd; | use std::os::unix::io::AsRawFd; | |||
use crate::util::units::Second; | use crate::util::units::Second; | |||
use wall_clock_timer::WallClockTimer; | use wall_clock_timer::WallClockTimer; | |||
use std::io::Read; | use std::io::Read; | |||
use std::process::{ChildStdout, Command, ExitStatus}; | use std::process::{ChildStdout, Command, ExitStatus}; | |||
use anyhow::Result; | use anyhow::Result; | |||
#[cfg(not(windows))] | ||||
#[derive(Debug, Copy, Clone)] | #[derive(Debug, Copy, Clone)] | |||
struct CPUTimes { | struct CPUTimes { | |||
/// Total amount of time spent executing in user mode | /// Total amount of time spent executing in user mode | |||
pub user_usec: i64, | pub user_usec: i64, | |||
/// Total amount of time spent executing in kernel mode | /// Total amount of time spent executing in kernel mode | |||
pub system_usec: i64, | pub system_usec: i64, | |||
} | } | |||
/// Used to indicate the result of running a command | /// Used to indicate the result of running a command | |||
skipping to change at line 77 | skipping to change at line 78 | |||
let mut buf = [0; CHUNK_SIZE]; | let mut buf = [0; CHUNK_SIZE]; | |||
while let Ok(bytes) = output.read(&mut buf) { | while let Ok(bytes) = output.read(&mut buf) { | |||
if bytes == 0 { | if bytes == 0 { | |||
break; | break; | |||
} | } | |||
} | } | |||
} | } | |||
/// Execute the given command and return a timing summary | /// Execute the given command and return a timing summary | |||
pub fn execute_and_measure(mut command: Command) -> Result<TimerResult> { | pub fn execute_and_measure(mut command: Command) -> Result<TimerResult> { | |||
let wallclock_timer = WallClockTimer::start(); | ||||
#[cfg(not(windows))] | #[cfg(not(windows))] | |||
let cpu_timer = self::unix_timer::CPUTimer::start(); | let cpu_timer = self::unix_timer::CPUTimer::start(); | |||
#[cfg(windows)] | ||||
{ | ||||
use std::os::windows::process::CommandExt; | ||||
// Create a suspended process | ||||
command.creation_flags(4); | ||||
} | ||||
let wallclock_timer = WallClockTimer::start(); | ||||
let mut child = command.spawn()?; | let mut child = command.spawn()?; | |||
#[cfg(windows)] | #[cfg(windows)] | |||
let cpu_timer = self::windows_timer::CPUTimer::start_for_process(&child); | let cpu_timer = { | |||
// SAFETY: We created a suspended process | ||||
unsafe { self::windows_timer::CPUTimer::start_suspended_process(&child) | ||||
} | ||||
}; | ||||
if let Some(output) = child.stdout.take() { | if let Some(output) = child.stdout.take() { | |||
// Handle CommandOutputPolicy::Pipe | // Handle CommandOutputPolicy::Pipe | |||
discard(output); | discard(output); | |||
} | } | |||
let status = child.wait()?; | let status = child.wait()?; | |||
let (time_user, time_system) = cpu_timer.stop(); | ||||
let time_real = wallclock_timer.stop(); | let time_real = wallclock_timer.stop(); | |||
let (time_user, time_system) = cpu_timer.stop(); | ||||
Ok(TimerResult { | Ok(TimerResult { | |||
time_real, | time_real, | |||
time_user, | time_user, | |||
time_system, | time_system, | |||
status, | status, | |||
}) | }) | |||
} | } | |||
End of changes. 6 change blocks. | ||||
4 lines changed or deleted | 16 lines changed or added |