Skip to content

Commit e6c06fb

Browse files
committed
Implement x perf as a separate tool
1 parent d7c5937 commit e6c06fb

File tree

18 files changed

+1104
-99
lines changed

18 files changed

+1104
-99
lines changed

Cargo.lock

+7
Original file line numberDiff line numberDiff line change
@@ -3453,6 +3453,13 @@ dependencies = [
34533453
"stable_mir",
34543454
]
34553455

3456+
[[package]]
3457+
name = "rustc-perf-wrapper"
3458+
version = "0.1.0"
3459+
dependencies = [
3460+
"clap",
3461+
]
3462+
34563463
[[package]]
34573464
name = "rustc-rayon"
34583465
version = "0.5.0"

Cargo.toml

+1
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 = [

src/bootstrap/src/core/build_steps/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ pub(crate) mod doc;
77
pub(crate) mod format;
88
pub(crate) mod install;
99
pub(crate) mod llvm;
10-
pub(crate) mod perf;
1110
pub(crate) mod run;
1211
pub(crate) mod setup;
1312
pub(crate) mod suggest;

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

-45
This file was deleted.

src/bootstrap/src/core/build_steps/run.rs

+51-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
//! A bit of a hodge-podge as e.g. if a tool's a test fixture it should be in `build_steps::test`.
44
//! If it can be reached from `./x.py run` it can go here.
55
6-
use std::path::PathBuf;
7-
use std::process::Command;
8-
6+
use crate::core::build_steps::compile::{Std, Sysroot};
97
use crate::core::build_steps::dist::distdir;
108
use crate::core::build_steps::test;
11-
use crate::core::build_steps::tool::{self, SourceType, Tool};
9+
use crate::core::build_steps::tool::{self, RustcPerf, SourceType, Tool};
1210
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
1311
use crate::core::config::flags::get_completion;
14-
use crate::core::config::TargetSelection;
12+
use crate::core::config::{DebuginfoLevel, TargetSelection};
1513
use crate::utils::helpers::output;
1614
use crate::Mode;
15+
use std::path::PathBuf;
16+
use std::process::Command;
1717

1818
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
1919
pub struct BuildManifest;
@@ -283,3 +283,49 @@ impl Step for GenerateCompletions {
283283
run.builder.ensure(GenerateCompletions);
284284
}
285285
}
286+
287+
/// Helper wrapper tool for `rustc-perf`, located at `src/tools/rustc-perf-wrapper`.
288+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
289+
pub struct RustfPerfWrapper;
290+
291+
impl Step for RustfPerfWrapper {
292+
type Output = ();
293+
294+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
295+
run.path("src/tools/rustc-perf-wrapper").alias("perf")
296+
}
297+
298+
fn make_run(run: RunConfig<'_>) {
299+
run.builder.ensure(RustfPerfWrapper);
300+
}
301+
302+
fn run(self, builder: &Builder<'_>) {
303+
let collector = builder.ensure(RustcPerf {
304+
compiler: builder.compiler(0, builder.config.build),
305+
target: builder.config.build,
306+
});
307+
308+
if builder.build.config.rust_debuginfo_level_rustc == DebuginfoLevel::None {
309+
builder.info(r#"WARNING: You are compiling rustc without debuginfo, this will make profiling less useful.
310+
Consider setting `rust.debuginfo-level = 1` in `config.toml`."#);
311+
}
312+
313+
let compiler = builder.compiler(builder.top_stage, builder.config.build);
314+
builder.ensure(Std::new(compiler, builder.config.build));
315+
let sysroot = builder.ensure(Sysroot::new(compiler));
316+
let rustc = sysroot.join("bin/rustc");
317+
318+
let rustc_perf_dir = builder.build.tempdir().join("rustc-perf");
319+
let profile_results_dir = rustc_perf_dir.join("results");
320+
321+
// We need to take args passed after `--` and pass them to `rustc-perf-wrapper`
322+
let args = std::env::args().skip_while(|a| a != "--").skip(1);
323+
324+
let mut cmd = builder.tool_cmd(Tool::RustcPerfWrapper);
325+
cmd.env("PERF_RUSTC", rustc)
326+
.env("PERF_COLLECTOR", collector)
327+
.env("PERF_RESULT_DIR", profile_results_dir)
328+
.args(args);
329+
builder.run(&mut cmd);
330+
}
331+
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ bootstrap_tool!(
336336
GenerateWindowsSys, "src/tools/generate-windows-sys", "generate-windows-sys";
337337
RustdocGUITest, "src/tools/rustdoc-gui-test", "rustdoc-gui-test", is_unstable_tool = true, allow_features = "test";
338338
CoverageDump, "src/tools/coverage-dump", "coverage-dump";
339+
RustcPerfWrapper, "src/tools/rustc-perf-wrapper", "rustc-perf-wrapper";
339340
);
340341

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

src/bootstrap/src/core/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,7 @@ impl<'a> Builder<'a> {
959959
run::GenerateCopyright,
960960
run::GenerateWindowsSys,
961961
run::GenerateCompletions,
962+
run::RustfPerfWrapper
962963
),
963964
Kind::Setup => describe!(setup::Profile, setup::Hook, setup::Link, setup::Vscode),
964965
Kind::Clean => describe!(clean::CleanAll, clean::Rustc, clean::Std),
@@ -1036,7 +1037,6 @@ impl<'a> Builder<'a> {
10361037
path.as_ref().map_or([].as_slice(), |path| std::slice::from_ref(path)),
10371038
),
10381039
Subcommand::Vendor { .. } => (Kind::Vendor, &paths[..]),
1039-
Subcommand::Perf { .. } => (Kind::Perf, &paths[..]),
10401040
};
10411041

10421042
Self::new_internal(build, kind, paths.to_owned())

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

+12-4
Original file line numberDiff line numberDiff line change
@@ -2043,17 +2043,26 @@ impl Config {
20432043
Subcommand::Bench { .. } => flags.stage.or(bench_stage).unwrap_or(2),
20442044
Subcommand::Dist { .. } => flags.stage.or(dist_stage).unwrap_or(2),
20452045
Subcommand::Install { .. } => flags.stage.or(install_stage).unwrap_or(2),
2046-
Subcommand::Perf { .. } => flags.stage.unwrap_or(1),
20472046
// These are all bootstrap tools, which don't depend on the compiler.
20482047
// The stage we pass shouldn't matter, but use 0 just in case.
20492048
Subcommand::Clean { .. }
20502049
| Subcommand::Clippy { .. }
20512050
| Subcommand::Fix { .. }
2052-
| Subcommand::Run { .. }
20532051
| Subcommand::Setup { .. }
20542052
| Subcommand::Format { .. }
20552053
| Subcommand::Suggest { .. }
20562054
| Subcommand::Vendor { .. } => flags.stage.unwrap_or(0),
2055+
Subcommand::Run { .. } => {
2056+
// We want to default to stage 1 for this specific tool/command.
2057+
let default = if config.paths.iter().any(|s| {
2058+
s.to_str() == Some("perf") || s.to_str() == Some("src/tools/rustc-perf-wrapper")
2059+
}) {
2060+
1
2061+
} else {
2062+
0
2063+
};
2064+
flags.stage.unwrap_or(default)
2065+
}
20572066
};
20582067

20592068
// CI should always run stage 2 builds, unless it specifically states otherwise
@@ -2081,8 +2090,7 @@ impl Config {
20812090
| Subcommand::Setup { .. }
20822091
| Subcommand::Format { .. }
20832092
| Subcommand::Suggest { .. }
2084-
| Subcommand::Vendor { .. }
2085-
| Subcommand::Perf { .. } => {}
2093+
| Subcommand::Vendor { .. } => {}
20862094
}
20872095
}
20882096

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

-4
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,6 @@ Arguments:
469469
#[arg(long)]
470470
versioned_dirs: bool,
471471
},
472-
/// Perform profiling and benchmarking of the compiler using the
473-
/// `rustc-perf` benchmark suite.
474-
Perf {},
475472
}
476473

477474
impl Subcommand {
@@ -493,7 +490,6 @@ impl Subcommand {
493490
Subcommand::Setup { .. } => Kind::Setup,
494491
Subcommand::Suggest { .. } => Kind::Suggest,
495492
Subcommand::Vendor { .. } => Kind::Vendor,
496-
Subcommand::Perf { .. } => Kind::Perf,
497493
}
498494
}
499495

src/bootstrap/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,6 @@ 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));
664-
}
665662
_ => (),
666663
}
667664

0 commit comments

Comments
 (0)