Skip to content
Myr

mod.rs

This file

Path

src/timer/mod.rs

64 lines · 1.5 KiB · Rust

Last changed by

Move wall clock timer into execute_and_measureDavid Peterbefore adoption55f0ef6

History of this file

Take it

Move wall clock timer into execute_and_measureDavid Peterbefore adoption55f0ef6

line 1why, one step back
1mod 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

line 9why, one step back
9use crate::util::units::Second;

Move wall clock timer into execute_and_measureDavid Peterbefore adoption55f0ef6

line 10why, one step back
10use wall_clock_timer::WallClockTimer;

Move to timer moduleDavid Peterbefore adoption0ffc6d7

lines 11–13why, one step back
11
12use std::process::{Command, ExitStatus};13

Further simplify execute_and_measureDavid Peterbefore adoptione1da8ba

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

Move to timer moduleDavid Peterbefore adoption0ffc6d7

line 15why, one step back
15

Remove timer/internal.rsDavid Peterbefore adoption9d61130

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

Move to timer moduleDavid Peterbefore adoption0ffc6d7

line 17why, one step back
17struct CPUTimes {

Remove timer/internal.rsDavid Peterbefore adoption9d61130

lines 18–24why, one step back
18 /// Total amount of time spent executing in user mode
19 pub user_usec: i64,2021 /// Total amount of time spent executing in kernel mode22 pub system_usec: i64,23}24

Move to timer moduleDavid Peterbefore adoption0ffc6d7

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

Remove timer/internal.rsDavid Peterbefore adoption9d61130

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

Move to timer moduleDavid Peterbefore adoption0ffc6d7

line 27why, one step back
27pub struct ExecuteResult {

Move wall clock timer into execute_and_measureDavid Peterbefore adoption55f0ef6

lines 28–30why, one step back
28 pub time_real: Second,
29 pub time_user: Second,30 pub time_system: Second,

Remove timer/internal.rsDavid Peterbefore adoption9d61130

line 31why, one step back
31

Move to timer moduleDavid Peterbefore adoption0ffc6d7

lines 32–36why, one step back
32 /// The exit status of the process
33 pub status: ExitStatus,34}3536/// Execute the given command and return a timing summary

Further simplify execute_and_measureDavid Peterbefore adoptione1da8ba

line 37why, one step back
37pub fn execute_and_measure(mut command: Command) -> Result<ExecuteResult> {

Move wall clock timer into execute_and_measureDavid Peterbefore adoption55f0ef6

line 38why, one step back
38 let wallclock_timer = WallClockTimer::start();

Move to timer moduleDavid Peterbefore adoption0ffc6d7

line 39why, one step back
39

Move wall clock timer into execute_and_measureDavid Peterbefore adoption55f0ef6

lines 40–45why, one step back
40 #[cfg(not(windows))]
41 let ((time_user, time_system), status) = {42 let cpu_timer = self::unix_timer::CPUTimer::start();43 let status = command.status()?;44 (cpu_timer.stop(), status)45 };

Move to timer moduleDavid Peterbefore adoption0ffc6d7

line 46why, one step back
46

Move wall clock timer into execute_and_measureDavid Peterbefore adoption55f0ef6

lines 47–51why, one step back
47 #[cfg(windows)]
48 let ((time_user, time_system), status) = {49 let mut child = command.spawn()?;50 let cpu_timer = self::windows_timer::CPUTimer::start_for_process(&child);51 let status = child.wait()?;

Move to timer moduleDavid Peterbefore adoption0ffc6d7

line 52why, one step back
52

Move wall clock timer into execute_and_measureDavid Peterbefore adoption55f0ef6

lines 53–57why, one step back
53 (cpu_timer.stop(), status)
54 };5556 let time_real = wallclock_timer.stop();57

Move to timer moduleDavid Peterbefore adoption0ffc6d7

line 58why, one step back
58 Ok(ExecuteResult {

Move wall clock timer into execute_and_measureDavid Peterbefore adoption55f0ef6

lines 59–61why, one step back
59 time_real,
60 time_user,61 time_system,

Move to timer moduleDavid Peterbefore adoption0ffc6d7

lines 62–63why, one step back
62 status,
63 })

Flat directory/module structureDavid Peterbefore adoption30c381f

line 64why, one step back
64}