Address review comments
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tavian Barnes · committed by David Peter · parent efdf735 · Browse files · 3 files·+28 added−31 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+28 added−31 removed
- other:+28 added−31 removed
Provenance
- Commit
3df63ba- Tree
e18d264- Author
Tavian Barnes <tavianator@tavianator.com>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
efdf735
3 files changed+28 added−31 removed
modified:src/timer/mod.rs+12 added-15 removed
11 unmodified lines12 use std::fs::File;13 #[cfg(target_os = "linux")]14 use std::os::unix::io::AsRawFd;15 16-#[cfg(not(target_os = "linux"))]17-use std::io::Read;18-16 use crate::util::units::Second;17 use wall_clock_timer::WallClockTimer;18 19+use std::io::Read;20 use std::process::{ChildStdout, Command, ExitStatus};21 22 use anyhow::Result;23 38 unmodified lines62 }63 }64 }65 68- #[cfg(not(target_os = "linux"))]69- {70- let mut output = output;71- let mut buf = [0; CHUNK_SIZE];72- while let Ok(bytes) = output.read(&mut buf) {73- if bytes == 0 {74- break;66+ 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;75- }71 }72 }73 }74 75 /// Execute the given command and return a timing summary76 pub fn execute_and_measure(mut command: Command) -> Result<TimerResult> {77 let wallclock_timer = WallClockTimer::start();78 84- let mut child = command.spawn()?;85- let output = child.stdout.take();86-79 #[cfg(not(windows))]80 let cpu_timer = self::unix_timer::CPUTimer::start();81+82+ let mut child = command.spawn()?;83+84 #[cfg(windows)]85 let cpu_timer = self::windows_timer::CPUTimer::start_for_process(&child);86 92- if let Some(output) = output {87+ if let Some(output) = child.stdout.take() {88+ // Handle CommandOutputPolicy::Pipe89 discard(output);90 }91+92 let status = child.wait()?;93 94 let (time_user, time_system) = cpu_timer.stop();95 let time_real = wallclock_timer.stop();8 unmodified linesmodified:src/error.rs+1 added-1 removed
47 unmodified lines48 #[error("An empty command has been specified for the '--shell <command>' option")]49 EmptyShell,50 #[error("Failed to parse '--shell <command>' expression as command line: {0}")]51 ShellParseError(shell_words::ParseError),52- #[error("Unknown output policy '{0}'. Use ./{0} to output to a file named {0}.")]52+ #[error("Unknown output policy '{0}'. Use './{0}' to output to a file named '{0}'.")]53 UnknownOutputPolicy(String),54 }modified:src/options.rs+15 added-15 removed
111 unmodified lines112 113 /// How to handle the output of benchmarked commands114 #[derive(Debug, Clone, PartialEq)]115 pub enum CommandOutputPolicy {116- /// Discard all output117- Discard,116+ /// Redirect output to the null device117+ Null,118 119 /// Feed output through a pipe before discarding it120 Pipe,121 122 /// Redirect output to a file123 File(PathBuf),124 125 /// Show command output on the terminal126- Forward,126+ Inherit,127 }128 129 impl Default for CommandOutputPolicy {130 fn default() -> Self {131- CommandOutputPolicy::Discard131+ CommandOutputPolicy::Null132 }133 }134 135 impl CommandOutputPolicy {136 pub fn get_stdout_stderr(&self) -> io::Result<(Stdio, Stdio)> {137 let streams = match self {138- CommandOutputPolicy::Discard => (Stdio::null(), Stdio::null()),138+ CommandOutputPolicy::Null => (Stdio::null(), Stdio::null()),139 140 // Typically only stdout is performance-relevant, so just pipe that141 CommandOutputPolicy::Pipe => (Stdio::piped(), Stdio::null()),142 1 unmodified line144 let file = File::create(&path)?;145 (file.into(), Stdio::null())146 }147 148- CommandOutputPolicy::Forward => (Stdio::inherit(), Stdio::inherit()),148+ CommandOutputPolicy::Inherit => (Stdio::inherit(), Stdio::inherit()),149 };150 151 Ok(streams)152 }58 unmodified lines211 setup_command: None,212 cleanup_command: None,213 output_style: OutputStyleOption::Full,214 executor_kind: ExecutorKind::default(),215- command_output_policy: CommandOutputPolicy::Discard,215+ command_output_policy: CommandOutputPolicy::Null,216 time_unit: None,217 }218 }219 }48 unmodified lines268 269 options.cleanup_command = matches.value_of("cleanup").map(String::from);270 271 options.command_output_policy = if matches.is_present("show-output") {272- CommandOutputPolicy::Forward272+ CommandOutputPolicy::Inherit273 } else if let Some(output) = matches.value_of("output") {274 match output {275- "null" => CommandOutputPolicy::Discard,275+ "null" => CommandOutputPolicy::Null,276 "pipe" => CommandOutputPolicy::Pipe,277- "inherit" => CommandOutputPolicy::Forward,277+ "inherit" => CommandOutputPolicy::Inherit,278 arg => {279 let path = PathBuf::from(arg);280 if path.components().count() <= 1 {281 return Err(OptionsError::UnknownOutputPolicy(arg.to_string()));1 unmodified line283 CommandOutputPolicy::File(path)284 }285 }286 } else {287- CommandOutputPolicy::Discard287+ CommandOutputPolicy::Null288 };289 290 options.output_style = match matches.value_of("style") {291 Some("full") => OutputStyleOption::Full,1 unmodified line293 Some("nocolor") => OutputStyleOption::NoColor,294 Some("color") => OutputStyleOption::Color,295 Some("none") => OutputStyleOption::Disabled,296 _ => {297- if options.command_output_policy != CommandOutputPolicy::Forward298- && atty::is(Stream::Stdout)297+ if options.command_output_policy == CommandOutputPolicy::Inherit298+ || !atty::is(Stream::Stdout)299 {300- OutputStyleOption::Full301- } else {300 OutputStyleOption::Basic301+ } else {302+ OutputStyleOption::Full303 }304 }305 };306 93 unmodified lines