Skip to content

Commit 5cf01b8

Browse files
committed
Add CLI arguments for x perf
1 parent d4cc01c commit 5cf01b8

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

src/bootstrap/src/core/build_steps/perf.rs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,29 @@ use crate::core::build_steps::tool::RustcPerf;
55
use crate::core::builder::Builder;
66
use crate::core::config::DebuginfoLevel;
77

8+
/// Performs profiling or benchmarking with [`rustc-perf`](https://github.com/rust-lang/rustc-perf)
9+
/// using a locally built compiler.
10+
#[derive(Debug, Clone, clap::Parser)]
11+
pub struct PerfArgs {
12+
#[clap(subcommand)]
13+
cmd: PerfCommand,
14+
}
15+
16+
#[derive(Debug, Clone, clap::Parser)]
17+
enum PerfCommand {
18+
/// Run `profile_local eprintln`.
19+
/// This executes the compiler on the given benchmarks and stores its stderr output.
20+
Eprintln,
21+
}
22+
23+
impl Default for PerfArgs {
24+
fn default() -> Self {
25+
Self { cmd: PerfCommand::Eprintln }
26+
}
27+
}
28+
829
/// Performs profiling using `rustc-perf` on a built version of the compiler.
9-
pub fn perf(builder: &Builder<'_>) {
30+
pub fn perf(builder: &Builder<'_>, args: &PerfArgs) {
1031
let collector = builder.ensure(RustcPerf {
1132
compiler: builder.compiler(0, builder.config.build),
1233
target: builder.config.build,
@@ -25,21 +46,19 @@ Consider setting `rust.debuginfo-level = 1` in `config.toml`."#);
2546
let results_dir = builder.build.tempdir().join("rustc-perf");
2647

2748
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);
49+
match args.cmd {
50+
PerfCommand::Eprintln => {
51+
cmd.arg("profile_local").arg("eprintln");
52+
}
53+
}
54+
cmd.arg("--out-dir").arg(&results_dir).arg("--include").arg("helloworld").arg(&rustc);
3655

3756
builder.info(&format!("Running `rustc-perf` using `{}`", rustc.display()));
3857

3958
// We need to set the working directory to `src/tools/perf`, so that it can find the directory
4059
// with compile-time benchmarks.
4160
let cmd = cmd.current_dir(builder.src.join("src/tools/rustc-perf"));
42-
builder.build.run(cmd);
61+
builder.run(cmd);
4362

4463
builder.info(&format!("You can find the results at `{}`", results_dir.display()));
4564
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::path::{Path, PathBuf};
77

88
use clap::{CommandFactory, Parser, ValueEnum};
99

10+
use crate::core::build_steps::perf::PerfArgs;
1011
use crate::core::build_steps::setup::Profile;
1112
use crate::core::builder::{Builder, Kind};
1213
use crate::core::config::{target_selection_list, Config, TargetSelectionList};
@@ -471,7 +472,7 @@ Arguments:
471472
},
472473
/// Perform profiling and benchmarking of the compiler using the
473474
/// `rustc-perf` benchmark suite.
474-
Perf {},
475+
Perf(PerfArgs),
475476
}
476477

477478
impl Subcommand {

src/bootstrap/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,8 +659,8 @@ impl Build {
659659
Subcommand::Suggest { run } => {
660660
return core::build_steps::suggest::suggest(&builder::Builder::new(self), *run);
661661
}
662-
Subcommand::Perf { .. } => {
663-
return core::build_steps::perf::perf(&builder::Builder::new(self));
662+
Subcommand::Perf(args) => {
663+
return core::build_steps::perf::perf(&builder::Builder::new(self), args);
664664
}
665665
_ => (),
666666
}

0 commit comments

Comments
 (0)