Skip to content

Commit 152350a

Browse files
authored
Merge pull request #1411 from rust-lang/bytehound
Add bytehound profiler
2 parents 7a21139 + aae7fd9 commit 152350a

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ jobs:
137137
sudo apt-get install -y valgrind
138138
cargo install --version 0.4.12 cargo-llvm-lines
139139
140+
- name: Install Bytehound
141+
run: |
142+
git clone https://github.com/koute/bytehound
143+
cd bytehound
144+
cargo build --release -p bytehound-preload
145+
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${PWD}/target/release" >> $GITHUB_ENV
146+
140147
- name: Configure environment
141148
run: |
142149
sudo apt-get install -y linux-tools-common linux-tools-generic linux-tools-`uname -r`

ci/check-profiling.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ RUST_BACKTRACE=1 RUST_LOG=raw_cargo_messages=trace,collector=debug,rust_sysroot=
118118
test -f results/msout-Test-helloworld-Check-Full
119119
grep -q "snapshot=0" results/msout-Test-helloworld-Check-Full
120120

121+
# Bytehound.
122+
RUST_BACKTRACE=1 RUST_LOG=raw_cargo_messages=trace,collector=debug,rust_sysroot=debug \
123+
cargo run -p collector --bin collector -- \
124+
profile_local bytehound $bindir/rustc \
125+
--id Test \
126+
--profiles Check \
127+
--cargo $bindir/cargo \
128+
--include helloworld \
129+
--scenarios Full
130+
test -f results/bhout-Test-helloworld-Check-Full
131+
121132
# eprintln. The output file is empty because a vanilla rustc doesn't print
122133
# anything to stderr.
123134
RUST_BACKTRACE=1 RUST_LOG=raw_cargo_messages=trace,collector=debug,rust_sysroot=debug \

collector/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ might be optimized.
230230
### Preparation
231231

232232
If you are going to use any of the profilers that rely on line numbers
233-
(OProfile, Cachegrind, Callgrind, DHAT, or Massif) use the following
233+
(OProfile, Cachegrind, Callgrind, DHAT, Massif or Bytehound) use the following
234234
`config.toml` file for your local build.
235235
```
236236
[llvm]
@@ -363,6 +363,14 @@ The mandatory `<PROFILER>` argument must be one of the following.
363363
[`massif-visualizer`](https://github.com/KDE/massif-visualizer); the latter
364364
is recommended, though it sometimes fails to read output files that
365365
`ms_print` can handle.
366+
- `bytehound`: Profile with
367+
[Bytehound](https://github.com/koute/bytehound), a memory profiler. You must add the
368+
directory containing `libbytehound.so` to the `LD_LIBRARY_PATH` environment variable
369+
when you use this profiler.
370+
- **Purpose**. Bytehound is designed to give insight into a program's memory usage.
371+
- **Slowdown**. Roughly 2--4x.
372+
- **Output**. Raw output is written to files with a `bytehound` prefix. Those
373+
files can be viewed with the `bytehound server <filename>` command.
366374
- `eprintln`: Profile with `eprintln!` statements.
367375
- **Purpose**. Sometimes it is useful to do ad hoc profiling by inserting
368376
`eprintln!` statements into rustc, e.g. to count how often particular paths

collector/src/execute.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ pub enum Profiler {
170170
Dhat,
171171
DhatCopy,
172172
Massif,
173+
Bytehound,
173174
Eprintln,
174175
LlvmLines,
175176
MonoItems,
@@ -187,6 +188,8 @@ impl Profiler {
187188
| Profiler::Callgrind
188189
| Profiler::Dhat
189190
| Profiler::DhatCopy
191+
| Profiler::Massif
192+
| Profiler::Bytehound
190193
| Profiler::Eprintln
191194
| Profiler::LlvmLines
192195
| Profiler::LlvmIr
@@ -230,6 +233,7 @@ impl PerfTool {
230233
| ProfileTool(Dhat)
231234
| ProfileTool(DhatCopy)
232235
| ProfileTool(Massif)
236+
| ProfileTool(Bytehound)
233237
| ProfileTool(Eprintln)
234238
| ProfileTool(DepGraph)
235239
| ProfileTool(MonoItems)
@@ -266,6 +270,7 @@ impl PerfTool {
266270
| ProfileTool(Dhat)
267271
| ProfileTool(DhatCopy)
268272
| ProfileTool(Massif)
273+
| ProfileTool(Bytehound)
269274
| ProfileTool(MonoItems)
270275
| ProfileTool(LlvmIr)
271276
| ProfileTool(Eprintln) => true,
@@ -1132,6 +1137,15 @@ impl<'a> Processor for ProfileProcessor<'a> {
11321137
fs::copy(&tmp_msout_file, &msout_file)?;
11331138
}
11341139

1140+
// Bytehound produces (via rustc-fake) a data file called
1141+
// `bytehound.dat`. We copy it from the temp dir to the output dir, giving
1142+
// it a new name in the process.
1143+
Profiler::Bytehound => {
1144+
let tmp_bytehound_file = filepath(data.cwd.as_ref(), "bytehound.dat");
1145+
let target_file = filepath(self.output_dir, &out_file("bhout"));
1146+
fs::copy(tmp_bytehound_file, target_file)?;
1147+
}
1148+
11351149
// `eprintln!` statements are redirected (via rustc-fake) to a file
11361150
// called `eprintln`. We copy it from the temp dir to the output
11371151
// dir, giving it a new name in the process.

collector/src/rustc-fake.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,15 @@ fn main() {
325325
run_with_determinism_env(cmd);
326326
}
327327

328+
"Bytehound" => {
329+
let mut cmd = Command::new(tool);
330+
cmd.args(args);
331+
cmd.env("MEMORY_PROFILER_OUTPUT", "bytehound.dat");
332+
cmd.env("LD_PRELOAD", "libbytehound.so");
333+
334+
run_with_determinism_env(cmd);
335+
}
336+
328337
"Eprintln" => {
329338
let mut cmd = Command::new(tool);
330339
cmd.args(args).stderr(std::process::Stdio::from(

0 commit comments

Comments
 (0)