Skip to content

Commit 264d20f

Browse files
Merge pull request #675 from jyn514/rustdoc
Add benchmarks for rustdoc
2 parents 7c168f1 + 3c67e79 commit 264d20f

File tree

7 files changed

+145
-75
lines changed

7 files changed

+145
-75
lines changed

collector/src/bin/rustc-fake.rs

+22-12
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@ use std::process::Command;
44
use std::time::{Duration, Instant};
55

66
fn main() {
7-
let mut args = env::args_os().skip(1).collect::<Vec<_>>();
7+
let mut args_os = env::args_os();
8+
let name = args_os.next().unwrap().into_string().unwrap();
9+
10+
let mut args = args_os.collect::<Vec<_>>();
811
let rustc = env::var_os("RUSTC_REAL").unwrap();
12+
let rustdoc = env::var_os("RUSTDOC_REAL").unwrap();
13+
let actually_rustdoc = name.ends_with("rustdoc-fake");
14+
let tool = if actually_rustdoc {
15+
rustdoc
16+
} else {
17+
rustc
18+
};
919

1020
if let Some(count) = env::var("RUSTC_THREAD_COUNT")
1121
.ok()
@@ -36,7 +46,7 @@ fn main() {
3646
.arg("instructions:u,cycles:u,task-clock,cpu-clock,faults")
3747
.arg("--log-fd")
3848
.arg("1")
39-
.arg(&rustc)
49+
.arg(&tool)
4050
.args(&args);
4151

4252
let prof_out_dir = std::env::current_dir().unwrap().join("self-profile-output");
@@ -91,14 +101,14 @@ fn main() {
91101
}
92102

93103
"self-profile" => {
94-
let mut cmd = Command::new(&rustc);
104+
let mut cmd = Command::new(&tool);
95105
cmd.arg("-Zself-profile=Zsp").args(&args);
96106

97107
assert!(cmd.status().expect("failed to spawn").success());
98108
}
99109

100110
"time-passes" => {
101-
let mut cmd = Command::new(&rustc);
111+
let mut cmd = Command::new(&tool);
102112
cmd.arg("-Ztime-passes").args(&args);
103113

104114
assert!(cmd.status().expect("failed to spawn").success());
@@ -113,7 +123,7 @@ fn main() {
113123
.arg("--output=perf")
114124
.arg("--freq=299")
115125
.arg("--event=cycles:u,instructions:u")
116-
.arg(&rustc)
126+
.arg(&tool)
117127
.args(&args);
118128

119129
assert!(cmd.status().expect("failed to spawn").success());
@@ -124,7 +134,7 @@ fn main() {
124134
let has_oprofile = cmd.output().is_ok();
125135
assert!(has_oprofile);
126136
// Other possibly useful args: --callgraph, --separate-thread
127-
cmd.arg("operf").arg(&rustc).args(&args);
137+
cmd.arg("operf").arg(&tool).args(&args);
128138

129139
assert!(cmd.status().expect("failed to spawn").success());
130140
}
@@ -140,7 +150,7 @@ fn main() {
140150
.arg("--cache-sim=no")
141151
.arg("--branch-sim=no")
142152
.arg("--cachegrind-out-file=cgout")
143-
.arg(&rustc)
153+
.arg(&tool)
144154
.args(&args);
145155

146156
assert!(cmd.status().expect("failed to spawn").success());
@@ -157,7 +167,7 @@ fn main() {
157167
.arg("--cache-sim=no")
158168
.arg("--branch-sim=no")
159169
.arg("--callgrind-out-file=clgout")
160-
.arg(&rustc)
170+
.arg(&tool)
161171
.args(&args);
162172

163173
assert!(cmd.status().expect("failed to spawn").success());
@@ -170,7 +180,7 @@ fn main() {
170180
cmd.arg("--tool=dhat")
171181
.arg("--num-callers=4")
172182
.arg("--dhat-out-file=dhout")
173-
.arg(&rustc)
183+
.arg(&tool)
174184
.args(&args);
175185

176186
assert!(cmd.status().expect("failed to spawn").success());
@@ -186,14 +196,14 @@ fn main() {
186196
.arg("--threshold=0.2")
187197
.arg("--massif-out-file=msout")
188198
.arg("--alloc-fn=__rdl_alloc")
189-
.arg(&rustc)
199+
.arg(&tool)
190200
.args(&args);
191201

192202
assert!(cmd.status().expect("failed to spawn").success());
193203
}
194204

195205
"eprintln" | "llvm-lines" => {
196-
let mut cmd = Command::new(&rustc);
206+
let mut cmd = Command::new(&tool);
197207
cmd.args(&args);
198208

199209
assert!(cmd.status().expect("failed to spawn").success());
@@ -204,7 +214,7 @@ fn main() {
204214
}
205215
}
206216
} else {
207-
let mut cmd = Command::new(&rustc);
217+
let mut cmd = Command::new(&tool);
208218
cmd.args(&args);
209219
exec(&mut cmd);
210220
}

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

+44-28
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl Profiler {
146146

147147
// What cargo subcommand do we need to run for this profiler? If not
148148
// `rustc`, must be a subcommand that itself invokes `rustc`.
149-
fn subcommand(&self) -> &'static str {
149+
fn subcommand(&self, build_kind: BuildKind) -> Option<&'static str> {
150150
match self {
151151
Profiler::PerfStat
152152
| Profiler::PerfStatSelfProfile
@@ -158,25 +158,17 @@ impl Profiler {
158158
| Profiler::Callgrind
159159
| Profiler::DHAT
160160
| Profiler::Massif
161-
| Profiler::Eprintln => "rustc",
162-
Profiler::LlvmLines => "llvm-lines",
163-
}
164-
}
165-
166-
fn is_build_kind_allowed(&self, build_kind: BuildKind) -> bool {
167-
match self {
168-
Profiler::PerfStat
169-
| Profiler::PerfStatSelfProfile
170-
| Profiler::SelfProfile
171-
| Profiler::TimePasses
172-
| Profiler::PerfRecord
173-
| Profiler::OProfile
174-
| Profiler::Cachegrind
175-
| Profiler::Callgrind
176-
| Profiler::DHAT
177-
| Profiler::Massif
178-
| Profiler::Eprintln => true,
179-
Profiler::LlvmLines => build_kind != BuildKind::Check,
161+
| Profiler::Eprintln => {
162+
if build_kind == BuildKind::Doc {
163+
Some("rustdoc")
164+
} else {
165+
Some("rustc")
166+
}
167+
}
168+
Profiler::LlvmLines => match build_kind {
169+
BuildKind::Debug | BuildKind::Opt => Some("rustc"),
170+
BuildKind::Check | BuildKind::Doc => None,
171+
},
180172
}
181173
}
182174

@@ -242,6 +234,10 @@ impl<'a> CargoProcess<'a> {
242234
.arg(subcommand)
243235
.arg("--manifest-path")
244236
.arg(&self.manifest_path);
237+
238+
if let Some(r) = &self.compiler.rustdoc {
239+
cmd.env("RUSTDOC", &*FAKE_RUSTDOC).env("RUSTDOC_REAL", r);
240+
}
245241
cmd
246242
}
247243

@@ -263,20 +259,22 @@ impl<'a> CargoProcess<'a> {
263259
// machinery works).
264260
let subcommand = if let Some((ref mut processor, run_kind, ..)) = self.processor_etc {
265261
let profiler = processor.profiler();
266-
if !profiler.is_build_kind_allowed(self.build_kind) {
267-
return Err(anyhow::anyhow!(
268-
"this profiler doesn't support {:?} builds",
269-
self.build_kind
270-
));
271-
}
272262
if !profiler.is_run_kind_allowed(run_kind) {
273263
return Err(anyhow::anyhow!(
274264
"this profiler doesn't support {:?} runs",
275265
run_kind
276266
));
277267
}
278268

279-
profiler.subcommand()
269+
match profiler.subcommand(self.build_kind) {
270+
None => {
271+
return Err(anyhow::anyhow!(
272+
"this profiler doesn't support {:?} builds",
273+
self.build_kind
274+
))
275+
}
276+
Some(sub) => sub,
277+
}
280278
} else {
281279
"rustc"
282280
};
@@ -288,6 +286,7 @@ impl<'a> CargoProcess<'a> {
288286
cmd.arg("--profile").arg("check");
289287
}
290288
BuildKind::Debug => {}
289+
BuildKind::Doc => {}
291290
BuildKind::Opt => {
292291
cmd.arg("--release");
293292
}
@@ -301,8 +300,9 @@ impl<'a> CargoProcess<'a> {
301300
// onto rustc for the final crate, which is exactly the crate for which
302301
// we want to wrap rustc.
303302
if let Some((ref mut processor, ..)) = self.processor_etc {
303+
let profiler = processor.profiler().name();
304304
cmd.arg("--wrap-rustc-with");
305-
cmd.arg(processor.profiler().name());
305+
cmd.arg(profiler);
306306
cmd.args(&self.rustc_args);
307307
}
308308

@@ -349,6 +349,21 @@ lazy_static::lazy_static! {
349349
fake_rustc.push("rustc-fake");
350350
fake_rustc
351351
};
352+
static ref FAKE_RUSTDOC: PathBuf = {
353+
let mut fake_rustdoc = env::current_exe().unwrap();
354+
fake_rustdoc.pop();
355+
fake_rustdoc.push("rustdoc-fake");
356+
// link from rustc-fake to rustdoc-fake
357+
if !fake_rustdoc.exists() {
358+
#[cfg(unix)]
359+
use std::os::unix::fs::symlink;
360+
#[cfg(windows)]
361+
use std::os::windows::fs::symlink_file as symlink;
362+
363+
symlink(&*FAKE_RUSTC, &fake_rustdoc).expect("failed to make symbolic link");
364+
}
365+
fake_rustdoc
366+
};
352367
}
353368

354369
/// Used to indicate if we need to retry a run.
@@ -448,6 +463,7 @@ impl<'a> MeasureProcessor<'a> {
448463
let profile = match build_kind {
449464
BuildKind::Check => database::Profile::Check,
450465
BuildKind::Debug => database::Profile::Debug,
466+
BuildKind::Doc => database::Profile::Doc,
451467
BuildKind::Opt => database::Profile::Opt,
452468
};
453469
let mut buf = FuturesUnordered::new();

0 commit comments

Comments
 (0)