Skip to content

Run cachegrind output through rustfilt #1043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion collector/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,22 @@ fn generate_cachegrind_diffs(
let id_diff = format!("{}-{}", id1, id2);
let cgout1 = out_dir.join(filename("cgout", id1));
let cgout2 = out_dir.join(filename("cgout", id2));
let cgfilt1 = out_dir.join(filename("cgfilt", id1));
let cgfilt2 = out_dir.join(filename("cgfilt", id2));
let cgdiff = out_dir.join(filename("cgdiff", &id_diff));
let cgann = out_dir.join(filename("cgann", &id_diff));

if let Err(e) = cg_diff(&cgout1, &cgout2, &cgdiff) {
if let Err(e) = rustfilt(&cgout1, &cgfilt1) {
errors.incr();
eprintln!("collector error: {:?}", e);
continue;
}
if let Err(e) = rustfilt(&cgout2, &cgfilt2) {
errors.incr();
eprintln!("collector error: {:?}", e);
continue;
}
if let Err(e) = cg_diff(&cgfilt1, &cgfilt2, &cgdiff) {
errors.incr();
eprintln!("collector error: {:?}", e);
continue;
Expand All @@ -528,6 +540,24 @@ fn generate_cachegrind_diffs(
}
}

/// Demangles symbols in a file using rustfilt and writes result to path.
fn rustfilt(cgout: &Path, path: &Path) -> anyhow::Result<()> {
let output = Command::new("rustfilt")
.arg("-i")
.arg(cgout)
.stderr(Stdio::inherit())
.output()
.context("failed to run `rustfilt`")?;

if !output.status.success() {
anyhow::bail!("failed to process output with rustfilt");
}

fs::write(path, output.stdout).context("failed to write `rustfilt` output")?;

Ok(())
}

/// Compares two Cachegrind output files using cg_diff and writes result to path.
fn cg_diff(cgout1: &Path, cgout2: &Path, path: &Path) -> anyhow::Result<()> {
let output = Command::new("cg_diff")
Expand Down