Skip to content

Commit

Permalink
Add fallback to summarize-0.7 if running raw summarize fails
Browse files Browse the repository at this point in the history
This is intended to ease the transition over rust-lang/rust#67397.
  • Loading branch information
Mark-Simulacrum committed Dec 24, 2019
1 parent c4cd85d commit 0e44914
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions collector/src/bin/rustc-fake.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::env;
use std::path::Path;
use std::process::Command;
use std::time::{Duration, Instant};

Expand Down Expand Up @@ -82,26 +83,9 @@ fn main() {
}
}
let prefix = prefix.expect(&format!("found prefix {:?}", prof_out_dir));
// FIXME: it'd be great to have a less generic name for this;
// we should think about renaming the binary in measureme to measureme, such
// that the command is `measureme summarize ...`.
let mut cmd = Command::new("summarize");
cmd.current_dir(&prof_out_dir);
cmd.arg("summarize").arg("--json");
cmd.arg(&prefix);
let status = cmd.status().expect(&format!(
"summarize spawned successfully in {:?}",
prof_out_dir
));
assert!(
status.success(),
"summarize failed in {:?}; prefix is {:?}",
prof_out_dir,
prefix
);
let json =
std::fs::read_to_string(prof_out_dir.join(&format!("{}.json", prefix)))
.expect("able to read JSON output");
let json = run_summarize("summarize", &prof_out_dir, &prefix)
.or_else(|_| run_summarize("summarize-0.7", &prof_out_dir, &prefix))
.expect("able to run summarize or summarize-0.7");
println!("!self-profile-output:{}", json);
}
}
Expand Down Expand Up @@ -282,6 +266,21 @@ fn print_time(dur: Duration) {
);
}

fn run_summarize(name: &str, prof_out_dir: &Path, prefix: &str) -> std::io::Result<String> {
let mut cmd = Command::new(name);
cmd.current_dir(&prof_out_dir);
cmd.arg("summarize").arg("--json");
cmd.arg(&prefix);
let status = cmd.status()?;
if !status.success() {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
"Failed to run successfully",
));
}
std::fs::read_to_string(prof_out_dir.join(&format!("{}.json", prefix)))
}

#[cfg(windows)]
fn raise_priority() {}

Expand Down

0 comments on commit 0e44914

Please sign in to comment.