Skip to content

Commit 3c67e79

Browse files
Make rustdoc optional for local profiling
1 parent f3c3a30 commit 3c67e79

File tree

2 files changed

+41
-20
lines changed

2 files changed

+41
-20
lines changed

collector/src/bin/rustc-perf-collector/execute.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,17 @@ impl Profiler {
158158
| Profiler::Callgrind
159159
| Profiler::DHAT
160160
| Profiler::Massif
161-
| Profiler::Eprintln => if build_kind == BuildKind::Doc {
161+
| Profiler::Eprintln => {
162+
if build_kind == BuildKind::Doc {
162163
Some("rustdoc")
163164
} else {
164165
Some("rustc")
165-
},
166+
}
167+
}
166168
Profiler::LlvmLines => match build_kind {
167169
BuildKind::Debug | BuildKind::Opt => Some("rustc"),
168170
BuildKind::Check | BuildKind::Doc => None,
169-
}
171+
},
170172
}
171173
}
172174

@@ -223,9 +225,7 @@ impl<'a> CargoProcess<'a> {
223225
// Not all cargo invocations (e.g. `cargo clean`) need all of these
224226
// env vars set, but it doesn't hurt to have them.
225227
.env("RUSTC", &*FAKE_RUSTC)
226-
.env("RUSTDOC", &*FAKE_RUSTDOC)
227228
.env("RUSTC_REAL", &self.compiler.rustc)
228-
.env("RUSTDOC_REAL", &self.compiler.rustdoc)
229229
.env(
230230
"CARGO_INCREMENTAL",
231231
&format!("{}", self.incremental as usize),
@@ -234,6 +234,10 @@ impl<'a> CargoProcess<'a> {
234234
.arg(subcommand)
235235
.arg("--manifest-path")
236236
.arg(&self.manifest_path);
237+
238+
if let Some(r) = &self.compiler.rustdoc {
239+
cmd.env("RUSTDOC", &*FAKE_RUSTDOC).env("RUSTDOC_REAL", r);
240+
}
237241
cmd
238242
}
239243

@@ -263,10 +267,12 @@ impl<'a> CargoProcess<'a> {
263267
}
264268

265269
match profiler.subcommand(self.build_kind) {
266-
None => return Err(anyhow::anyhow!(
267-
"this profiler doesn't support {:?} builds",
268-
self.build_kind
269-
)),
270+
None => {
271+
return Err(anyhow::anyhow!(
272+
"this profiler doesn't support {:?} builds",
273+
self.build_kind
274+
))
275+
}
270276
Some(sub) => sub,
271277
}
272278
} else {

collector/src/bin/rustc-perf-collector/main.rs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use sysroot::Sysroot;
2929
#[derive(Debug, Copy, Clone)]
3030
pub struct Compiler<'a> {
3131
pub rustc: &'a Path,
32-
pub rustdoc: &'a Path,
32+
pub rustdoc: Option<&'a Path>,
3333
pub cargo: &'a Path,
3434
pub triple: &'a str,
3535
pub is_nightly: bool,
@@ -39,7 +39,7 @@ impl<'a> Compiler<'a> {
3939
fn from_sysroot(sysroot: &'a Sysroot) -> Compiler<'a> {
4040
Compiler {
4141
rustc: &sysroot.rustc,
42-
rustdoc: &sysroot.rustdoc,
42+
rustdoc: Some(&sysroot.rustdoc),
4343
cargo: &sysroot.cargo,
4444
triple: &sysroot.triple,
4545
is_nightly: true,
@@ -239,6 +239,11 @@ fn bench_commit(
239239
call_home: bool,
240240
self_profile: bool,
241241
) -> BenchmarkErrors {
242+
if compiler.rustdoc.is_none() && build_kinds.iter().any(|b| *b == BuildKind::Doc) {
243+
eprintln!("Rustdoc build specified but rustdoc path not provided");
244+
std::process::exit(1);
245+
}
246+
242247
let mut errors_recorded = 0;
243248
eprintln!("Benchmarking {} for triple {}", cid, compiler.triple);
244249

@@ -332,7 +337,8 @@ fn get_benchmarks(
332337
) -> anyhow::Result<Vec<Benchmark>> {
333338
let mut benchmarks = Vec::new();
334339
'outer: for entry in fs::read_dir(benchmark_dir)
335-
.with_context(|| format!("failed to list benchmark dir {}", benchmark_dir.display()))? {
340+
.with_context(|| format!("failed to list benchmark dir {}", benchmark_dir.display()))?
341+
{
336342
let entry = entry?;
337343
let path = entry.path();
338344
let name = match entry.file_name().into_string() {
@@ -410,7 +416,7 @@ fn main_result() -> anyhow::Result<i32> {
410416
(@subcommand bench_local =>
411417
(about: "benchmark a local rustc")
412418
(@arg RUSTC: --rustc +required +takes_value "The path to the local rustc to benchmark")
413-
(@arg RUSTDOC: --rustdoc +required +takes_value "The path to the local rustdoc to benchmark")
419+
(@arg RUSTDOC: --rustdoc +takes_value "The path to the local rustdoc to benchmark")
414420
(@arg CARGO: --cargo +required +takes_value "The path to the local Cargo to use")
415421
(@arg BUILDS: --builds +takes_value
416422
"One or more (comma-separated) of: 'Check', 'Debug',\n\
@@ -431,6 +437,7 @@ fn main_result() -> anyhow::Result<i32> {
431437
(about: "profile a local rustc")
432438
(@arg output_dir: --("output") +required +takes_value "Output directory")
433439
(@arg RUSTC: --rustc +required +takes_value "The path to the local rustc to benchmark")
440+
(@arg RUSTDOC: --rustdoc +takes_value "The path to the local rustdoc to benchmark")
434441
(@arg CARGO: --cargo +required +takes_value "The path to the local Cargo to use")
435442
(@arg BUILDS: --builds +takes_value
436443
"One or more (comma-separated) of: 'Check', 'Debug',\n\
@@ -498,14 +505,18 @@ fn main_result() -> anyhow::Result<i32> {
498505

499506
("bench_local", Some(sub_m)) => {
500507
let rustc = sub_m.value_of("RUSTC").unwrap();
501-
let rustdoc = sub_m.value_of("RUSTDOC").unwrap();
508+
let rustdoc = sub_m.value_of("RUSTDOC");
502509
let cargo = sub_m.value_of("CARGO").unwrap();
503510
let build_kinds = build_kinds_from_arg(&sub_m.value_of("BUILDS"))?;
504511
let run_kinds = run_kinds_from_arg(&sub_m.value_of("RUNS"))?;
505512
let id = sub_m.value_of("ID").unwrap();
506513

507514
let rustc_path = PathBuf::from(rustc).canonicalize()?;
508-
let rustdoc_path = PathBuf::from(rustdoc).canonicalize()?;
515+
let rustdoc_path = if let Some(r) = rustdoc {
516+
Some(PathBuf::from(r).canonicalize()?)
517+
} else {
518+
None
519+
};
509520
let cargo_path = PathBuf::from(cargo).canonicalize()?;
510521
let conn = rt.block_on(pool.expect("--db passed").connection());
511522
bench_commit(
@@ -516,7 +527,7 @@ fn main_result() -> anyhow::Result<i32> {
516527
&run_kinds,
517528
Compiler {
518529
rustc: &rustc_path,
519-
rustdoc: &rustdoc_path,
530+
rustdoc: rustdoc_path.as_deref(),
520531
cargo: &cargo_path,
521532
triple: "x86_64-unknown-linux-gnu",
522533
is_nightly: true,
@@ -573,7 +584,7 @@ fn main_result() -> anyhow::Result<i32> {
573584
&run_kinds,
574585
Compiler {
575586
rustc: Path::new(rustc.trim()),
576-
rustdoc: Path::new(rustdoc.trim()),
587+
rustdoc: Some(Path::new(rustdoc.trim())),
577588
cargo: Path::new(cargo.trim()),
578589
is_nightly: false,
579590
triple: "x86_64-unknown-linux-gnu",
@@ -598,7 +609,7 @@ fn main_result() -> anyhow::Result<i32> {
598609

599610
("profile", Some(sub_m)) => {
600611
let rustc = sub_m.value_of("RUSTC").unwrap();
601-
let rustdoc = sub_m.value_of("RUSTDOC").unwrap();
612+
let rustdoc = sub_m.value_of("RUSTDOC");
602613
let cargo = sub_m.value_of("CARGO").unwrap();
603614
let build_kinds = build_kinds_from_arg(&sub_m.value_of("BUILDS"))?;
604615
let run_kinds = run_kinds_from_arg(&sub_m.value_of("RUNS"))?;
@@ -609,11 +620,15 @@ fn main_result() -> anyhow::Result<i32> {
609620
eprintln!("Profiling with {:?}", profiler);
610621

611622
let rustc_path = PathBuf::from(rustc).canonicalize()?;
612-
let rustdoc_path = PathBuf::from(rustdoc).canonicalize()?;
623+
let rustdoc_path = if let Some(r) = rustdoc {
624+
Some(PathBuf::from(r).canonicalize()?)
625+
} else {
626+
None
627+
};
613628
let cargo_path = PathBuf::from(cargo).canonicalize()?;
614629
let compiler = Compiler {
615630
rustc: &rustc_path,
616-
rustdoc: &rustdoc_path,
631+
rustdoc: rustdoc_path.as_deref(),
617632
cargo: &cargo_path,
618633
is_nightly: true,
619634
triple: "x86_64-unknown-linux-gnu", // XXX: Technically not necessarily true

0 commit comments

Comments
 (0)