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 fileTake 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 back1mod wall_clock_timer;2Support hardware counters (instructions, cache misses, ...) (#983)David Peterbefore adoptionbc3a3f0
lines 3–7why, one step back3#[cfg(target_os = "linux")]4mod linux_counters;5#[cfg(target_os = "macos")]6mod macos_counters;7Improve error message, mention --shell=noneDavid Peterbefore adoption926b8d0
lines 8–18why, one step back8#[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 back19use std::os::fd::AsFd;Improve error message, mention --shell=noneDavid Peterbefore adoption926b8d0
lines 20–23why, one step back2021#[cfg(target_os = "windows")]22use windows_sys::Win32::System::Threading::CREATE_SUSPENDED;23Merge pull request #954 from sharkdp/codex/remove-statisticalDavid Peterbefore adoption750fe11
line 24why, one step back24use crate::benchmark::measurement::Measurement;Improve error message, mention --shell=noneDavid Peterbefore adoption926b8d0
lines 25–27why, one step back25use wall_clock_timer::WallClockTimer;2627use std::io::Read;Merge pull request #954 from sharkdp/codex/remove-statisticalDavid Peterbefore adoption750fe11
line 28why, one step back28use std::process::{ChildStdout, Command};Improve error message, mention --shell=noneDavid Peterbefore adoption926b8d0
lines 29–39why, one step back2930use 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 back40 output.as_fd(),Improve error message, mention --shell=noneDavid Peterbefore adoption926b8d0
line 41why, one step back41 None,Update dependenciesDavid Peterbefore adoption2efc633
line 42why, one step back42 file.as_fd(),Improve error message, mention --shell=noneDavid Peterbefore adoption926b8d0
lines 43–63why, one step back43 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 summarySupport hardware counters (instructions, cache misses, ...) (#983)David Peterbefore adoptionbc3a3f0
lines 64–69why, one step back64pub 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 back70 #[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 }94Support hardware counters (instructions, cache misses, ...) (#983)David Peterbefore adoptionbc3a3f0
lines 95–105why, one step back95 #[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 back106 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 back107 #[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 back110 let time_wall_clock = wallclock_timer.stop();Improve error message, mention --shell=noneDavid Peterbefore adoption926b8d0
line 111why, one step back111Support hardware counters (instructions, cache misses, ...) (#983)David Peterbefore adoptionbc3a3f0
lines 112–118why, one step back112 #[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();118Merge pull request #954 from sharkdp/codex/remove-statisticalDavid Peterbefore adoption750fe11
line 119why, one step back119 Ok(Measurement {Merge pull request #958 from sharkdp/codex/measurements-collectionDavid Peterbefore adoption16e23a1
line 120why, one step back120 time_wall_clock,Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 121why, one step back121 time_cpu: time_user + time_system,Improve error message, mention --shell=noneDavid Peterbefore adoption926b8d0
lines 122–123why, one step back122 time_user,123 time_system,Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
line 124why, one step back124 memory_peak_resident,Support hardware counters (instructions, cache misses, ...) (#983)David Peterbefore adoptionbc3a3f0
line 125why, one step back125 hardware_counters,Merge pull request #958 from sharkdp/codex/measurements-collectionDavid Peterbefore adoption16e23a1
line 126why, one step back126 exit_status,Improve error message, mention --shell=noneDavid Peterbefore adoption926b8d0
lines 127–128why, one step back127 })128}