mod.rs
This file
Path
src/timer/mod.rs
103 lines · 2.4 KiB · Rust
Last changed by
Address review commentsTavian Barnesbefore adoption3df63ba
History of this fileTake it
Move wall clock timer into execute_and_measureDavid Peterbefore adoption55f0ef6
line 1why, one step back1mod 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 back8Implement --output={null,pipe,<FILE>}Tavian Barnesbefore adoption277807c
lines 9–15why, one step back9#[cfg(target_os = "linux")]10use nix::fcntl::{splice, SpliceFFlags};11#[cfg(target_os = "linux")]12use std::fs::File;13#[cfg(target_os = "linux")]14use std::os::unix::io::AsRawFd;15Move to timer moduleDavid Peterbefore adoption0ffc6d7
line 16why, one step back16use crate::util::units::Second;Move wall clock timer into execute_and_measureDavid Peterbefore adoption55f0ef6
line 17why, one step back17use wall_clock_timer::WallClockTimer;Move to timer moduleDavid Peterbefore adoption0ffc6d7
line 18why, one step back18Address review commentsTavian Barnesbefore adoption3df63ba
line 19why, one step back19use std::io::Read;Implement --output={null,pipe,<FILE>}Tavian Barnesbefore adoption277807c
line 20why, one step back20use std::process::{ChildStdout, Command, ExitStatus};Move to timer moduleDavid Peterbefore adoption0ffc6d7
line 21why, one step back21Further simplify execute_and_measureDavid Peterbefore adoptione1da8ba
line 22why, one step back22use anyhow::Result;Move to timer moduleDavid Peterbefore adoption0ffc6d7
line 23why, one step back23Remove timer/internal.rsDavid Peterbefore adoption9d61130
line 24why, one step back24#[derive(Debug, Copy, Clone)]Move to timer moduleDavid Peterbefore adoption0ffc6d7
line 25why, one step back25struct CPUTimes {Remove timer/internal.rsDavid Peterbefore adoption9d61130
lines 26–32why, one step back26 /// Total amount of time spent executing in user mode27 pub user_usec: i64,2829 /// Total amount of time spent executing in kernel mode30 pub system_usec: i64,31}32Move to timer moduleDavid Peterbefore adoption0ffc6d7
line 33why, one step back33/// Used to indicate the result of running a commandRemove timer/internal.rsDavid Peterbefore adoption9d61130
line 34why, one step back34#[derive(Debug, Copy, Clone)]Rename to TimerResultDavid Peterbefore adoption7fd4aea
line 35why, one step back35pub struct TimerResult {Move wall clock timer into execute_and_measureDavid Peterbefore adoption55f0ef6
lines 36–38why, one step back36 pub time_real: Second,37 pub time_user: Second,38 pub time_system: Second,Remove timer/internal.rsDavid Peterbefore adoption9d61130
line 39why, one step back39Move to timer moduleDavid Peterbefore adoption0ffc6d7
lines 40–43why, one step back40 /// The exit status of the process41 pub status: ExitStatus,42}43Implement --output={null,pipe,<FILE>}Tavian Barnesbefore adoption277807c
lines 44–65why, one step back44/// Discard the output of a child process.45fn discard(output: ChildStdout) {46 const CHUNK_SIZE: usize = 64 << 10;4748 #[cfg(target_os = "linux")]49 {50 if let Ok(file) = File::create("/dev/null") {51 while let Ok(bytes) = splice(52 output.as_raw_fd(),53 None,54 file.as_raw_fd(),55 None,56 CHUNK_SIZE,57 SpliceFFlags::empty(),58 ) {59 if bytes == 0 {60 break;61 }62 }63 }64 }65Address review commentsTavian Barnesbefore adoption3df63ba
lines 66–70why, one step back66 let mut output = output;67 let mut buf = [0; CHUNK_SIZE];68 while let Ok(bytes) = output.read(&mut buf) {69 if bytes == 0 {70 break;Implement --output={null,pipe,<FILE>}Tavian Barnesbefore adoption277807c
lines 71–74why, one step back71 }72 }73}74Move to timer moduleDavid Peterbefore adoption0ffc6d7
line 75why, one step back75/// Execute the given command and return a timing summaryRename to TimerResultDavid Peterbefore adoption7fd4aea
line 76why, one step back76pub fn execute_and_measure(mut command: Command) -> Result<TimerResult> {Move wall clock timer into execute_and_measureDavid Peterbefore adoption55f0ef6
line 77why, one step back77 let wallclock_timer = WallClockTimer::start();Move to timer moduleDavid Peterbefore adoption0ffc6d7
line 78why, one step back78Implement --output={null,pipe,<FILE>}Tavian Barnesbefore adoption277807c
lines 79–80why, one step back79 #[cfg(not(windows))]80 let cpu_timer = self::unix_timer::CPUTimer::start();Address review commentsTavian Barnesbefore adoption3df63ba
lines 81–83why, one step back8182 let mut child = command.spawn()?;83Move wall clock timer into execute_and_measureDavid Peterbefore adoption55f0ef6
line 84why, one step back84 #[cfg(windows)]Implement --output={null,pipe,<FILE>}Tavian Barnesbefore adoption277807c
line 85why, one step back85 let cpu_timer = self::windows_timer::CPUTimer::start_for_process(&child);Move to timer moduleDavid Peterbefore adoption0ffc6d7
line 86why, one step back86Address review commentsTavian Barnesbefore adoption3df63ba
lines 87–88why, one step back87 if let Some(output) = child.stdout.take() {88 // Handle CommandOutputPolicy::PipeImplement --output={null,pipe,<FILE>}Tavian Barnesbefore adoption277807c
lines 89–90why, one step back89 discard(output);90 }Address review commentsTavian Barnesbefore adoption3df63ba
line 91why, one step back91Implement --output={null,pipe,<FILE>}Tavian Barnesbefore adoption277807c
line 92why, one step back92 let status = child.wait()?;Move wall clock timer into execute_and_measureDavid Peterbefore adoption55f0ef6
line 93why, one step back93Implement --output={null,pipe,<FILE>}Tavian Barnesbefore adoption277807c
line 94why, one step back94 let (time_user, time_system) = cpu_timer.stop();Move wall clock timer into execute_and_measureDavid Peterbefore adoption55f0ef6
lines 95–96why, one step back95 let time_real = wallclock_timer.stop();96Rename to TimerResultDavid Peterbefore adoption7fd4aea
line 97why, one step back97 Ok(TimerResult {Move wall clock timer into execute_and_measureDavid Peterbefore adoption55f0ef6
lines 98–100why, one step back98 time_real,99 time_user,100 time_system,Move to timer moduleDavid Peterbefore adoption0ffc6d7
lines 101–102why, one step back101 status,102 })Flat directory/module structureDavid Peterbefore adoption30c381f
line 103why, one step back103}