Skip to content

Commit 6a28881

Browse files
committed
Stream output of the rustc benchmark
1 parent d7d577d commit 6a28881

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

collector/src/compile/execute/rustc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ async fn record(
105105
.context("configuring")?;
106106
assert!(status.success(), "configure successful");
107107

108-
let output = crate::command_output(
108+
let output = crate::command_output_stream(
109109
Command::new("python3")
110110
.arg(
111111
checkout

collector/src/lib.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,12 @@ pub fn run_command(cmd: &mut Command) -> anyhow::Result<()> {
168168
Ok(())
169169
}
170170

171-
fn run_command_with_output(cmd: &mut Command) -> anyhow::Result<process::Output> {
171+
/// If `stream_output` is true, stdout/stderr of `cmd` should be streamed to stdout/stderr of the
172+
/// current process, in addition to being captured.
173+
fn run_command_with_output(
174+
cmd: &mut Command,
175+
stream_output: bool,
176+
) -> anyhow::Result<process::Output> {
172177
use anyhow::Context;
173178
use utils::read2;
174179
let mut child = cmd
@@ -187,7 +192,7 @@ fn run_command_with_output(cmd: &mut Command) -> anyhow::Result<process::Output>
187192
child.stderr.take().unwrap(),
188193
&mut |is_stdout, buffer, _is_done| {
189194
// Send output if trace logging is enabled
190-
if log::log_enabled!(target: "raw_cargo_messages", log::Level::Trace) {
195+
if stream_output || log::log_enabled!(target: "raw_cargo_messages", log::Level::Trace) {
191196
use std::io::Write;
192197
if is_stdout {
193198
stdout_writer.write_all(&buffer[stdout_written..]).unwrap();
@@ -215,18 +220,28 @@ fn run_command_with_output(cmd: &mut Command) -> anyhow::Result<process::Output>
215220
}
216221

217222
pub fn command_output(cmd: &mut Command) -> anyhow::Result<process::Output> {
218-
let output = run_command_with_output(cmd)?;
223+
let output = run_command_with_output(cmd, false)?;
224+
check_command_output(&output)?;
225+
Ok(output)
226+
}
227+
228+
pub fn command_output_stream(cmd: &mut Command) -> anyhow::Result<process::Output> {
229+
let output = run_command_with_output(cmd, true)?;
230+
check_command_output(&output)?;
231+
Ok(output)
232+
}
219233

234+
fn check_command_output(output: &process::Output) -> anyhow::Result<()> {
220235
if !output.status.success() {
221-
return Err(anyhow::anyhow!(
236+
Err(anyhow::anyhow!(
222237
"expected success, got {}\n\nstderr={}\n\n stdout={}\n",
223238
output.status,
224239
String::from_utf8_lossy(&output.stderr),
225240
String::from_utf8_lossy(&output.stdout)
226-
));
241+
))
242+
} else {
243+
Ok(())
227244
}
228-
229-
Ok(output)
230245
}
231246

232247
pub async fn async_command_output(

0 commit comments

Comments
 (0)