-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #126318 - Kobzol:bootstrap-perf, r=onur-ozkan
Add a `x perf` command for integrating bootstrap with `rustc-perf` This PR adds a new `x perf` command to bootstrap. The idea is to let rustc developers profile (`profile_local`) and benchmark (`bench_local`) a stage1/stage2 compiler directly from within `rust`. Before, if you wanted to use `rustc-perf`, you had to clone it, set it up, copy the `rustc` sysroot after every change to `rust` etc. This is an attempt to automate that. I opened this PR mostly for discussion. My idea is to offer an interface that looks something like this (a random sample of commands): ```bash x perf --stage 2 profile eprintln x perf --stage1 profile cachegrind x perf benchmark --id baseline x perf benchmark --id after-edit x perf cmp baseline after-edit ``` In this PR, I'd like to only implement the simplest case (`profile_local (eprintln)`), because that only requires a single sysroot (you don't compare anything), and it's relatively easy to set up. Also, I'd like to avoid forcing developers to deal with the rustc-perf UI, so more complex use-cases (like benchmarking two sysroots and comparing the results) should probably wait for rust-lang/rustc-perf#1734 (which is hopefully coming along soon-ish). I'm not sure if it's better to do this in bootstrap directly, or if I should create some shim tool that will receive a `rustc` sysroot, and offer a simplified CLI on top of `rustc-perf`. ## Why is a separate CLI needed? We definitely need to add some support to bootstrap to automate preparing `rustc-perf` and the `rustc` sysroot, but in theory after that we could just let people invoke `rustc-perf` manually. While that is definitely possible, you'd need to manually figure out where is your sysroot located, which seems annoying to me. The `rustc-perf` CLI is also relatively complex, and for this use-case it makes sense to only use a subset of it. So I thought that it would be better to offer a simplified interface on top of it that would make life easier for contributors. But maybe it's not worth it. CC `@onur-ozkan`
- Loading branch information
Showing
11 changed files
with
380 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,45 @@ | ||
use std::process::Command; | ||
|
||
use crate::core::build_steps::compile::{Std, Sysroot}; | ||
use crate::core::build_steps::tool::RustcPerf; | ||
use crate::core::builder::Builder; | ||
use crate::core::config::DebuginfoLevel; | ||
|
||
/// Performs profiling using `rustc-perf` on a built version of the compiler. | ||
pub fn perf(builder: &Builder<'_>) { | ||
let collector = builder.ensure(RustcPerf { | ||
compiler: builder.compiler(0, builder.config.build), | ||
target: builder.config.build, | ||
}); | ||
|
||
if builder.build.config.rust_debuginfo_level_rustc == DebuginfoLevel::None { | ||
builder.info(r#"WARNING: You are compiling rustc without debuginfo, this will make profiling less useful. | ||
Consider setting `rust.debuginfo-level = 1` in `config.toml`."#); | ||
} | ||
|
||
let compiler = builder.compiler(builder.top_stage, builder.config.build); | ||
builder.ensure(Std::new(compiler, builder.config.build)); | ||
let sysroot = builder.ensure(Sysroot::new(compiler)); | ||
let rustc = sysroot.join("bin/rustc"); | ||
|
||
let results_dir = builder.build.tempdir().join("rustc-perf"); | ||
|
||
let mut cmd = Command::new(collector); | ||
let cmd = cmd | ||
.arg("profile_local") | ||
.arg("eprintln") | ||
.arg("--out-dir") | ||
.arg(&results_dir) | ||
.arg("--include") | ||
.arg("helloworld") | ||
.arg(&rustc); | ||
|
||
builder.info(&format!("Running `rustc-perf` using `{}`", rustc.display())); | ||
|
||
// We need to set the working directory to `src/tools/perf`, so that it can find the directory | ||
// with compile-time benchmarks. | ||
let cmd = cmd.current_dir(builder.src.join("src/tools/rustc-perf")); | ||
builder.build.run(cmd); | ||
|
||
builder.info(&format!("You can find the results at `{}`", results_dir.display())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.