Skip to content

Commit 35741d5

Browse files
committed
Demangle cachegrind files immediately after creating them
This avoids the creation of needless `cgfilt` files when comparing two Cachegrind profiles. It also produces a demangled `cgout` file even without using Cachegrind diff.
1 parent 8c07012 commit 35741d5

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

collector/src/bin/collector.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ use collector::runtime::{profile_runtime, RuntimeCompilationOpts};
3939
use collector::toolchain::{
4040
create_toolchain_from_published_version, get_local_toolchain, Sysroot, Toolchain,
4141
};
42-
use collector::utils::mangling::demangle_file;
4342
use collector::utils::wait_for_future;
4443

4544
fn n_normal_benchmarks_remaining(n: usize) -> String {
@@ -162,22 +161,10 @@ fn generate_cachegrind_diffs(
162161
let id_diff = format!("{}-{}", id1, id2);
163162
let cgout1 = out_dir.join(filename("cgout", id1));
164163
let cgout2 = out_dir.join(filename("cgout", id2));
165-
let cgfilt1 = out_dir.join(filename("cgfilt", id1));
166-
let cgfilt2 = out_dir.join(filename("cgfilt", id2));
167164
let cgfilt_diff = out_dir.join(filename("cgfilt-diff", &id_diff));
168165
let cgann_diff = out_dir.join(filename("cgann-diff", &id_diff));
169166

170-
if let Err(e) = demangle_file(&cgout1, &cgfilt1) {
171-
errors.incr();
172-
eprintln!("collector error: {:?}", e);
173-
continue;
174-
}
175-
if let Err(e) = demangle_file(&cgout2, &cgfilt2) {
176-
errors.incr();
177-
eprintln!("collector error: {:?}", e);
178-
continue;
179-
}
180-
if let Err(e) = cg_diff(&cgfilt1, &cgfilt2, &cgfilt_diff) {
167+
if let Err(e) = cg_diff(&cgout1, &cgout2, &cgfilt_diff) {
181168
errors.incr();
182169
eprintln!("collector error: {:?}", e);
183170
continue;

collector/src/utils/cachegrind.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
use crate::utils::mangling::demangle_file;
2+
use anyhow::Context;
13
use std::io::{BufRead, Write};
24
use std::path::Path;
35
use std::process::Command;
46
use std::{fs, io};
57

6-
/// Annotate the output of Cachegrind using the `cg_annotate` tool.
8+
/// Annotate and demangle the output of Cachegrind using the `cg_annotate` tool.
79
pub fn cachegrind_annotate(
810
input: &Path,
911
cgout_output: &Path,
1012
cgann_output: &Path,
1113
) -> anyhow::Result<()> {
14+
let tmp_cgout = tempfile::NamedTempFile::new()?.into_temp_path();
15+
1216
// It's useful to filter all `file:function` entries from
1317
// jemalloc into a single fake
1418
// `<all-jemalloc-files>:<all-jemalloc-functions>` entry. That
@@ -20,7 +24,7 @@ pub fn cachegrind_annotate(
2024
// jemalloc is basically a black box whose code we never look
2125
// at anyway. DHAT is the best way to profile allocations.
2226
let reader = io::BufReader::new(fs::File::open(input)?);
23-
let mut writer = io::BufWriter::new(fs::File::create(cgout_output)?);
27+
let mut writer = io::BufWriter::new(fs::File::create(&tmp_cgout)?);
2428
let mut in_jemalloc_file = false;
2529

2630
// A Cachegrind profile contains `fn=<function-name>` lines,
@@ -50,6 +54,8 @@ pub fn cachegrind_annotate(
5054
}
5155
writer.flush()?;
5256

57+
demangle_file(&tmp_cgout, cgout_output).context("Cannot demangle cgout file")?;
58+
5359
let mut cg_annotate_cmd = Command::new("cg_annotate");
5460
cg_annotate_cmd
5561
.arg("--auto=yes")

0 commit comments

Comments
 (0)