Skip to content
Myr

mod.rs

This file

Path

src/timer/mod.rs

103 lines · 2.5 KiB · Rust

Last changed by

Merge pull request #965 from sharkdp/codex/wait4-resource-usageDavid Peterbefore adoptione43bf85

History of this file

Take it

The walk stopped after 200 commits: lines older than e88fa27 point at it.

Change order of input/oututDavid Peterbefore adoptione88fa27

lines 1–13why, one step back
1mod wall_clock_timer;
23#[cfg(windows)]4mod windows_timer;56#[cfg(not(windows))]7mod unix_timer;89#[cfg(target_os = "linux")]10use nix::fcntl::{splice, SpliceFFlags};11#[cfg(target_os = "linux")]12use std::fs::File;13#[cfg(target_os = "linux")]

Update dependenciesDavid Peterbefore adoption2efc633

line 14why, one step back
14use std::os::fd::AsFd;

Change order of input/oututDavid Peterbefore adoptione88fa27

line 15why, one step back
15

Use windows-sys and fix feature flagClemens Wasserbefore adoptiond2fb7d4

lines 16–18why, one step back
16#[cfg(target_os = "windows")]
17use windows_sys::Win32::System::Threading::CREATE_SUSPENDED;18

Merge pull request #954 from sharkdp/codex/remove-statisticalDavid Peterbefore adoption750fe11

line 19why, one step back
19use crate::benchmark::measurement::Measurement;

Change order of input/oututDavid Peterbefore adoptione88fa27

lines 20–22why, one step back
20use wall_clock_timer::WallClockTimer;
2122use std::io::Read;

Merge pull request #954 from sharkdp/codex/remove-statisticalDavid Peterbefore adoption750fe11

line 23why, one step back
23use std::process::{ChildStdout, Command};

Change order of input/oututDavid Peterbefore adoptione88fa27

lines 24–34why, one step back
24
25use anyhow::Result;2627/// Discard the output of a child process.28fn discard(output: ChildStdout) {29 const CHUNK_SIZE: usize = 64 << 10;3031 #[cfg(target_os = "linux")]32 {33 if let Ok(file) = File::create("/dev/null") {34 while let Ok(bytes) = splice(

Update dependenciesDavid Peterbefore adoption2efc633

line 35why, one step back
35 output.as_fd(),

Change order of input/oututDavid Peterbefore adoptione88fa27

line 36why, one step back
36 None,

Update dependenciesDavid Peterbefore adoption2efc633

line 37why, one step back
37 file.as_fd(),

Change order of input/oututDavid Peterbefore adoptione88fa27

lines 38–58why, one step back
38 None,
39 CHUNK_SIZE,40 SpliceFFlags::empty(),41 ) {42 if bytes == 0 {43 break;44 }45 }46 }47 }4849 let mut output = output;50 let mut buf = [0; CHUNK_SIZE];51 while let Ok(bytes) = output.read(&mut buf) {52 if bytes == 0 {53 break;54 }55 }56}5758/// Execute the given command and return a timing summary

Merge pull request #954 from sharkdp/codex/remove-statisticalDavid Peterbefore adoption750fe11

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

Change order of input/oututDavid Peterbefore adoptione88fa27

lines 60–66why, one step back
60 #[cfg(not(windows))]
61 let cpu_timer = self::unix_timer::CPUTimer::start();6263 #[cfg(windows)]64 {65 use std::os::windows::process::CommandExt;66

Use windows-sys and fix feature flagClemens Wasserbefore adoptiond2fb7d4

lines 67–68why, one step back
67 // Create the process in a suspended state so that we don't miss any cpu time between process creation and `CPUTimer` start.
68 command.creation_flags(CREATE_SUSPENDED);

Change order of input/oututDavid Peterbefore adoptione88fa27

lines 69–84why, one step back
69 }
7071 let wallclock_timer = WallClockTimer::start();72 let mut child = command.spawn()?;7374 #[cfg(windows)]75 let cpu_timer = {76 // SAFETY: We created a suspended process77 unsafe { self::windows_timer::CPUTimer::start_suspended_process(&child) }78 };7980 if let Some(output) = child.stdout.take() {81 // Handle CommandOutputPolicy::Pipe82 discard(output);83 }84

Merge pull request #965 from sharkdp/codex/wait4-resource-usageDavid Peterbefore adoptione43bf85

lines 85–88why, one step back
85 #[cfg(not(windows))]
86 let (time_user, time_system, peak_memory_usage, exit_status) = cpu_timer.stop(child)?;8788 #[cfg(windows)]

Merge pull request #958 from sharkdp/codex/measurements-collectionDavid Peterbefore adoption16e23a1

line 89why, one step back
89 let exit_status = child.wait()?;

Change order of input/oututDavid Peterbefore adoptione88fa27

line 90why, one step back
90

Merge pull request #958 from sharkdp/codex/measurements-collectionDavid Peterbefore adoption16e23a1

line 91why, one step back
91 let time_wall_clock = wallclock_timer.stop();

Merge pull request #965 from sharkdp/codex/wait4-resource-usageDavid Peterbefore adoptione43bf85

lines 92–93why, one step back
92
93 #[cfg(windows)]

Merge pull request #958 from sharkdp/codex/measurements-collectionDavid Peterbefore adoption16e23a1

line 94why, one step back
94 let (time_user, time_system, peak_memory_usage) = cpu_timer.stop();

Change order of input/oututDavid Peterbefore adoptione88fa27

line 95why, one step back
95

Merge pull request #954 from sharkdp/codex/remove-statisticalDavid Peterbefore adoption750fe11

line 96why, one step back
96 Ok(Measurement {

Merge pull request #958 from sharkdp/codex/measurements-collectionDavid Peterbefore adoption16e23a1

line 97why, one step back
97 time_wall_clock,

Change order of input/oututDavid Peterbefore adoptione88fa27

lines 98–99why, one step back
98 time_user,
99 time_system,

Merge pull request #958 from sharkdp/codex/measurements-collectionDavid Peterbefore adoption16e23a1

lines 100–101why, one step back
100 peak_memory_usage,
101 exit_status,

Change order of input/oututDavid Peterbefore adoptione88fa27

lines 102–103why, one step back
102 })
103}