Skip to content

Commit b0f0fd8

Browse files
committed
Execute runtime benchmarks in bench_published_artifact
1 parent 6006c96 commit b0f0fd8

File tree

4 files changed

+97
-32
lines changed

4 files changed

+97
-32
lines changed

collector/src/bin/collector.rs

Lines changed: 80 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ use tokio::runtime::Runtime;
2828
use collector::compile::execute::bencher::BenchProcessor;
2929
use collector::compile::execute::profiler::{ProfileProcessor, Profiler};
3030
use collector::runtime::{
31-
bench_runtime, runtime_benchmark_dir, BenchmarkFilter, CargoIsolationMode,
31+
bench_runtime, runtime_benchmark_dir, BenchmarkFilter, BenchmarkSuite, CargoIsolationMode,
32+
DEFAULT_RUNTIME_ITERATIONS,
3233
};
3334
use collector::toolchain::{
3435
create_toolchain_from_published_version, get_local_toolchain, Sysroot, Toolchain,
@@ -62,6 +63,12 @@ impl BenchmarkErrors {
6263
}
6364
}
6465

66+
#[derive(Debug)]
67+
struct BenchmarkDirs<'a> {
68+
compile: &'a Path,
69+
runtime: &'a Path,
70+
}
71+
6572
#[allow(clippy::too_many_arguments)]
6673
fn bench(
6774
rt: &mut Runtime,
@@ -563,7 +570,7 @@ enum Commands {
563570
local: LocalOptions,
564571

565572
/// How many iterations of each benchmark should be executed.
566-
#[arg(long, default_value = "5")]
573+
#[arg(long, default_value_t = DEFAULT_RUNTIME_ITERATIONS)]
567574
iterations: u32,
568575

569576
#[command(flatten)]
@@ -693,6 +700,11 @@ fn main_result() -> anyhow::Result<i32> {
693700
let compile_benchmark_dir = compile_benchmark_dir();
694701
let runtime_benchmark_dir = runtime_benchmark_dir();
695702

703+
let benchmark_dirs = BenchmarkDirs {
704+
compile: &compile_benchmark_dir,
705+
runtime: &runtime_benchmark_dir,
706+
};
707+
696708
let mut builder = tokio::runtime::Builder::new_multi_thread();
697709
// We want to minimize noise from the runtime
698710
builder
@@ -727,7 +739,7 @@ fn main_result() -> anyhow::Result<i32> {
727739
} else {
728740
CargoIsolationMode::Isolated
729741
};
730-
let suite = runtime::create_runtime_benchmark_suite(
742+
let suite = runtime::prepare_runtime_benchmark_suite(
731743
&toolchain,
732744
&runtime_benchmark_dir,
733745
isolation_mode,
@@ -783,8 +795,9 @@ fn main_result() -> anyhow::Result<i32> {
783795
benchmarks.retain(|b| b.category().is_primary_or_secondary());
784796

785797
let artifact_id = ArtifactId::Tag(toolchain.id.clone());
786-
let (mut conn, collector) = rt.block_on(init_compile_collector(
787-
&pool,
798+
let mut conn = rt.block_on(pool.connection());
799+
let collector = rt.block_on(init_compile_collector(
800+
conn.as_mut(),
788801
&benchmarks,
789802
bench_rustc.bench_rustc,
790803
artifact_id,
@@ -830,7 +843,12 @@ fn main_result() -> anyhow::Result<i32> {
830843
match next {
831844
NextArtifact::Release(tag) => {
832845
let toolchain = create_toolchain_from_published_version(&tag, &target_triple)?;
833-
bench_published_artifact(&toolchain, pool, &mut rt, &compile_benchmark_dir)?;
846+
bench_published_artifact(
847+
&toolchain,
848+
rt.block_on(pool.connection()),
849+
&mut rt,
850+
&benchmark_dirs,
851+
)?;
834852

835853
client.post(format!("{}/perf/onpush", site_url)).send()?;
836854
}
@@ -853,8 +871,9 @@ fn main_result() -> anyhow::Result<i32> {
853871
benchmarks.retain(|b| b.category().is_primary_or_secondary());
854872

855873
let artifact_id = ArtifactId::Commit(commit);
856-
let (mut conn, collector) = rt.block_on(init_compile_collector(
857-
&pool,
874+
let mut conn = rt.block_on(pool.connection());
875+
let collector = rt.block_on(init_compile_collector(
876+
conn.as_mut(),
858877
&benchmarks,
859878
bench_rustc.bench_rustc,
860879
artifact_id,
@@ -882,8 +901,9 @@ fn main_result() -> anyhow::Result<i32> {
882901

883902
Commands::BenchPublished { toolchain, db } => {
884903
let pool = database::Pool::open(&db.db);
904+
let conn = rt.block_on(pool.connection());
885905
let toolchain = create_toolchain_from_published_version(&toolchain, &target_triple)?;
886-
bench_published_artifact(&toolchain, pool, &mut rt, &compile_benchmark_dir)?;
906+
bench_published_artifact(&toolchain, conn, &mut rt, &benchmark_dirs)?;
887907
Ok(0)
888908
}
889909

@@ -1030,25 +1050,35 @@ fn main_result() -> anyhow::Result<i32> {
10301050
}
10311051

10321052
async fn init_compile_collector(
1033-
pool: &database::Pool,
1053+
connection: &mut dyn Connection,
10341054
benchmarks: &[Benchmark],
10351055
bench_rustc: bool,
10361056
artifact_id: ArtifactId,
1037-
) -> (Box<dyn Connection>, CollectorCtx) {
1038-
let mut conn = pool.connection().await;
1039-
let collector = CollectorStepBuilder::default()
1057+
) -> CollectorCtx {
1058+
CollectorStepBuilder::default()
10401059
.record_compile_benchmarks(benchmarks, bench_rustc)
1041-
.start_collection(conn.as_mut(), artifact_id)
1042-
.await;
1043-
(conn, collector)
1060+
.start_collection(connection, artifact_id)
1061+
.await
1062+
}
1063+
1064+
async fn init_runtime_collector(
1065+
connection: &mut dyn Connection,
1066+
suite: &BenchmarkSuite,
1067+
artifact_id: ArtifactId,
1068+
) -> CollectorCtx {
1069+
CollectorStepBuilder::default()
1070+
.record_runtime_benchmarks(suite)
1071+
.start_collection(connection, artifact_id)
1072+
.await
10441073
}
10451074

10461075
fn bench_published_artifact(
10471076
toolchain: &Toolchain,
1048-
pool: Pool,
1077+
mut connection: Box<dyn Connection>,
10491078
rt: &mut Runtime,
1050-
benchmark_dir: &Path,
1079+
dirs: &BenchmarkDirs,
10511080
) -> anyhow::Result<()> {
1081+
// Compile benchmarks
10521082
let profiles = if collector::version_supports_doc(&toolchain.id) {
10531083
Profile::all()
10541084
} else {
@@ -1061,29 +1091,51 @@ fn bench_published_artifact(
10611091
};
10621092

10631093
// Exclude benchmarks that don't work with a stable compiler.
1064-
let mut benchmarks = get_compile_benchmarks(benchmark_dir, None, None, None)?;
1065-
benchmarks.retain(|b| b.category().is_stable());
1094+
let mut compile_benchmarks = get_compile_benchmarks(dirs.compile, None, None, None)?;
1095+
compile_benchmarks.retain(|b| b.category().is_stable());
10661096

10671097
let artifact_id = ArtifactId::Tag(toolchain.id.clone());
1068-
let (mut conn, collector) = rt.block_on(init_compile_collector(
1069-
&pool,
1070-
&benchmarks,
1098+
let collector = rt.block_on(init_compile_collector(
1099+
connection.as_mut(),
1100+
&compile_benchmarks,
10711101
/* bench_rustc */ false,
1072-
artifact_id,
1102+
artifact_id.clone(),
10731103
));
10741104
let res = bench(
10751105
rt,
1076-
conn.as_mut(),
1106+
connection.as_mut(),
10771107
&profiles,
10781108
&scenarios,
10791109
toolchain,
1080-
&benchmarks,
1110+
&compile_benchmarks,
10811111
Some(3),
10821112
/* is_self_profile */ false,
10831113
collector,
10841114
);
1085-
res.fail_if_nonzero()?;
1086-
Ok(())
1115+
let compile_result = res.fail_if_nonzero().context("Compile benchmarks failed");
1116+
1117+
// Runtime benchmarks
1118+
let runtime_suite = runtime::prepare_runtime_benchmark_suite(
1119+
toolchain,
1120+
dirs.runtime,
1121+
CargoIsolationMode::Isolated,
1122+
)?;
1123+
let collector = rt.block_on(init_runtime_collector(
1124+
connection.as_mut(),
1125+
&runtime_suite,
1126+
artifact_id,
1127+
));
1128+
let runtime_result = rt
1129+
.block_on(bench_runtime(
1130+
connection,
1131+
runtime_suite,
1132+
collector,
1133+
BenchmarkFilter::keep_all(),
1134+
DEFAULT_RUNTIME_ITERATIONS,
1135+
))
1136+
.context("Runtime benchmarks failed");
1137+
1138+
compile_result.or(runtime_result)
10871139
}
10881140

10891141
fn add_perf_config(directory: &Path, category: Category) {

collector/src/runtime/benchmark.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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,7 +94,7 @@ 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(
97+
pub fn prepare_runtime_benchmark_suite(
9198
toolchain: &Toolchain,
9299
benchmark_dir: &Path,
93100
isolation_mode: CargoIsolationMode,
@@ -124,7 +131,7 @@ pub fn create_runtime_benchmark_suite(
124131

125132
let cargo_process = start_cargo_build(toolchain, &benchmark_crate.path, target_dir)
126133
.with_context(|| {
127-
anyhow::anyhow!("Cannot not start compilation of {}", benchmark_crate.name)
134+
anyhow::anyhow!("Cannot start compilation of {}", benchmark_crate.name)
128135
})?;
129136
let group =
130137
parse_benchmark_group(cargo_process, &benchmark_crate.name).with_context(|| {

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

collector/src/toolchain.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ pub fn create_toolchain_from_published_version(
416416
let rustdoc = which("rustdoc")?;
417417
let cargo = which("cargo")?;
418418

419+
debug!("Found rustc: {}", rustc.display());
420+
debug!("Found rustdoc: {}", rustdoc.display());
421+
debug!("Found cargo: {}", cargo.display());
422+
419423
Ok(Toolchain {
420424
rustc,
421425
rustdoc: Some(rustdoc),

0 commit comments

Comments
 (0)