Skip to content
Myr

mod.rs

This file

Path

src/timer/mod.rs

95 lines · 2.4 KiB · Rust

Last changed by

RefactoringDavid Peterbefore adoption71365c2

History of this file

Take it

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

Updates for v1.18David Peterbefore adoption45b18d9

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;

Updates for v1.18David Peterbefore adoption45b18d9

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

Unify TimingResult/TimerResult/MeasurementDavid Peterbefore adoption42e75c1

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

Updates for v1.18David Peterbefore adoption45b18d9

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};

Updates for v1.18David Peterbefore adoption45b18d9

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(),

Updates for v1.18David Peterbefore adoption45b18d9

line 36why, one step back
36 None,

Update dependenciesDavid Peterbefore adoption2efc633

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

Updates for v1.18David Peterbefore adoption45b18d9

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> {

Updates for v1.18David Peterbefore adoption45b18d9

lines 60–84why, 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;6667 // 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);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

RefactoringDavid Peterbefore adoption71365c2

line 85why, one step back
85 let (time_user, time_system, peak_memory_usage, exit_status) = cpu_timer.stop(child)?;

Real => wall clockDavid Peterbefore adoptionc20fcc0

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

Updates for v1.18David Peterbefore adoption45b18d9

line 87why, one step back
87

Unify TimingResult/TimerResult/MeasurementDavid Peterbefore adoption42e75c1

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

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

line 89why, one step back
89 time_wall_clock,

Updates for v1.18David Peterbefore adoption45b18d9

lines 90–91why, one step back
90 time_user,
91 time_system,

RefactoringDavid Peterbefore adoption71365c2

line 92why, one step back
92 peak_memory_usage,

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

line 93why, one step back
93 exit_status,

Updates for v1.18David Peterbefore adoption45b18d9

lines 94–95why, one step back
94 })
95}