Skip to content
Myr

mod.rs

This file

Path

src/timer/mod.rs

128 lines · 3.5 KiB · Rust

Last changed by

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

History of this file

Take it

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

Improve error message, mention --shell=noneDavid Peterbefore adoption926b8d0

lines 1–2why, one step back
1mod wall_clock_timer;
2

Support hardware counters (instructions, cache misses, ...) (#983)David Peterbefore adoptionbc3a3f0

lines 3–7why, one step back
3#[cfg(target_os = "linux")]
4mod linux_counters;5#[cfg(target_os = "macos")]6mod macos_counters;7

Improve error message, mention --shell=noneDavid Peterbefore adoption926b8d0

lines 8–18why, one step back
8#[cfg(windows)]
9mod windows_timer;1011#[cfg(not(windows))]12mod unix_timer;1314#[cfg(target_os = "linux")]15use nix::fcntl::{splice, SpliceFFlags};16#[cfg(target_os = "linux")]17use std::fs::File;18#[cfg(target_os = "linux")]

Update dependenciesDavid Peterbefore adoption2efc633

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

Improve error message, mention --shell=noneDavid Peterbefore adoption926b8d0

lines 20–23why, one step back
20
21#[cfg(target_os = "windows")]22use windows_sys::Win32::System::Threading::CREATE_SUSPENDED;23

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

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

Improve error message, mention --shell=noneDavid Peterbefore adoption926b8d0

lines 25–27why, one step back
25use wall_clock_timer::WallClockTimer;
2627use std::io::Read;

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

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

Improve error message, mention --shell=noneDavid Peterbefore adoption926b8d0

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

Update dependenciesDavid Peterbefore adoption2efc633

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

Improve error message, mention --shell=noneDavid Peterbefore adoption926b8d0

line 41why, one step back
41 None,

Update dependenciesDavid Peterbefore adoption2efc633

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

Improve error message, mention --shell=noneDavid Peterbefore adoption926b8d0

lines 43–63why, one step back
43 None,
44 CHUNK_SIZE,45 SpliceFFlags::empty(),46 ) {47 if bytes == 0 {48 break;49 }50 }51 }52 }5354 let mut output = output;55 let mut buf = [0; CHUNK_SIZE];56 while let Ok(bytes) = output.read(&mut buf) {57 if bytes == 0 {58 break;59 }60 }61}6263/// Execute the given command and return a timing summary

Support hardware counters (instructions, cache misses, ...) (#983)David Peterbefore adoptionbc3a3f0

lines 64–69why, one step back
64pub fn execute_and_measure(
65 mut command: Command,66 _collect_hardware_counters: bool,67) -> Result<Measurement> {68 #[cfg(target_os = "linux")]69 let counters = _collect_hardware_counters.then(linux_counters::CounterGroup::new);

Improve error message, mention --shell=noneDavid Peterbefore adoption926b8d0

lines 70–94why, one step back
70 #[cfg(not(windows))]
71 let cpu_timer = self::unix_timer::CPUTimer::start();7273 #[cfg(windows)]74 {75 use std::os::windows::process::CommandExt;7677 // Create the process in a suspended state so that we don't miss any cpu time between process creation and `CPUTimer` start.78 command.creation_flags(CREATE_SUSPENDED);79 }8081 let wallclock_timer = WallClockTimer::start();82 let mut child = command.spawn()?;8384 #[cfg(windows)]85 let cpu_timer = {86 // SAFETY: We created a suspended process87 unsafe { self::windows_timer::CPUTimer::start_suspended_process(&child) }88 };8990 if let Some(output) = child.stdout.take() {91 // Handle CommandOutputPolicy::Pipe92 discard(output);93 }94

Support hardware counters (instructions, cache misses, ...) (#983)David Peterbefore adoptionbc3a3f0

lines 95–105why, one step back
95 #[cfg(target_os = "macos")]
96 let (time_wall_clock, hardware_counters) =97 if _collect_hardware_counters && macos_counters::wait(&mut child).is_ok() {98 // Stop timing before querying counters, but leave the child available for wait4.99 (100 Some(wallclock_timer.stop()),101 macos_counters::read(child.id()),102 )103 } else {104 (None, Default::default())105 };

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

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

Support hardware counters (instructions, cache misses, ...) (#983)David Peterbefore adoptionbc3a3f0

lines 107–109why, one step back
107 #[cfg(target_os = "macos")]
108 let time_wall_clock = time_wall_clock.unwrap_or_else(|| wallclock_timer.stop());109 #[cfg(not(target_os = "macos"))]

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

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

Improve error message, mention --shell=noneDavid Peterbefore adoption926b8d0

line 111why, one step back
111

Support hardware counters (instructions, cache misses, ...) (#983)David Peterbefore adoptionbc3a3f0

lines 112–118why, one step back
112 #[cfg(target_os = "linux")]
113 let hardware_counters = counters114 .map(linux_counters::CounterGroup::read)115 .unwrap_or_default();116 #[cfg(not(any(target_os = "linux", target_os = "macos")))]117 let hardware_counters = Default::default();118

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

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

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

line 120why, one step back
120 time_wall_clock,

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 121why, one step back
121 time_cpu: time_user + time_system,

Improve error message, mention --shell=noneDavid Peterbefore adoption926b8d0

lines 122–123why, one step back
122 time_user,
123 time_system,

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

line 124why, one step back
124 memory_peak_resident,

Support hardware counters (instructions, cache misses, ...) (#983)David Peterbefore adoptionbc3a3f0

line 125why, one step back
125 hardware_counters,

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

line 126why, one step back
126 exit_status,

Improve error message, mention --shell=noneDavid Peterbefore adoption926b8d0

lines 127–128why, one step back
127 })
128}