Skip to content

Commit e4eded3

Browse files
authored
Document bootstrap integration with rustc-perf (rust-lang#2005)
1 parent ab71898 commit e4eded3

File tree

4 files changed

+49
-31
lines changed

4 files changed

+49
-31
lines changed

src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
- [Profiling the compiler](./profiling.md)
3737
- [with the linux perf tool](./profiling/with_perf.md)
3838
- [with Windows Performance Analyzer](./profiling/wpa_profiling.md)
39+
- [with the Rust benchmark suite](./profiling/with_rustc_perf.md)
3940
- [crates.io Dependencies](./crates-io.md)
4041

4142
# Contributing to Rust

src/profiling/with_perf.md

+8-31
Original file line numberDiff line numberDiff line change
@@ -54,46 +54,23 @@ you made in the beginning. But there are some things to be aware of:
5454

5555
### Gathering a perf profile from a `perf.rust-lang.org` test
5656

57-
Often we want to analyze a specific test from `perf.rust-lang.org`. To
58-
do that, the first step is to clone
59-
[the rustc-perf repository][rustc-perf-gh]:
57+
Often we want to analyze a specific test from `perf.rust-lang.org`.
58+
The easiest way to do that is to use the [rustc-perf][rustc-perf]
59+
benchmarking suite, this approach is described [here](with_rustc_perf.md).
6060

61-
```bash
62-
git clone https://github.com/rust-lang/rustc-perf
63-
```
64-
65-
[rustc-perf-gh]: https://github.com/rust-lang/rustc-perf
66-
67-
#### Doing it the easy way
68-
69-
Once you've cloned the repo, you can use the `collector` executable to
70-
do profiling for you! You can find
71-
[instructions in the rustc-perf readme][rustc-perf-readme].
72-
73-
[rustc-perf-readme]: https://github.com/rust-lang/rustc-perf/blob/master/collector/README.md#profiling
74-
75-
For example, to measure the clap-rs test, you might do:
61+
Instead of using the benchmark suite CLI, you can also profile the benchmarks manually. First,
62+
you need to clone the [rustc-perf][rustc-perf] repository:
7663

7764
```bash
78-
./target/release/collector \
79-
--output-repo /path/to/place/output \
80-
profile perf-record \
81-
--rustc /path/to/rustc/executable/from/your/build/directory \
82-
--cargo `which cargo` \
83-
--filter clap-rs \
84-
--builds Check \
65+
$ git clone https://github.com/rust-lang/rustc-perf
8566
```
8667

87-
You can also use that same command to use cachegrind or other profiling tools.
88-
89-
#### Doing it the hard way
90-
91-
If you prefer to run things manually, that is also possible. You first
92-
need to find the source for the test you want. Sources for the tests
68+
and then find the source code of the test that you want to profile. Sources for the tests
9369
are found in [the `collector/compile-benchmarks` directory][compile-time dir]
9470
and [the `collector/runtime-benchmarks` directory][runtime dir]. So let's
9571
go into the directory of a specific test; we'll use `clap-rs` as an example:
9672

73+
[rustc-perf]: https://github.com/rust-lang/rustc-perf
9774
[compile-time dir]: https://github.com/rust-lang/rustc-perf/tree/master/collector/compile-benchmarks
9875
[runtime dir]: https://github.com/rust-lang/rustc-perf/tree/master/collector/runtime-benchmarks
9976

src/profiling/with_rustc_perf.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Profiling with rustc-perf
2+
3+
The [Rust benchmark suite][rustc-perf] provides a comprehensive way of profiling and benchmarking
4+
the Rust compiler. You can find instructions on how to use the suite in its [manual][rustc-perf-readme].
5+
6+
However, using the suite manually can be a bit cumbersome. To make this easier for `rustc` contributors,
7+
the compiler build system (`bootstrap`) also provides built-in integration with the benchmarking suite,
8+
which will download and build the suite for you, build a local compiler toolchain and let you profile it using a simplified command-line interface.
9+
10+
You can use the `./x perf -- <command> [options]` command to use this integration.
11+
12+
> Note that you need to specify arguments after `--` in the `x perf` command! You will not be able to pass arguments without the double dashes.
13+
14+
You can use normal bootstrap flags for this command, such as `--stage 1` or `--stage 2`, for example to modify the stage of the created sysroot. It might also be useful to configure `config.toml` to better support profiling, e.g. set `rust.debuginfo-level = 1` to add source line information to the built compiler.
15+
16+
`x perf` currently supports the following commands:
17+
- `benchmark <id>`: Benchmark the compiler and store the results under the passed `id`.
18+
- `compare <baseline> <modified>`: Compare the benchmark results of two compilers with the two passed `id`s.
19+
- `eprintln`: Just run the compiler and capture its `stderr` output. Note that the compiler normally does not print
20+
anything to `stderr`, you might want to add some `eprintln!` calls to get any output.
21+
- `samply`: Profile the compiler using the [samply][samply] sampling profiler.
22+
- `cachegrind`: Use [Cachegrind][cachegrind] to generate a detailed simulated trace of the compiler's execution.
23+
24+
> You can find a more detailed description of the profilers in the [`rustc-perf` manual][rustc-perf-readme-profilers].
25+
26+
You can use the following options for the `x perf` command, which mirror the corresponding options of the
27+
`profile_local` and `bench_local` commands that you can use in the suite:
28+
29+
- `--include`: Select benchmarks which should be profiled/benchmarked.
30+
- `--profiles`: Select profiles (`Check`, `Debug`, `Opt`, `Doc`) which should be profiled/benchmarked.
31+
- `--scenarios`: Select scenarios (`Full`, `IncrFull`, `IncrPatched`, `IncrUnchanged`) which should be profiled/benchmarked.
32+
33+
[samply]: https://github.com/mstange/samply
34+
[cachegrind]: https://www.cs.cmu.edu/afs/cs.cmu.edu/project/cmt-40/Nice/RuleRefinement/bin/valgrind-3.2.0/docs/html/cg-manual.html
35+
[rustc-perf]: https://github.com/rust-lang/rustc-perf
36+
[rustc-perf-readme]: https://github.com/rust-lang/rustc-perf/blob/master/collector/README.md
37+
[rustc-perf-readme-profilers]: https://github.com/rust-lang/rustc-perf/blob/master/collector/README.md#profiling-local-builds

src/tests/perf.md

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ configurations include "fresh builds", builds with incremental compilation, etc.
1717
The result of a perf run is a comparison between two versions of the compiler
1818
(by their commit hashes).
1919

20+
You can also use `rustc-perf` to manually benchmark and profile the compiler
21+
[locally](../profiling/with_rustc_perf.md).
22+
2023
### Automatic perf runs
2124

2225
After every PR is merged, a suite of benchmarks are run against the compiler.

0 commit comments

Comments
 (0)