Skip to content
Myr

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 file

Take it

Move to timer moduleDavid Peterbefore adoption0ffc6d7

line 1why, one step back
1pub mod wall_clock_timer;

Remove timer/internal.rsDavid Peterbefore adoption9d61130

line 2why, one step back
2

Remove cfg-if dependencyDavid Peterbefore adoption60e9771

line 3why, one step back
3#[cfg(windows)]

Move to timer moduleDavid Peterbefore adoption0ffc6d7

line 4why, one step back
4mod windows_timer;

Flat directory/module structureDavid Peterbefore adoption30c381f

line 5why, one step back
5

Remove cfg-if dependencyDavid Peterbefore adoption60e9771

line 6why, one step back
6#[cfg(not(windows))]

Move to timer moduleDavid Peterbefore adoption0ffc6d7

line 7why, one step back
7mod unix_timer;

Remove timer/internal.rsDavid Peterbefore adoption9d61130

line 8why, one step back
8

Move to timer moduleDavid Peterbefore adoption0ffc6d7

lines 9–12why, one step back
9use crate::util::units::Second;
1011use std::process::{Command, ExitStatus};12

Further simplify execute_and_measureDavid Peterbefore adoptione1da8ba

line 13why, one step back
13use anyhow::Result;

Move to timer moduleDavid Peterbefore adoption0ffc6d7

line 14why, one step back
14

Remove timer/internal.rsDavid Peterbefore adoption9d61130

line 15why, one step back
15#[derive(Debug, Copy, Clone)]

Move to timer moduleDavid Peterbefore adoption0ffc6d7

line 16why, one step back
16struct CPUTimes {

Remove timer/internal.rsDavid Peterbefore adoption9d61130

lines 17–23why, one step back
17 /// Total amount of time spent executing in user mode
18 pub user_usec: i64,1920 /// Total amount of time spent executing in kernel mode21 pub system_usec: i64,22}23

Move to timer moduleDavid Peterbefore adoption0ffc6d7

line 24why, one step back
24/// Used to indicate the result of running a command

Remove timer/internal.rsDavid Peterbefore adoption9d61130

line 25why, one step back
25#[derive(Debug, Copy, Clone)]

Move to timer moduleDavid Peterbefore adoption0ffc6d7

lines 26–28why, one step back
26pub 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 back
29

Move to timer moduleDavid Peterbefore adoption0ffc6d7

lines 30–38why, one step back
30 /// The amount of cpu time the process used
31 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 back
39pub fn execute_and_measure(mut command: Command) -> Result<ExecuteResult> {

Move to timer moduleDavid Peterbefore adoption0ffc6d7

line 40why, one step back
40 let cpu_timer = self::unix_timer::CPUTimer::start();

Further simplify execute_and_measureDavid Peterbefore adoptione1da8ba

line 41why, one step back
41 let status = command.status()?;

Move to timer moduleDavid Peterbefore adoption0ffc6d7

lines 42–52why, one step back
42 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 back
53pub 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 back
55 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 back
64}