Skip to content

Commit 2f15679

Browse files
authored
Merge pull request #1636 from Kobzol/runtime-ci-db-storage
Refactor runtime benchmarks in `bench_published`
2 parents 3988e7c + 9553fd9 commit 2f15679

File tree

3 files changed

+31
-50
lines changed

3 files changed

+31
-50
lines changed

collector/src/bin/collector.rs

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ 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, BenchmarkSuite, CargoIsolationMode,
31+
bench_runtime, runtime_benchmark_dir, BenchmarkFilter, CargoIsolationMode,
3232
DEFAULT_RUNTIME_ITERATIONS,
3333
};
3434
use collector::toolchain::{
@@ -79,7 +79,7 @@ fn bench(
7979
benchmarks: &[Benchmark],
8080
iterations: Option<usize>,
8181
is_self_profile: bool,
82-
mut collector: CollectorCtx,
82+
collector: &CollectorCtx,
8383
) -> BenchmarkErrors {
8484
let mut errors = BenchmarkErrors::new();
8585
eprintln!(
@@ -756,7 +756,7 @@ fn main_result() -> anyhow::Result<i32> {
756756
let fut = bench_runtime(
757757
conn,
758758
suite,
759-
collector,
759+
&collector,
760760
BenchmarkFilter::new(local.exclude, local.include),
761761
iterations,
762762
);
@@ -812,7 +812,7 @@ fn main_result() -> anyhow::Result<i32> {
812812
&benchmarks,
813813
Some(iterations),
814814
self_profile.self_profile,
815-
collector,
815+
&collector,
816816
);
817817
res.fail_if_nonzero()?;
818818
Ok(0)
@@ -889,7 +889,7 @@ fn main_result() -> anyhow::Result<i32> {
889889
&benchmarks,
890890
runs.map(|v| v as usize),
891891
self_profile.self_profile,
892-
collector,
892+
&collector,
893893
);
894894

895895
client.post(format!("{}/perf/onpush", site_url)).send()?;
@@ -1063,17 +1063,6 @@ async fn init_compile_collector(
10631063
.await
10641064
}
10651065

1066-
async fn init_runtime_collector(
1067-
connection: &mut dyn Connection,
1068-
suite: &BenchmarkSuite,
1069-
artifact_id: ArtifactId,
1070-
) -> CollectorCtx {
1071-
CollectorStepBuilder::default()
1072-
.record_runtime_benchmarks(suite)
1073-
.start_collection(connection, artifact_id)
1074-
.await
1075-
}
1076-
10771066
fn bench_published_artifact(
10781067
toolchain: &Toolchain,
10791068
mut connection: Box<dyn Connection>,
@@ -1096,13 +1085,19 @@ fn bench_published_artifact(
10961085
let mut compile_benchmarks = get_compile_benchmarks(dirs.compile, None, None, None)?;
10971086
compile_benchmarks.retain(|b| b.category().is_stable());
10981087

1088+
let runtime_suite = runtime::prepare_runtime_benchmark_suite(
1089+
toolchain,
1090+
dirs.runtime,
1091+
CargoIsolationMode::Isolated,
1092+
)?;
1093+
10991094
let artifact_id = ArtifactId::Tag(toolchain.id.clone());
1100-
let collector = rt.block_on(init_compile_collector(
1101-
connection.as_mut(),
1102-
&compile_benchmarks,
1103-
/* bench_rustc */ false,
1104-
artifact_id.clone(),
1105-
));
1095+
let collector = rt.block_on(
1096+
CollectorStepBuilder::default()
1097+
.record_compile_benchmarks(&compile_benchmarks, false)
1098+
.record_runtime_benchmarks(&runtime_suite)
1099+
.start_collection(connection.as_mut(), artifact_id),
1100+
);
11061101
let res = bench(
11071102
rt,
11081103
connection.as_mut(),
@@ -1112,26 +1107,16 @@ fn bench_published_artifact(
11121107
&compile_benchmarks,
11131108
Some(3),
11141109
/* is_self_profile */ false,
1115-
collector,
1110+
&collector,
11161111
);
11171112
let compile_result = res.fail_if_nonzero().context("Compile benchmarks failed");
11181113

11191114
// Runtime benchmarks
1120-
let runtime_suite = runtime::prepare_runtime_benchmark_suite(
1121-
toolchain,
1122-
dirs.runtime,
1123-
CargoIsolationMode::Isolated,
1124-
)?;
1125-
let collector = rt.block_on(init_runtime_collector(
1126-
connection.as_mut(),
1127-
&runtime_suite,
1128-
artifact_id,
1129-
));
11301115
let runtime_result = rt
11311116
.block_on(bench_runtime(
11321117
connection,
11331118
runtime_suite,
1134-
collector,
1119+
&collector,
11351120
BenchmarkFilter::keep_all(),
11361121
DEFAULT_RUNTIME_ITERATIONS,
11371122
))

collector/src/lib.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -308,33 +308,25 @@ pub struct CollectorCtx {
308308

309309
impl CollectorCtx {
310310
pub async fn start_compile_step(
311-
&mut self,
312-
conn: &mut dyn Connection,
311+
&self,
312+
conn: &dyn Connection,
313313
benchmark_name: &BenchmarkName,
314314
) -> bool {
315315
conn.collector_start_step(self.artifact_row_id, &benchmark_name.0)
316316
.await
317317
}
318318

319-
pub async fn end_compile_step(
320-
&mut self,
321-
conn: &mut dyn Connection,
322-
benchmark_name: &BenchmarkName,
323-
) {
319+
pub async fn end_compile_step(&self, conn: &dyn Connection, benchmark_name: &BenchmarkName) {
324320
conn.collector_end_step(self.artifact_row_id, &benchmark_name.0)
325321
.await
326322
}
327323

328-
pub async fn start_runtime_step(
329-
&mut self,
330-
conn: &mut dyn Connection,
331-
group: &BenchmarkGroup,
332-
) -> bool {
324+
pub async fn start_runtime_step(&self, conn: &dyn Connection, group: &BenchmarkGroup) -> bool {
333325
conn.collector_start_step(self.artifact_row_id, &runtime_group_step_name(group))
334326
.await
335327
}
336328

337-
pub async fn end_runtime_step(&mut self, conn: &mut dyn Connection, group: &BenchmarkGroup) {
329+
pub async fn end_runtime_step(&self, conn: &dyn Connection, group: &BenchmarkGroup) {
338330
conn.collector_end_step(self.artifact_row_id, &runtime_group_step_name(group))
339331
.await
340332
}

collector/src/runtime/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub const DEFAULT_RUNTIME_ITERATIONS: u32 = 5;
2525
pub async fn bench_runtime(
2626
mut conn: Box<dyn Connection>,
2727
suite: BenchmarkSuite,
28-
mut collector: CollectorCtx,
28+
collector: &CollectorCtx,
2929
filter: BenchmarkFilter,
3030
iterations: u32,
3131
) -> anyhow::Result<()> {
@@ -46,6 +46,7 @@ pub async fn bench_runtime(
4646
continue;
4747
}
4848

49+
let mut tx = conn.transaction().await;
4950
for message in execute_runtime_benchmark_binary(&group.binary, &filter, iterations)? {
5051
let message = message.map_err(|err| {
5152
anyhow::anyhow!(
@@ -63,7 +64,7 @@ pub async fn bench_runtime(
6364

6465
print_stats(&result);
6566
record_stats(
66-
conn.as_ref(),
67+
tx.conn(),
6768
collector.artifact_row_id,
6869
&rustc_perf_version,
6970
result,
@@ -73,7 +74,10 @@ pub async fn bench_runtime(
7374
}
7475
}
7576

76-
collector.end_runtime_step(conn.as_mut(), &group).await;
77+
collector.end_runtime_step(tx.conn(), &group).await;
78+
tx.commit()
79+
.await
80+
.expect("Cannot commit runtime benchmark group results");
7781
}
7882

7983
Ok(())

0 commit comments

Comments
 (0)