Skip to content

Commit 6d74ffd

Browse files
authored
Rollup merge of #127002 - Kobzol:bootstrap-perf-tool, r=onur-ozkan
Implement `x perf` as a separate tool Continues work from #126318, adds a CLI for running `rustc-perf` profiling commands through a new `rustc-perf-wrapper` tool. The CLI is in a separate tool to enable experimentation outside of `bootstrap`. This is probably most of what we can do so far, I'll add support for benchmarking once `rustc-perf` gets a terminal output for comparing benchmark results. r? ``@onur-ozkan``
2 parents 6df6879 + 6a2638e commit 6d74ffd

File tree

13 files changed

+212
-25
lines changed

13 files changed

+212
-25
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3461,6 +3461,13 @@ dependencies = [
34613461
"stable_mir",
34623462
]
34633463

3464+
[[package]]
3465+
name = "rustc-perf-wrapper"
3466+
version = "0.1.0"
3467+
dependencies = [
3468+
"clap",
3469+
]
3470+
34643471
[[package]]
34653472
name = "rustc-rayon"
34663473
version = "0.5.0"

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ members = [
4444
"src/tools/rustdoc-gui-test",
4545
"src/tools/opt-dist",
4646
"src/tools/coverage-dump",
47+
"src/tools/rustc-perf-wrapper",
4748
]
4849

4950
exclude = [
Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
use std::process::Command;
2-
31
use crate::core::build_steps::compile::{Std, Sysroot};
4-
use crate::core::build_steps::tool::RustcPerf;
2+
use crate::core::build_steps::tool::{RustcPerf, Tool};
53
use crate::core::builder::Builder;
64
use crate::core::config::DebuginfoLevel;
75

@@ -22,24 +20,16 @@ Consider setting `rust.debuginfo-level = 1` in `config.toml`."#);
2220
let sysroot = builder.ensure(Sysroot::new(compiler));
2321
let rustc = sysroot.join("bin/rustc");
2422

25-
let results_dir = builder.build.tempdir().join("rustc-perf");
26-
27-
let mut cmd = Command::new(collector);
28-
let cmd = cmd
29-
.arg("profile_local")
30-
.arg("eprintln")
31-
.arg("--out-dir")
32-
.arg(&results_dir)
33-
.arg("--include")
34-
.arg("helloworld")
35-
.arg(&rustc);
36-
37-
builder.info(&format!("Running `rustc-perf` using `{}`", rustc.display()));
23+
let rustc_perf_dir = builder.build.tempdir().join("rustc-perf");
24+
let profile_results_dir = rustc_perf_dir.join("results");
3825

39-
// We need to set the working directory to `src/tools/perf`, so that it can find the directory
40-
// with compile-time benchmarks.
41-
let cmd = cmd.current_dir(builder.src.join("src/tools/rustc-perf"));
42-
builder.build.run(cmd);
26+
// We need to take args passed after `--` and pass them to `rustc-perf-wrapper`
27+
let args = std::env::args().skip_while(|a| a != "--").skip(1);
4328

44-
builder.info(&format!("You can find the results at `{}`", results_dir.display()));
29+
let mut cmd = builder.tool_cmd(Tool::RustcPerfWrapper);
30+
cmd.env("RUSTC_REAL", rustc)
31+
.env("PERF_COLLECTOR", collector)
32+
.env("PERF_RESULT_DIR", profile_results_dir)
33+
.args(args);
34+
builder.run(&mut cmd);
4535
}

src/bootstrap/src/core/build_steps/tool.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ bootstrap_tool!(
337337
GenerateWindowsSys, "src/tools/generate-windows-sys", "generate-windows-sys";
338338
RustdocGUITest, "src/tools/rustdoc-gui-test", "rustdoc-gui-test", is_unstable_tool = true, allow_features = "test";
339339
CoverageDump, "src/tools/coverage-dump", "coverage-dump";
340+
RustcPerfWrapper, "src/tools/rustc-perf-wrapper", "rustc-perf-wrapper";
340341
);
341342

342343
#[derive(Debug, Clone, Hash, PartialEq, Eq)]

src/bootstrap/src/core/config/flags.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,9 @@ Arguments:
470470
versioned_dirs: bool,
471471
},
472472
/// Perform profiling and benchmarking of the compiler using the
473-
/// `rustc-perf` benchmark suite.
473+
/// `rustc-perf-wrapper` tool.
474+
///
475+
/// You need to pass arguments after `--`, e.g.`x perf -- cachegrind`.
474476
Perf {},
475477
}
476478

src/etc/completions/x.py.fish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ complete -c x.py -n "__fish_use_subcommand" -f -a "run" -d 'Run tools contained
4848
complete -c x.py -n "__fish_use_subcommand" -f -a "setup" -d 'Set up the environment for development'
4949
complete -c x.py -n "__fish_use_subcommand" -f -a "suggest" -d 'Suggest a subset of tests to run, based on modified files'
5050
complete -c x.py -n "__fish_use_subcommand" -f -a "vendor" -d 'Vendor dependencies'
51-
complete -c x.py -n "__fish_use_subcommand" -f -a "perf" -d 'Perform profiling and benchmarking of the compiler using the `rustc-perf` benchmark suite'
51+
complete -c x.py -n "__fish_use_subcommand" -f -a "perf" -d 'Perform profiling and benchmarking of the compiler using the `rustc-perf-wrapper` tool'
5252
complete -c x.py -n "__fish_seen_subcommand_from build" -l config -d 'TOML configuration file for build' -r -F
5353
complete -c x.py -n "__fish_seen_subcommand_from build" -l build-dir -d 'Build directory, overrides `build.build-dir` in `config.toml`' -r -f -a "(__fish_complete_directories)"
5454
complete -c x.py -n "__fish_seen_subcommand_from build" -l build -d 'build target of the stage0 compiler' -r -f

src/etc/completions/x.py.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Register-ArgumentCompleter -Native -CommandName 'x.py' -ScriptBlock {
7575
[CompletionResult]::new('setup', 'setup', [CompletionResultType]::ParameterValue, 'Set up the environment for development')
7676
[CompletionResult]::new('suggest', 'suggest', [CompletionResultType]::ParameterValue, 'Suggest a subset of tests to run, based on modified files')
7777
[CompletionResult]::new('vendor', 'vendor', [CompletionResultType]::ParameterValue, 'Vendor dependencies')
78-
[CompletionResult]::new('perf', 'perf', [CompletionResultType]::ParameterValue, 'Perform profiling and benchmarking of the compiler using the `rustc-perf` benchmark suite')
78+
[CompletionResult]::new('perf', 'perf', [CompletionResultType]::ParameterValue, 'Perform profiling and benchmarking of the compiler using the `rustc-perf-wrapper` tool')
7979
break
8080
}
8181
'x.py;build' {

src/etc/completions/x.py.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ _x.py_commands() {
856856
'setup:Set up the environment for development' \
857857
'suggest:Suggest a subset of tests to run, based on modified files' \
858858
'vendor:Vendor dependencies' \
859-
'perf:Perform profiling and benchmarking of the compiler using the \`rustc-perf\` benchmark suite' \
859+
'perf:Perform profiling and benchmarking of the compiler using the \`rustc-perf-wrapper\` tool' \
860860
)
861861
_describe -t commands 'x.py commands' commands "$@"
862862
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "rustc-perf-wrapper"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
clap = { version = "4.5.7", features = ["derive", "env"] }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# rustc-perf wrapper
2+
Utility tool for invoking [`rustc-perf`](https://github.com/rust-lang/rustc-perf) for benchmarking/profiling
3+
a stage1/2 compiler built by bootstrap using `x perf -- <command>`.

0 commit comments

Comments
 (0)