mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-01 00:40:19 +00:00
Move to timer module
This commit is contained in:
1 parent
1f3943e7d1
commit
0ffc6d7cc0
6 files changed
+61
-62
No files matched your search
+50
-11
@@ -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<ExecuteResult> {
|
||||
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<ExecuteResult> {
|
||||
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,
|
||||
})
|
||||
}
|
||||
+10
-1
@@ -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,
|
||||
}
|
||||
|
||||
File renamed without changes.
Reference in new issue
Block a user