Skip to content

Commit f4d787b

Browse files
authored
Merge pull request #1192 from nnethercote/add-dhat-copy
Add `DhatCopy` as a profiler.
2 parents 1e8322f + 8b33793 commit f4d787b

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

ci/check-profiling.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ RUST_BACKTRACE=1 RUST_LOG=raw_cargo_messages=trace,collector=debug,rust_sysroot=
8888
test -f results/dhout-Test-helloworld-Check-Full
8989
grep -q "dhatFileVersion" results/dhout-Test-helloworld-Check-Full
9090

91+
92+
# DHAT (copy mode).
93+
# FIXME: CI currently runs Ubuntu 20.04 LTS, which has a Valgrind that is too
94+
# old to run with `--mode=copy`. When CI is upgraded to 22.04, uncomment this.
95+
#RUST_BACKTRACE=1 RUST_LOG=raw_cargo_messages=trace,collector=debug,rust_sysroot=debug \
96+
# cargo run -p collector --bin collector -- \
97+
# profile_local dhat-copy $bindir/rustc \
98+
# --id Test \
99+
# --profiles Check \
100+
# --cargo $bindir/cargo \
101+
# --include helloworld \
102+
# --scenarios Full
103+
#test -f results/dhcopy-Test-helloworld-Check-Full
104+
#grep -q "dhatFileVersion" results/dhcopy-Test-helloworld-Check-Full
105+
91106
# Massif.
92107
RUST_BACKTRACE=1 RUST_LOG=raw_cargo_messages=trace,collector=debug,rust_sysroot=debug \
93108
cargo run -p collector --bin collector -- \

collector/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,15 @@ The mandatory `<PROFILER>` argument must be one of the following.
340340
run more slowly and increase the size of its data files.
341341
- **Output**. Raw output is written to files with a `dhout` prefix. Those
342342
files can be viewed with DHAT's viewer (`dh_view.html`).
343+
- `dhat-copy`: Profile with DHAT in "copy mode". Requires Valgrind 3.17 or later.
344+
- **Purpose**. DHAT's copy mode is good for finding which parts of the code
345+
are causing a lot of memory copies. This is relevant if another profiler
346+
such as `perf-record` or Cachegrind tell you that functions like `memcpy`
347+
or `memmove` are hot (as they often are).
348+
- **Slowdown**. Roughly 5--20x.
349+
- **Configuration**. Same as for DHAT.
350+
- **Output**. Raw output is written to files with a `dhcopy` prefix. Those
351+
files can be viewed with DHAT's viewer (`dh_view.html`).
343352
- `massif`: Profile with
344353
[Massif](http://valgrind.org/docs/manual/ms-manual.html), a heap profiler.
345354
- **Purpose**. Massif is designed to give insight into a program's peak

collector/src/execute.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ pub enum Profiler {
181181
Cachegrind,
182182
Callgrind,
183183
Dhat,
184+
DhatCopy,
184185
Massif,
185186
Eprintln,
186187
LlvmLines,
@@ -221,6 +222,7 @@ impl PerfTool {
221222
| ProfileTool(Cachegrind)
222223
| ProfileTool(Callgrind)
223224
| ProfileTool(Dhat)
225+
| ProfileTool(DhatCopy)
224226
| ProfileTool(Massif)
225227
| ProfileTool(Eprintln)
226228
| ProfileTool(DepGraph)
@@ -256,6 +258,7 @@ impl PerfTool {
256258
| ProfileTool(Cachegrind)
257259
| ProfileTool(Callgrind)
258260
| ProfileTool(Dhat)
261+
| ProfileTool(DhatCopy)
259262
| ProfileTool(Massif)
260263
| ProfileTool(MonoItems)
261264
| ProfileTool(LlvmIr)
@@ -1087,6 +1090,16 @@ impl<'a> Processor for ProfileProcessor<'a> {
10871090
fs::copy(&tmp_dhout_file, &dhout_file)?;
10881091
}
10891092

1093+
// DHAT (in copy mode) produces (via rustc-fake) a data file called
1094+
// `dhcopy`. We copy it from the temp dir to the output dir, giving
1095+
// it a new name in the process.
1096+
Profiler::DhatCopy => {
1097+
let tmp_dhcopy_file = filepath(data.cwd.as_ref(), "dhcopy");
1098+
let dhcopy_file = filepath(self.output_dir, &out_file("dhcopy"));
1099+
1100+
fs::copy(&tmp_dhcopy_file, &dhcopy_file)?;
1101+
}
1102+
10901103
// Massif produces (via rustc-fake) a data file called `msout`. We
10911104
// copy it from the temp dir to the output dir, giving it a new
10921105
// name in the process.

collector/src/rustc-fake.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,21 @@ fn main() {
291291
assert!(cmd.status().expect("failed to spawn").success());
292292
}
293293

294+
"DhatCopy" => {
295+
let mut cmd = Command::new("valgrind");
296+
determinism_env(&mut cmd);
297+
let has_valgrind = cmd.output().is_ok();
298+
assert!(has_valgrind);
299+
cmd.arg("--tool=dhat")
300+
.arg("--mode=copy")
301+
.arg("--num-callers=4")
302+
.arg("--dhat-out-file=dhcopy")
303+
.arg(&tool)
304+
.args(&args);
305+
306+
assert!(cmd.status().expect("failed to spawn").success());
307+
}
308+
294309
"Massif" => {
295310
let mut cmd = Command::new("valgrind");
296311
determinism_env(&mut cmd);

0 commit comments

Comments
 (0)