Skip to content
Myr

Move to timer module

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Peter · committed by David Peter · parent 1f3943e · Browse files · 7 files+81 added−82 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

7 files+81 added−82 removed

  • other:+81 added−82 removed

7 files+81 added−82 removed

modified:src/benchmark/executor.rs+1 added-2 removed
1use std::process::{ExitStatus, Stdio};23use crate::command::Command;4use crate::execute::execute_and_measure;4use crate::options::{CmdFailureAction, CommandOutputPolicy, Options, OutputStyleOption, Shell};5use crate::output::progress_bar::get_progress_bar;7use crate::timer::wallclocktimer::WallClockTimer;6use crate::timer::{execute_and_measure, wall_clock_timer::WallClockTimer};7use crate::util::randomized_environment_offset;8use crate::util::units::Second;910use super::timing_result::TimingResult;
239 unmodified lines
modified:src/timer/mod.rs+50 added-11 removed
1use crate::util::units::Second;1pub mod wall_clock_timer;23pub mod wallclocktimer;43#[cfg(windows)]6pub mod windows_timer;4mod windows_timer;56#[cfg(not(windows))]9pub mod unix_timer;7mod unix_timer;89use crate::util::units::Second;1011use std::process::{Command, ExitStatus};1213use anyhow::{Context, Result};1415#[derive(Debug, Copy, Clone)]12pub struct CPUTimes {16struct CPUTimes {17 /// 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}2324/// Used to indicate the result of running a command25#[derive(Debug, Copy, Clone)]21pub struct CPUInterval {22 /// Total amount of time spent executing in user mode23 pub user: Second,26pub struct ExecuteResult {27 /// The amount of user time the process used28 pub user_time: Second,2925 /// Total amount of time spent executing in kernel mode26 pub system: Second,30 /// 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))]39pub fn execute_and_measure(mut command: Command, error_message: &str) -> Result<ExecuteResult> {40 let cpu_timer = self::unix_timer::CPUTimer::start();41 let status = command42 .status()43 .with_context(|| error_message.to_string())?;44 let (user_time, system_time) = cpu_timer.stop();4546 Ok(ExecuteResult {47 user_time,48 system_time,49 status,50 })51}5253/// Execute the given command and return a timing summary54#[cfg(windows)]55pub fn execute_and_measure(mut command: Command, error_message: &str) -> Result<ExecuteResult> {56 let mut child = command.spawn().with_context(|| error_message.to_string())?;57 let cpu_timer = self::windows_timer::CPUTimer::start_for_process(&child);58 let status = child.wait()?;5960 let (user_time, system_time) = cpu_timer.stop();61 Ok(ExecuteResult {62 user_time,63 system_time,64 status,65 })66}
modified:src/timer/unix_timer.rs+10 added-1 removed
1#![cfg(not(windows))]23use std::mem;45use crate::timer::{CPUInterval, CPUTimes};5use crate::timer::CPUTimes;6use crate::util::units::Second;78#[derive(Debug, Copy, Clone)]9pub struct CPUInterval {10 /// Total amount of time spent executing in user mode11 pub user: Second,1213 /// Total amount of time spent executing in kernel mode14 pub system: Second,15}1617pub struct CPUTimer {18 start_cpu: CPUTimes,19}20
71 unmodified lines
added:src/timer/wall_clock_timer.rs+20 added
1use std::time::Instant;23use crate::util::units::Second;45pub struct WallClockTimer {6 start: Instant,7}89impl WallClockTimer {10 pub fn start() -> WallClockTimer {11 WallClockTimer {12 start: Instant::now(),13 }14 }1516 pub fn stop(&self) -> Second {17 let duration = self.start.elapsed();18 duration.as_secs() as f64 + f64::from(duration.subsec_nanos()) * 1e-919 }20}
deleted:src/timer/wallclocktimer.rs-20 removed
1use std::time::Instant;23use crate::util::units::Second;45pub struct WallClockTimer {6 start: Instant,7}89impl WallClockTimer {10 pub fn start() -> WallClockTimer {11 WallClockTimer {12 start: Instant::now(),13 }14 }1516 pub fn stop(&self) -> Second {17 let duration = self.start.elapsed();18 duration.as_secs() as f64 + f64::from(duration.subsec_nanos()) * 1e-919 }20}
deleted:src/execute.rs-47 removed
1use std::process::{Command, ExitStatus};23use anyhow::{Context, Result};45/// Used to indicate the result of running a command6#[derive(Debug, Copy, Clone)]7pub struct ExecuteResult {8 /// The amount of user time the process used9 pub user_time: f64,1011 /// The amount of cpu time the process used12 pub system_time: f64,1314 /// The exit status of the process15 pub status: ExitStatus,16}1718/// Execute the given command and return a timing summary19#[cfg(not(windows))]20pub fn execute_and_measure(mut command: Command, error_message: &str) -> Result<ExecuteResult> {21 let cpu_timer = crate::timer::unix_timer::CPUTimer::start();22 let status = command23 .status()24 .with_context(|| error_message.to_string())?;25 let (user_time, system_time) = cpu_timer.stop();2627 Ok(ExecuteResult {28 user_time,29 system_time,30 status,31 })32}3334/// Execute the given command and return a timing summary35#[cfg(windows)]36pub fn execute_and_measure(mut command: Command, error_message: &str) -> Result<ExecuteResult> {37 let mut child = command.spawn().with_context(|| error_message.to_string())?;38 let cpu_timer = crate::timer::windows_timer::CPUTimer::start_for_process(&child);39 let status = child.wait()?;4041 let (user_time, system_time) = cpu_timer.stop();42 Ok(ExecuteResult {43 user_time,44 system_time,45 status,46 })47}
modified:src/main.rs-1 removed
11 unmodified lines
12pub mod app;13pub mod benchmark;14pub mod command;15pub mod error;16pub mod execute;16pub mod export;17pub mod options;18pub mod outlier_detection;19pub mod output;
32 unmodified lines