Skip to content

Commit a2f56cd

Browse files
authored
Merge pull request #2156 from Kobzol/rustdoc-json-perf-check
Add `DocJson` profile for benchmarking JSON rustdoc output
2 parents 70fe651 + 2f75b4e commit a2f56cd

File tree

15 files changed

+62
-21
lines changed

15 files changed

+62
-21
lines changed

collector/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ The following options alter the behaviour of the `bench_local` subcommand.
146146
possible choices are one or more (comma-separated) of `Primary`, `Secondary`,
147147
`Stable`, and `All`. The default is `Primary,Secondary`.
148148
- `--profiles <PROFILES>`: the profiles to be benchmarked. The possible choices
149-
are one or more (comma-separated) of `Check`, `Debug`, `Doc`, `Opt`, and
150-
`All`. The default is `Check,Debug,Opt`.
149+
are one or more (comma-separated) of `Check`, `Debug`, `Doc`, `DocJson`, `Opt`,
150+
`Clippy` and `All`. The default is `Check,Debug,Opt`.
151151
- `--rustdoc <RUSTDOC>`: a path (relative or absolute) to a rustdoc
152-
executable that will be benchmarked (but only if a `Doc` profile is requested
153-
with `--profiles`). If a `Doc` profile is requested, by default the tool will
152+
executable that will be benchmarked (but only if a `Doc`/`DocJson` profile is requested
153+
with `--profiles`). If a `Doc`/`DocJson` profile is requested, by default the tool will
154154
look for a rustdoc executable next to the rustc specified via the `<RUSTC>`
155155
argument.
156156
- `--scenarios <SCENARIOS>`: the scenarios to be benchmarked. The possible

collector/compile-benchmarks/bitmaps-3.2.1-new-solver/perf-config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"category": "secondary",
44
"cargo_rustc_opts": "-Znext-solver=globally",
55
"excluded_profiles": [
6-
"Doc"
6+
"Doc",
7+
"DocJson"
78
],
89
"excluded_scenarios": [
910
"IncrFull",

collector/compile-benchmarks/html5ever-0.31.0-new-solver/perf-config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"category": "secondary",
55
"cargo_rustc_opts": "-Znext-solver=globally",
66
"excluded_profiles": [
7-
"Doc"
7+
"Doc",
8+
"DocJson"
89
],
910
"excluded_scenarios": [
1011
"IncrFull",

collector/compile-benchmarks/nalgebra-0.33.0-new-solver/perf-config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"category": "secondary",
44
"cargo_rustc_opts": "-Znext-solver=globally",
55
"excluded_profiles": [
6-
"Doc"
6+
"Doc",
7+
"DocJson"
78
],
89
"excluded_scenarios": [
910
"IncrFull",

collector/compile-benchmarks/serde-1.0.219-new-solver/perf-config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"category": "secondary",
44
"cargo_rustc_opts": "-Znext-solver=globally",
55
"excluded_profiles": [
6-
"Doc"
6+
"Doc",
7+
"DocJson"
78
],
89
"excluded_scenarios": [
910
"IncrFull",

collector/compile-benchmarks/syn-2.0.101-new-solver/perf-config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"category": "secondary",
44
"cargo_rustc_opts": "-Znext-solver=globally",
55
"excluded_profiles": [
6-
"Doc"
6+
"Doc",
7+
"DocJson"
78
],
89
"excluded_scenarios": [
910
"IncrFull",

collector/src/bin/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fn generate_diffs(
151151
for benchmark in benchmarks {
152152
for &profile in profiles {
153153
for scenario in scenarios.iter().flat_map(|scenario| {
154-
if profile == Profile::Doc && scenario.is_incr() {
154+
if profile.is_doc() && scenario.is_incr() {
155155
return vec![];
156156
}
157157
match scenario {

collector/src/compile/benchmark/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ impl Benchmark {
400400
}
401401

402402
// Rustdoc does not support incremental compilation
403-
if profile != Profile::Doc {
403+
if !profile.is_doc() {
404404
// An incremental from scratch (slowest incremental case).
405405
// This is required for any subsequent incremental builds.
406406
if scenarios.iter().any(|s| s.is_incr()) {

collector/src/compile/benchmark/profile.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@
88
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, clap::ValueEnum, serde::Deserialize)]
99
#[value(rename_all = "PascalCase")]
1010
pub enum Profile {
11+
/// Perform the equivalent of `cargo check`.
1112
Check,
13+
/// Perform the equivalent of `cargo build`.
1214
Debug,
15+
/// Perform the equivalent of `cargo doc`.
1316
Doc,
17+
/// Perform the equivalent of `cargo doc` with `--output-format=json`.
18+
DocJson,
19+
/// Perform the equivalent of `cargo build --release`.
1420
Opt,
21+
/// Perform the equivalent of `cargo clippy`.
1522
Clippy,
1623
}
1724

@@ -21,8 +28,16 @@ impl Profile {
2128
Profile::Check,
2229
Profile::Debug,
2330
Profile::Doc,
31+
Profile::DocJson,
2432
Profile::Opt,
2533
Profile::Clippy,
2634
]
2735
}
36+
37+
pub fn is_doc(&self) -> bool {
38+
match self {
39+
Profile::Doc | Profile::DocJson => true,
40+
Profile::Check | Profile::Debug | Profile::Opt | Profile::Clippy => false,
41+
}
42+
}
2843
}

collector/src/compile/execute/bencher.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ impl Processor for BenchProcessor<'_> {
184184
Profile::Check => database::Profile::Check,
185185
Profile::Debug => database::Profile::Debug,
186186
Profile::Doc => database::Profile::Doc,
187+
Profile::DocJson => database::Profile::DocJson,
187188
Profile::Opt => database::Profile::Opt,
188189
Profile::Clippy => database::Profile::Clippy,
189190
};

collector/src/compile/execute/mod.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ impl PerfTool {
6767
| ProfileTool(DepGraph)
6868
| ProfileTool(MonoItems)
6969
| ProfileTool(LlvmIr) => {
70-
if profile == Profile::Doc {
70+
if profile.is_doc() {
7171
Some("rustdoc")
7272
} else {
7373
Some("rustc")
7474
}
7575
}
7676
ProfileTool(LlvmLines) => match profile {
7777
Profile::Debug | Profile::Opt => Some("llvm-lines"),
78-
Profile::Check | Profile::Doc | Profile::Clippy => None,
78+
Profile::Check | Profile::Doc | Profile::DocJson | Profile::Clippy => None,
7979
},
8080
}
8181
}
@@ -320,11 +320,10 @@ impl<'a> CargoProcess<'a> {
320320
}
321321
Some(sub) => sub,
322322
}
323+
} else if self.profile.is_doc() {
324+
"rustdoc"
323325
} else {
324-
match self.profile {
325-
Profile::Doc => "rustdoc",
326-
_ => "rustc",
327-
}
326+
"rustc"
328327
};
329328

330329
let mut cmd = self.base_command(self.cwd, cargo_subcommand);
@@ -335,6 +334,11 @@ impl<'a> CargoProcess<'a> {
335334
}
336335
Profile::Debug => {}
337336
Profile::Doc => {}
337+
Profile::DocJson => {
338+
// Enable JSON output
339+
cmd.arg("-Zunstable-options");
340+
cmd.arg("--output-format=json");
341+
}
338342
Profile::Opt => {
339343
cmd.arg("--release");
340344
}
@@ -369,6 +373,13 @@ impl<'a> CargoProcess<'a> {
369373
cmd.env("RUSTC", &*FAKE_CLIPPY);
370374
}
371375

376+
if let Profile::DocJson = self.profile {
377+
// Document more things to stress the doc JSON machinery.
378+
// And this is what `cargo-semver-checks` does.
379+
cmd.arg("--document-private-items");
380+
cmd.arg("--document-hidden-items");
381+
}
382+
372383
let processor = self
373384
.processor_etc
374385
.as_mut()

collector/src/toolchain.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,15 +460,15 @@ pub fn get_local_toolchain(
460460
Some(rustdoc.canonicalize().with_context(|| {
461461
format!("failed to canonicalize rustdoc executable {:?}", rustdoc)
462462
})?)
463-
} else if profiles.contains(&Profile::Doc) {
463+
} else if profiles.iter().any(|p| p.is_doc()) {
464464
// We need a `rustdoc`. Look for one next to `rustc`.
465465
if let Ok(rustdoc) = rustc.with_file_name("rustdoc").canonicalize() {
466466
debug!("found rustdoc: {:?}", &rustdoc);
467467
Some(rustdoc)
468468
} else {
469469
anyhow::bail!(
470-
"'Doc' build specified but '--rustdoc' not specified and no 'rustdoc' found \
471-
next to 'rustc'"
470+
"'Doc' or 'DocJson' build specified but '--rustdoc' not specified and no \
471+
'rustdoc' found next to 'rustc'"
472472
);
473473
}
474474
} else {

database/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ pub enum Profile {
210210
Debug,
211211
/// A doc build
212212
Doc,
213+
/// A doc build with `--output-format=json` option.
214+
DocJson,
213215
/// An optimized "release" build
214216
Opt,
215217
/// A Clippy run
@@ -223,6 +225,7 @@ impl Profile {
223225
Profile::Opt => "opt",
224226
Profile::Debug => "debug",
225227
Profile::Doc => "doc",
228+
Profile::DocJson => "doc-json",
226229
Profile::Clippy => "clippy",
227230
}
228231
}
@@ -235,6 +238,7 @@ impl std::str::FromStr for Profile {
235238
"check" => Profile::Check,
236239
"debug" => Profile::Debug,
237240
"doc" => Profile::Doc,
241+
"doc-json" => Profile::DocJson,
238242
"opt" => Profile::Opt,
239243
"clippy" => Profile::Clippy,
240244
_ => return Err(format!("{} is not a profile", s)),

docs/glossary.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ The following is a glossary of domain specific terminology. Although benchmarks
1515
- `check` corresponds to running `cargo check`.
1616
- `debug` corresponds to running `cargo build`.
1717
- `opt` corresponds to running `cargo build --release`.
18-
- `doc` corresponds to running rustdoc.
18+
- `doc` corresponds to running rustdoc with the JSON output format.
19+
- `doc-json` corresponds to running rustdoc.
20+
- `clippy` corresponds to running `cargo clippy`.
1921
* **scenario**: describes the incremental cache state and an optional change in the source since last compilation.
2022
- `full`: incremental compilation is not used.
2123
- `incr-full`: incremental compilation is used, with an empty incremental cache.

site/src/request_handlers/dashboard.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ pub struct ByProfile<T> {
174174
pub check: T,
175175
pub debug: T,
176176
pub doc: T,
177+
pub doc_json: T,
177178
pub opt: T,
178179
pub clippy: T,
179180
}
@@ -188,6 +189,7 @@ impl<T> ByProfile<T> {
188189
check: f(Profile::Check).await?,
189190
debug: f(Profile::Debug).await?,
190191
doc: f(Profile::Doc).await?,
192+
doc_json: f(Profile::DocJson).await?,
191193
opt: f(Profile::Opt).await?,
192194
clippy: f(Profile::Clippy).await?,
193195
})
@@ -201,6 +203,7 @@ impl<T> std::ops::Index<Profile> for ByProfile<T> {
201203
Profile::Check => &self.check,
202204
Profile::Debug => &self.debug,
203205
Profile::Doc => &self.doc,
206+
Profile::DocJson => &self.doc_json,
204207
Profile::Opt => &self.opt,
205208
Profile::Clippy => &self.clippy,
206209
}

0 commit comments

Comments
 (0)