Skip to content

Commit cd37051

Browse files
committed
Make all commands return non-zero on benchmark failure.
This will allow commands like `bench_local` to be used in CI testing. The commit also tweaks how `BenchmarkErrors` works.
1 parent 329ee4a commit cd37051

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

collector/collect.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ while : ; do
2323
touch todo-artifacts
2424

2525
target/release/collector bench_next $SITE_URL --self-profile --db $DATABASE;
26-
test $? -gt 0 && echo "sleeping 30 seconds -- failure detected" && sleep 30;
2726
echo sleeping for 30sec at `date`;
2827
sleep 30;
2928
done

collector/src/main.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,15 @@ fn n_benchmarks_remaining(n: usize) -> String {
170170
struct BenchmarkErrors(usize);
171171

172172
impl BenchmarkErrors {
173-
fn fail_if_error(self) -> anyhow::Result<()> {
173+
fn new() -> BenchmarkErrors {
174+
BenchmarkErrors(0)
175+
}
176+
177+
fn incr(&mut self) {
178+
self.0 += 1;
179+
}
180+
181+
fn fail_if_nonzero(self) -> anyhow::Result<()> {
174182
if self.0 > 0 {
175183
anyhow::bail!("{} benchmarks failed", self.0)
176184
}
@@ -190,7 +198,7 @@ fn bench(
190198
call_home: bool,
191199
self_profile: bool,
192200
) -> BenchmarkErrors {
193-
let mut errors_recorded = 0;
201+
let mut errors = BenchmarkErrors::new();
194202
eprintln!("Benchmarking {} for triple {}", cid, compiler.triple);
195203

196204
if call_home {
@@ -223,7 +231,7 @@ fn bench(
223231
"Note that this behavior is likely to change in the future \
224232
to collect and append the data instead."
225233
);
226-
return BenchmarkErrors(errors_recorded);
234+
return errors;
227235
}
228236
let interned_cid = rt.block_on(tx.conn().artifact_id(&cid));
229237

@@ -252,7 +260,7 @@ fn bench(
252260
"collector error: Failed to benchmark '{}', recorded: {}",
253261
benchmark.name, s
254262
);
255-
errors_recorded += 1;
263+
errors.incr();
256264
rt.block_on(tx.conn().record_error(
257265
interned_cid,
258266
benchmark.name.0.as_str(),
@@ -282,7 +290,7 @@ fn bench(
282290
// This ensures that we're good to go with the just updated data.
283291
conn.maybe_create_indices().await;
284292
});
285-
BenchmarkErrors(errors_recorded)
293+
errors
286294
}
287295

288296
fn get_benchmarks(
@@ -539,7 +547,7 @@ fn main_result() -> anyhow::Result<i32> {
539547

540548
let benchmarks = get_benchmarks(&benchmark_dir, include, exclude)?;
541549

542-
bench(
550+
let res = bench(
543551
&mut rt,
544552
conn,
545553
&ArtifactId::Artifact(id.to_string()),
@@ -557,6 +565,7 @@ fn main_result() -> anyhow::Result<i32> {
557565
/* call_home */ false,
558566
self_profile,
559567
);
568+
res.fail_if_nonzero()?;
560569
Ok(0)
561570
}
562571

@@ -591,7 +600,7 @@ fn main_result() -> anyhow::Result<i32> {
591600

592601
let benchmarks = get_benchmarks(&benchmark_dir, None, None)?;
593602

594-
bench(
603+
let res = bench(
595604
&mut rt,
596605
conn,
597606
&ArtifactId::Commit(commit),
@@ -606,6 +615,7 @@ fn main_result() -> anyhow::Result<i32> {
606615

607616
client.post(&format!("{}/perf/onpush", site_url)).send()?;
608617

618+
res.fail_if_nonzero()?;
609619
Ok(0)
610620
}
611621

@@ -662,7 +672,7 @@ fn main_result() -> anyhow::Result<i32> {
662672
let mut benchmarks = get_benchmarks(&benchmark_dir, None, None)?;
663673
benchmarks.retain(|b| b.supports_stable());
664674

665-
bench(
675+
let res = bench(
666676
&mut rt,
667677
conn,
668678
&ArtifactId::Artifact(toolchain.to_string()),
@@ -680,6 +690,7 @@ fn main_result() -> anyhow::Result<i32> {
680690
/* call_home */ false,
681691
/* self_profile */ false,
682692
);
693+
res.fail_if_nonzero()?;
683694
Ok(0)
684695
}
685696

@@ -719,7 +730,7 @@ fn main_result() -> anyhow::Result<i32> {
719730
/* call_home */ false,
720731
/* self_profile */ false,
721732
);
722-
res.fail_if_error()?;
733+
res.fail_if_nonzero()?;
723734
Ok(0)
724735
}
725736

@@ -752,18 +763,21 @@ fn main_result() -> anyhow::Result<i32> {
752763

753764
eprintln!("Profiling with {:?}", profiler);
754765

766+
let mut errors = BenchmarkErrors::new();
755767
for (i, benchmark) in benchmarks.iter().enumerate() {
756768
eprintln!("{}", n_benchmarks_remaining(benchmarks.len() - i));
757769
let mut processor = execute::ProfileProcessor::new(profiler, &out_dir, &id);
758770
let result =
759771
benchmark.measure(&mut processor, &build_kinds, &run_kinds, compiler, 1);
760772
if let Err(ref s) = result {
773+
errors.incr();
761774
eprintln!(
762775
"collector error: Failed to profile '{}' with {:?}, recorded: {:?}",
763776
benchmark.name, profiler, s
764777
);
765778
}
766779
}
780+
errors.fail_if_nonzero()?;
767781
Ok(0)
768782
}
769783

0 commit comments

Comments
 (0)