Skip to content

Commit 183b954

Browse files
authored
Merge pull request #1630 from Kobzol/runtime-bench-published
Perform runtime benchmarks when benchmarking published artifacts
2 parents bc1f239 + b0f0fd8 commit 183b954

File tree

8 files changed

+223
-168
lines changed

8 files changed

+223
-168
lines changed

collector/src/bin/collector.rs

Lines changed: 109 additions & 95 deletions
Large diffs are not rendered by default.

collector/src/compile/benchmark/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::compile::benchmark::patch::Patch;
33
use crate::compile::benchmark::profile::Profile;
44
use crate::compile::benchmark::scenario::Scenario;
55
use crate::compile::execute::{CargoProcess, Processor};
6-
use crate::toolchain::Compiler;
6+
use crate::toolchain::Toolchain;
77
use anyhow::{bail, Context};
88
use log::debug;
99
use std::collections::{HashMap, HashSet};
@@ -143,7 +143,7 @@ impl Benchmark {
143143

144144
fn mk_cargo_process<'a>(
145145
&'a self,
146-
compiler: Compiler<'a>,
146+
toolchain: &'a Toolchain,
147147
cwd: &'a Path,
148148
profile: Profile,
149149
) -> CargoProcess<'a> {
@@ -163,7 +163,7 @@ impl Benchmark {
163163
}
164164

165165
CargoProcess {
166-
compiler,
166+
toolchain,
167167
processor_name: self.name.clone(),
168168
cwd,
169169
profile,
@@ -194,7 +194,7 @@ impl Benchmark {
194194
processor: &mut dyn Processor,
195195
profiles: &[Profile],
196196
scenarios: &[Scenario],
197-
compiler: Compiler<'_>,
197+
toolchain: &Toolchain,
198198
iterations: Option<usize>,
199199
) -> anyhow::Result<()> {
200200
if self.config.disabled {
@@ -261,7 +261,7 @@ impl Benchmark {
261261
for (profile, prep_dir) in &profile_dirs {
262262
let server = server.clone();
263263
let thread = s.spawn::<_, anyhow::Result<()>>(move || {
264-
self.mk_cargo_process(compiler, prep_dir.path(), *profile)
264+
self.mk_cargo_process(toolchain, prep_dir.path(), *profile)
265265
.jobserver(server)
266266
.run_rustc(false)?;
267267
Ok(())
@@ -308,7 +308,7 @@ impl Benchmark {
308308

309309
// A full non-incremental build.
310310
if scenarios.contains(&Scenario::Full) {
311-
self.mk_cargo_process(compiler, cwd, profile)
311+
self.mk_cargo_process(toolchain, cwd, profile)
312312
.processor(processor, Scenario::Full, "Full", None)
313313
.run_rustc(true)?;
314314
}
@@ -318,15 +318,15 @@ impl Benchmark {
318318
// An incremental from scratch (slowest incremental case).
319319
// This is required for any subsequent incremental builds.
320320
if scenarios.iter().any(|s| s.is_incr()) {
321-
self.mk_cargo_process(compiler, cwd, profile)
321+
self.mk_cargo_process(toolchain, cwd, profile)
322322
.incremental(true)
323323
.processor(processor, Scenario::IncrFull, "IncrFull", None)
324324
.run_rustc(true)?;
325325
}
326326

327327
// An incremental build with no changes (fastest incremental case).
328328
if scenarios.contains(&Scenario::IncrUnchanged) {
329-
self.mk_cargo_process(compiler, cwd, profile)
329+
self.mk_cargo_process(toolchain, cwd, profile)
330330
.incremental(true)
331331
.processor(processor, Scenario::IncrUnchanged, "IncrUnchanged", None)
332332
.run_rustc(true)?;
@@ -340,7 +340,7 @@ impl Benchmark {
340340
// An incremental build with some changes (realistic
341341
// incremental case).
342342
let scenario_str = format!("IncrPatched{}", i);
343-
self.mk_cargo_process(compiler, cwd, profile)
343+
self.mk_cargo_process(toolchain, cwd, profile)
344344
.incremental(true)
345345
.processor(
346346
processor,

collector/src/compile/execute/bencher.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::compile::execute::{
66
rustc, DeserializeStatError, PerfTool, ProcessOutputData, Processor, Retry, SelfProfile,
77
SelfProfileFiles, Stats, Upload,
88
};
9-
use crate::toolchain::Compiler;
9+
use crate::toolchain::Toolchain;
1010
use crate::utils::git::get_rustc_perf_commit;
1111
use futures::stream::FuturesUnordered;
1212
use futures::StreamExt;
@@ -160,11 +160,11 @@ impl<'a> BenchProcessor<'a> {
160160
.block_on(async move { while let Some(()) = buf.next().await {} });
161161
}
162162

163-
pub fn measure_rustc(&mut self, compiler: Compiler<'_>) -> anyhow::Result<()> {
163+
pub fn measure_rustc(&mut self, toolchain: &Toolchain) -> anyhow::Result<()> {
164164
rustc::measure(
165165
self.rt,
166166
self.conn,
167-
compiler,
167+
toolchain,
168168
self.artifact,
169169
self.artifact_row_id,
170170
)

collector/src/compile/execute/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::compile::benchmark::patch::Patch;
44
use crate::compile::benchmark::profile::Profile;
55
use crate::compile::benchmark::scenario::Scenario;
66
use crate::compile::benchmark::BenchmarkName;
7-
use crate::toolchain::Compiler;
7+
use crate::toolchain::Toolchain;
88
use crate::{command_output, utils};
99
use anyhow::Context;
1010
use bencher::Bencher;
@@ -113,7 +113,7 @@ impl PerfTool {
113113
}
114114

115115
pub struct CargoProcess<'a> {
116-
pub compiler: Compiler<'a>,
116+
pub toolchain: &'a Toolchain,
117117
pub cwd: &'a Path,
118118
pub profile: Profile,
119119
pub incremental: bool,
@@ -144,12 +144,12 @@ impl<'a> CargoProcess<'a> {
144144
}
145145

146146
fn base_command(&self, cwd: &Path, subcommand: &str) -> Command {
147-
let mut cmd = Command::new(Path::new(self.compiler.cargo));
147+
let mut cmd = Command::new(Path::new(&self.toolchain.cargo));
148148
cmd
149149
// Not all cargo invocations (e.g. `cargo clean`) need all of these
150150
// env vars set, but it doesn't hurt to have them.
151151
.env("RUSTC", &*FAKE_RUSTC)
152-
.env("RUSTC_REAL", self.compiler.rustc)
152+
.env("RUSTC_REAL", &self.toolchain.rustc)
153153
// We separately pass -Cincremental to the leaf crate --
154154
// CARGO_INCREMENTAL is cached separately for both the leaf crate
155155
// and any in-tree dependencies, and we don't want that; it wastes
@@ -164,7 +164,7 @@ impl<'a> CargoProcess<'a> {
164164
.arg("--manifest-path")
165165
.arg(&self.manifest_path);
166166

167-
if let Some(r) = &self.compiler.rustdoc {
167+
if let Some(r) = &self.toolchain.rustdoc {
168168
cmd.env("RUSTDOC", &*FAKE_RUSTDOC).env("RUSTDOC_REAL", r);
169169
}
170170
cmd

collector/src/compile/execute/rustc.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! no real reason for us to compile the standard library twice, and it avoids
88
//! having to think about how to deduplicate results.
99
10-
use crate::toolchain::Compiler;
10+
use crate::toolchain::Toolchain;
1111
use crate::utils::git::get_rustc_perf_commit;
1212
use anyhow::Context;
1313
use database::ArtifactId;
@@ -20,23 +20,23 @@ use tokio::runtime::Runtime;
2020
pub fn measure(
2121
rt: &mut Runtime,
2222
conn: &mut dyn database::Connection,
23-
compiler: Compiler<'_>,
23+
toolchain: &Toolchain,
2424
artifact: &database::ArtifactId,
2525
aid: database::ArtifactIdNumber,
2626
) -> anyhow::Result<()> {
2727
eprintln!("Running rustc");
2828

2929
checkout(artifact).context("checking out rust-lang/rust")?;
3030

31-
record(rt, conn, compiler, artifact, aid)?;
31+
record(rt, conn, toolchain, artifact, aid)?;
3232

3333
Ok(())
3434
}
3535

3636
fn record(
3737
rt: &mut Runtime,
3838
conn: &mut dyn database::Connection,
39-
compiler: Compiler<'_>,
39+
toolchain: &Toolchain,
4040
artifact: &database::ArtifactId,
4141
aid: database::ArtifactIdNumber,
4242
) -> anyhow::Result<()> {
@@ -95,9 +95,12 @@ fn record(
9595
.arg("rust.deny-warnings=false")
9696
.arg("--set")
9797
.arg(&format!("build.rustc={}", fake_rustc.to_str().unwrap()))
98-
.env("RUSTC_PERF_REAL_RUSTC", compiler.rustc)
98+
.env("RUSTC_PERF_REAL_RUSTC", &toolchain.rustc)
9999
.arg("--set")
100-
.arg(&format!("build.cargo={}", compiler.cargo.to_str().unwrap()))
100+
.arg(&format!(
101+
"build.cargo={}",
102+
toolchain.cargo.to_str().unwrap()
103+
))
101104
.status()
102105
.context("configuring")?;
103106
assert!(status.success(), "configure successful");
@@ -111,7 +114,7 @@ fn record(
111114
.context("x.py script canonicalize")?,
112115
)
113116
.current_dir(checkout)
114-
.env("RUSTC_PERF_REAL_RUSTC", compiler.rustc)
117+
.env("RUSTC_PERF_REAL_RUSTC", &toolchain.rustc)
115118
.arg("build")
116119
.arg("--stage")
117120
.arg("0")

collector/src/runtime/benchmark.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use crate::toolchain::LocalToolchain;
1+
use crate::toolchain::Toolchain;
22
use anyhow::Context;
33
use benchlib::benchmark::passes_filter;
44
use cargo_metadata::Message;
55
use core::option::Option;
66
use core::option::Option::Some;
77
use core::result::Result::Ok;
88
use std::collections::HashMap;
9-
use std::io::{BufReader, Write};
9+
use std::io::BufReader;
1010
use std::path::{Path, PathBuf};
1111
use std::process::{Child, Command, Stdio};
1212
use tempfile::TempDir;
@@ -66,7 +66,14 @@ pub struct BenchmarkFilter {
6666
}
6767

6868
impl BenchmarkFilter {
69-
pub fn new(exclude: Option<String>, include: Option<String>) -> BenchmarkFilter {
69+
pub fn keep_all() -> Self {
70+
Self {
71+
exclude: None,
72+
include: None,
73+
}
74+
}
75+
76+
pub fn new(exclude: Option<String>, include: Option<String>) -> Self {
7077
Self { exclude, include }
7178
}
7279
}
@@ -87,8 +94,8 @@ pub enum CargoIsolationMode {
8794
/// We assume that each binary defines a benchmark suite using `benchlib`.
8895
/// We then execute each benchmark suite with the `list-benchmarks` command to find out its
8996
/// benchmark names.
90-
pub fn create_runtime_benchmark_suite(
91-
toolchain: &LocalToolchain,
97+
pub fn prepare_runtime_benchmark_suite(
98+
toolchain: &Toolchain,
9299
benchmark_dir: &Path,
93100
isolation_mode: CargoIsolationMode,
94101
) -> anyhow::Result<BenchmarkSuite> {
@@ -114,28 +121,24 @@ pub fn create_runtime_benchmark_suite(
114121

115122
let mut groups = Vec::new();
116123
for (index, benchmark_crate) in benchmark_crates.into_iter().enumerate() {
117-
// Show incremental progress
118-
print!(
119-
"\r{}\rCompiling `{}` ({}/{group_count})",
120-
" ".repeat(80),
121-
benchmark_crate.name,
124+
println!(
125+
"Compiling {:<22} ({}/{group_count})",
126+
format!("`{}`", benchmark_crate.name),
122127
index + 1
123128
);
124-
std::io::stdout().flush().unwrap();
125129

126130
let target_dir = temp_dir.as_ref().map(|d| d.path());
127131

128132
let cargo_process = start_cargo_build(toolchain, &benchmark_crate.path, target_dir)
129133
.with_context(|| {
130-
anyhow::anyhow!("Cannot not start compilation of {}", benchmark_crate.name)
134+
anyhow::anyhow!("Cannot start compilation of {}", benchmark_crate.name)
131135
})?;
132136
let group =
133137
parse_benchmark_group(cargo_process, &benchmark_crate.name).with_context(|| {
134138
anyhow::anyhow!("Cannot compile runtime benchmark {}", benchmark_crate.name)
135139
})?;
136140
groups.push(group);
137141
}
138-
println!();
139142

140143
groups.sort_unstable_by(|a, b| a.binary.cmp(&b.binary));
141144
log::debug!("Found binaries: {:?}", groups);
@@ -233,7 +236,7 @@ fn parse_benchmark_group(
233236
/// Starts the compilation of a single runtime benchmark crate.
234237
/// Returns the stdout output stream of Cargo.
235238
fn start_cargo_build(
236-
toolchain: &LocalToolchain,
239+
toolchain: &Toolchain,
237240
benchmark_dir: &Path,
238241
target_dir: Option<&Path>,
239242
) -> anyhow::Result<Child> {

collector/src/runtime/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use thousands::Separable;
66

77
use benchlib::comm::messages::{BenchmarkMessage, BenchmarkResult, BenchmarkStats};
88
pub use benchmark::{
9-
create_runtime_benchmark_suite, runtime_benchmark_dir, BenchmarkFilter, BenchmarkGroup,
9+
prepare_runtime_benchmark_suite, runtime_benchmark_dir, BenchmarkFilter, BenchmarkGroup,
1010
BenchmarkSuite, CargoIsolationMode,
1111
};
1212
use database::{ArtifactIdNumber, CollectionId, Connection};
@@ -16,6 +16,8 @@ use crate::CollectorCtx;
1616

1717
mod benchmark;
1818

19+
pub const DEFAULT_RUNTIME_ITERATIONS: u32 = 5;
20+
1921
/// Perform a series of runtime benchmarks using the provided `rustc` compiler.
2022
/// The runtime benchmarks are looked up in `benchmark_dir`, which is expected to be a path
2123
/// to a Cargo crate. All binaries built by that crate are expected to be runtime benchmark

0 commit comments

Comments
 (0)