mod.rs
This file
Path
src/timer/mod.rs
64 lines · 1.5 KiB · Rust
Last changed by
Further simplify execute_and_measureDavid Peterbefore adoptione1da8ba
History of this fileTake it
Move to timer moduleDavid Peterbefore adoption0ffc6d7
line 1why, one step back1pub mod wall_clock_timer;Remove timer/internal.rsDavid Peterbefore adoption9d61130
line 2why, one step back2Remove cfg-if dependencyDavid Peterbefore adoption60e9771
line 3why, one step back3#[cfg(windows)]Move to timer moduleDavid Peterbefore adoption0ffc6d7
line 4why, one step back4mod windows_timer;Flat directory/module structureDavid Peterbefore adoption30c381f
line 5why, one step back5Remove cfg-if dependencyDavid Peterbefore adoption60e9771
line 6why, one step back6#[cfg(not(windows))]Move to timer moduleDavid Peterbefore adoption0ffc6d7
line 7why, one step back7mod unix_timer;Remove timer/internal.rsDavid Peterbefore adoption9d61130
line 8why, one step back8Move to timer moduleDavid Peterbefore adoption0ffc6d7
lines 9–12why, one step back9use crate::util::units::Second;1011use std::process::{Command, ExitStatus};12Further simplify execute_and_measureDavid Peterbefore adoptione1da8ba
line 13why, one step back13use anyhow::Result;Move to timer moduleDavid Peterbefore adoption0ffc6d7
line 14why, one step back14Remove timer/internal.rsDavid Peterbefore adoption9d61130
line 15why, one step back15#[derive(Debug, Copy, Clone)]Move to timer moduleDavid Peterbefore adoption0ffc6d7
line 16why, one step back16struct CPUTimes {Remove timer/internal.rsDavid Peterbefore adoption9d61130
lines 17–23why, one step back17 /// Total amount of time spent executing in user mode18 pub user_usec: i64,1920 /// Total amount of time spent executing in kernel mode21 pub system_usec: i64,22}23Move to timer moduleDavid Peterbefore adoption0ffc6d7
line 24why, one step back24/// Used to indicate the result of running a commandRemove timer/internal.rsDavid Peterbefore adoption9d61130
line 25why, one step back25#[derive(Debug, Copy, Clone)]Move to timer moduleDavid Peterbefore adoption0ffc6d7
lines 26–28why, one step back26pub struct ExecuteResult {27 /// The amount of user time the process used28 pub user_time: Second,Remove timer/internal.rsDavid Peterbefore adoption9d61130
line 29why, one step back29Move to timer moduleDavid Peterbefore adoption0ffc6d7
lines 30–38why, one step back30 /// The amount of cpu time the process used31 pub system_time: Second,3233 /// The exit status of the process34 pub status: ExitStatus,35}3637/// Execute the given command and return a timing summary38#[cfg(not(windows))]Further simplify execute_and_measureDavid Peterbefore adoptione1da8ba
line 39why, one step back39pub fn execute_and_measure(mut command: Command) -> Result<ExecuteResult> {Move to timer moduleDavid Peterbefore adoption0ffc6d7
line 40why, one step back40 let cpu_timer = self::unix_timer::CPUTimer::start();Further simplify execute_and_measureDavid Peterbefore adoptione1da8ba
line 41why, one step back41 let status = command.status()?;Move to timer moduleDavid Peterbefore adoption0ffc6d7
lines 42–52why, one step back42 let (user_time, system_time) = cpu_timer.stop();4344 Ok(ExecuteResult {45 user_time,46 system_time,47 status,48 })49}5051/// Execute the given command and return a timing summary52#[cfg(windows)]Further simplify execute_and_measureDavid Peterbefore adoptione1da8ba
lines 53–54why, one step back53pub fn execute_and_measure(mut command: Command) -> Result<ExecuteResult> {54 let mut child = command.spawn()?;Move to timer moduleDavid Peterbefore adoption0ffc6d7
lines 55–63why, one step back55 let cpu_timer = self::windows_timer::CPUTimer::start_for_process(&child);56 let status = child.wait()?;5758 let (user_time, system_time) = cpu_timer.stop();59 Ok(ExecuteResult {60 user_time,61 system_time,62 status,63 })Flat directory/module structureDavid Peterbefore adoption30c381f
line 64why, one step back64}