Skip to content
Myr

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

3 files+28 added−31 removed

modified:src/timer/mod.rs+12 added-15 removed
11 unmodified lines
12use std::fs::File;13#[cfg(target_os = "linux")]14use std::os::unix::io::AsRawFd;1516#[cfg(not(target_os = "linux"))]17use std::io::Read;1816use crate::util::units::Second;17use wall_clock_timer::WallClockTimer;1819use std::io::Read;20use std::process::{ChildStdout, Command, ExitStatus};2122use anyhow::Result;23
38 unmodified lines
62 }63 }64 }6568 #[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}7475/// Execute the given command and return a timing summary76pub fn execute_and_measure(mut command: Command) -> Result<TimerResult> {77 let wallclock_timer = WallClockTimer::start();7884 let mut child = command.spawn()?;85 let output = child.stdout.take();8679 #[cfg(not(windows))]80 let cpu_timer = self::unix_timer::CPUTimer::start();8182 let mut child = command.spawn()?;8384 #[cfg(windows)]85 let cpu_timer = self::windows_timer::CPUTimer::start_for_process(&child);8692 if let Some(output) = output {87 if let Some(output) = child.stdout.take() {88 // Handle CommandOutputPolicy::Pipe89 discard(output);90 }9192 let status = child.wait()?;9394 let (time_user, time_system) = cpu_timer.stop();95 let time_real = wallclock_timer.stop();
8 unmodified lines
modified:src/error.rs+1 added-1 removed
47 unmodified lines
48 #[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 lines
112113/// How to handle the output of benchmarked commands114#[derive(Debug, Clone, PartialEq)]115pub enum CommandOutputPolicy {116 /// Discard all output117 Discard,116 /// Redirect output to the null device117 Null,118119 /// Feed output through a pipe before discarding it120 Pipe,121122 /// Redirect output to a file123 File(PathBuf),124125 /// Show command output on the terminal126 Forward,126 Inherit,127}128129impl Default for CommandOutputPolicy {130 fn default() -> Self {131 CommandOutputPolicy::Discard131 CommandOutputPolicy::Null132 }133}134135impl 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()),139140 // Typically only stdout is performance-relevant, so just pipe that141 CommandOutputPolicy::Pipe => (Stdio::piped(), Stdio::null()),142
1 unmodified line
144 let file = File::create(&path)?;145 (file.into(), Stdio::null())146 }147148 CommandOutputPolicy::Forward => (Stdio::inherit(), Stdio::inherit()),148 CommandOutputPolicy::Inherit => (Stdio::inherit(), Stdio::inherit()),149 };150151 Ok(streams)152 }
58 unmodified lines
211 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 lines
268269 options.cleanup_command = matches.value_of("cleanup").map(String::from);270271 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 line
283 CommandOutputPolicy::File(path)284 }285 }286 } else {287 CommandOutputPolicy::Discard287 CommandOutputPolicy::Null288 };289290 options.output_style = match matches.value_of("style") {291 Some("full") => OutputStyleOption::Full,
1 unmodified line
293 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