Skip to content

Commit 48cdb26

Browse files
authored
Merge pull request #699 from nnethercote/improve-testing
Improve testing
2 parents 718393a + 35a5e64 commit 48cdb26

File tree

5 files changed

+109
-112
lines changed

5 files changed

+109
-112
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
- name: Check benchmarks
6060
run: sh -x -c "ci/check-benchmarks.sh"
6161
env:
62-
BENCH_TEST_OPTS: "--exclude script-servo"
62+
BENCH_INCLUDE_EXCLUDE_OPTS: "--exclude script-servo"
6363
test_script_servo:
6464
name: Test benchmark script-servo
6565
runs-on: ubuntu-latest
@@ -90,5 +90,5 @@ jobs:
9090
- name: Check benchmarks
9191
run: sh -x -c "ci/check-benchmarks.sh"
9292
env:
93-
BENCH_TEST_OPTS: "--include script-servo"
93+
BENCH_INCLUDE_EXCLUDE_OPTS: "--include script-servo"
9494
SHELL: "/bin/bash"

ci/check-benchmarks.sh

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@ set -x;
55
bash -c "while true; do sleep 30; echo \$(date) - running ...; done" &
66
PING_LOOP_PID=$!
77
trap - ERR
8+
RUST_BACKTRACE=1 RUST_LOG=collector_raw_cargo=trace,collector=debug,rust_sysroot=debug \
9+
bindir=`cargo run -p collector --bin collector install_next` \
10+
&& \
811
RUST_BACKTRACE=1 RUST_LOG=collector_raw_cargo=trace,collector=debug,rust_sysroot=debug \
912
cargo run -p collector --bin collector -- \
10-
bench_test $BENCH_TEST_OPTS
13+
bench_local $bindir/rustc Test \
14+
--builds Check,Doc \
15+
--cargo $bindir/cargo \
16+
--runs All \
17+
--rustdoc $bindir/rustdoc \
18+
$BENCH_INCLUDE_EXCLUDE_OPTS
1119
code=$?
1220
kill $PING_LOOP_PID
1321
exit $code

collector/collect.sh

-1
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

+89-108
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ extern crate clap;
66
use anyhow::{bail, Context};
77
use collector::api::collected;
88
use database::{pool::Connection, ArtifactId, Commit};
9-
use log::{debug, error};
9+
use log::debug;
1010
use std::collections::HashSet;
1111
use std::fs;
1212
use std::io::{stderr, Write};
@@ -162,54 +162,6 @@ where
162162
Ok(v)
163163
}
164164

165-
fn bench_next(
166-
rt: &mut Runtime,
167-
site_url: &str,
168-
pool: &database::Pool,
169-
benchmarks: &[Benchmark],
170-
self_profile: bool,
171-
) -> anyhow::Result<()> {
172-
println!("processing commits");
173-
let client = reqwest::blocking::Client::new();
174-
let response: collector::api::next_commit::Response = client
175-
.get(&format!("{}/perf/next_commit", site_url))
176-
.send()?
177-
.json()?;
178-
let commit = if let Some(c) = response.commit {
179-
c
180-
} else {
181-
println!("no commit to benchmark");
182-
// no missing commits
183-
return Ok(());
184-
};
185-
186-
let commit = get_commit_or_fake_it(&commit)?;
187-
match Sysroot::install(commit.sha.to_string(), "x86_64-unknown-linux-gnu") {
188-
Ok(sysroot) => {
189-
let conn = rt.block_on(pool.connection());
190-
bench(
191-
rt,
192-
conn,
193-
&ArtifactId::Commit(commit),
194-
&BuildKind::all(),
195-
&RunKind::all(),
196-
Compiler::from_sysroot(&sysroot),
197-
&benchmarks,
198-
3,
199-
/* call_home */ true,
200-
self_profile,
201-
);
202-
}
203-
Err(err) => {
204-
error!("failed to install sysroot for {:?}: {:?}", commit, err);
205-
}
206-
}
207-
208-
client.post(&format!("{}/perf/onpush", site_url)).send()?;
209-
210-
Ok(())
211-
}
212-
213165
fn n_benchmarks_remaining(n: usize) -> String {
214166
let suffix = if n == 1 { "" } else { "s" };
215167
format!("{} benchmark{} remaining", n, suffix)
@@ -218,7 +170,15 @@ fn n_benchmarks_remaining(n: usize) -> String {
218170
struct BenchmarkErrors(usize);
219171

220172
impl BenchmarkErrors {
221-
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<()> {
222182
if self.0 > 0 {
223183
anyhow::bail!("{} benchmarks failed", self.0)
224184
}
@@ -238,7 +198,7 @@ fn bench(
238198
call_home: bool,
239199
self_profile: bool,
240200
) -> BenchmarkErrors {
241-
let mut errors_recorded = 0;
201+
let mut errors = BenchmarkErrors::new();
242202
eprintln!("Benchmarking {} for triple {}", cid, compiler.triple);
243203

244204
if call_home {
@@ -271,7 +231,7 @@ fn bench(
271231
"Note that this behavior is likely to change in the future \
272232
to collect and append the data instead."
273233
);
274-
return BenchmarkErrors(errors_recorded);
234+
return errors;
275235
}
276236
let interned_cid = rt.block_on(tx.conn().artifact_id(&cid));
277237

@@ -300,7 +260,7 @@ fn bench(
300260
"collector error: Failed to benchmark '{}', recorded: {}",
301261
benchmark.name, s
302262
);
303-
errors_recorded += 1;
263+
errors.incr();
304264
rt.block_on(tx.conn().record_error(
305265
interned_cid,
306266
benchmark.name.0.as_str(),
@@ -330,7 +290,7 @@ fn bench(
330290
// This ensures that we're good to go with the just updated data.
331291
conn.maybe_create_indices().await;
332292
});
333-
BenchmarkErrors(errors_recorded)
293+
errors
334294
}
335295

336296
fn get_benchmarks(
@@ -513,17 +473,6 @@ fn main_result() -> anyhow::Result<i32> {
513473
(@arg DB: --db +takes_value "Database output file")
514474
)
515475

516-
(@subcommand bench_test =>
517-
(about: "Benchmarks the most recent commit for testing purposes")
518-
519-
// Mandatory arguments: (none)
520-
521-
// Options
522-
(@arg DB: --db +takes_value "Database output file")
523-
(@arg EXCLUDE: --exclude +takes_value "Exclude benchmarks matching these")
524-
(@arg INCLUDE: --include +takes_value "Include benchmarks matching these")
525-
)
526-
527476
(@subcommand profile_local =>
528477
(about: "Profiles a local rustc with one of several profilers")
529478

@@ -547,6 +496,14 @@ fn main_result() -> anyhow::Result<i32> {
547496
'IncrFull', 'IncrUnchanged', 'IncrPatched', 'All'")
548497
(@arg RUSTDOC: --rustdoc +takes_value "The path to the local rustdoc to benchmark")
549498
)
499+
500+
(@subcommand install_next =>
501+
(about: "Installs the next commit for perf.rust-lang.org")
502+
503+
// Mandatory arguments: (none)
504+
505+
// Options: (none)
506+
)
550507
)
551508
.get_matches();
552509

@@ -587,7 +544,7 @@ fn main_result() -> anyhow::Result<i32> {
587544

588545
let benchmarks = get_benchmarks(&benchmark_dir, include, exclude)?;
589546

590-
bench(
547+
let res = bench(
591548
&mut rt,
592549
conn,
593550
&ArtifactId::Artifact(id.to_string()),
@@ -605,6 +562,7 @@ fn main_result() -> anyhow::Result<i32> {
605562
/* call_home */ false,
606563
self_profile,
607564
);
565+
res.fail_if_nonzero()?;
608566
Ok(0)
609567
}
610568

@@ -616,11 +574,45 @@ fn main_result() -> anyhow::Result<i32> {
616574
let db = sub_m.value_of("DB").unwrap_or(default_db);
617575
let self_profile = sub_m.is_present("SELF_PROFILE");
618576

577+
println!("processing commits");
578+
let client = reqwest::blocking::Client::new();
579+
let response: collector::api::next_commit::Response = client
580+
.get(&format!("{}/perf/next_commit", site_url))
581+
.send()?
582+
.json()?;
583+
let commit = if let Some(c) = response.commit {
584+
c
585+
} else {
586+
println!("no commit to benchmark");
587+
// no missing commits
588+
return Ok(0);
589+
};
590+
let commit = get_commit_or_fake_it(&commit)?;
591+
619592
let pool = database::Pool::open(db);
593+
let conn = rt.block_on(pool.connection());
594+
595+
let sysroot = Sysroot::install(commit.sha.to_string(), "x86_64-unknown-linux-gnu")
596+
.with_context(|| format!("failed to install sysroot for {:?}", commit))?;
620597

621598
let benchmarks = get_benchmarks(&benchmark_dir, None, None)?;
622599

623-
bench_next(&mut rt, &site_url, &pool, &benchmarks, self_profile)?;
600+
let res = bench(
601+
&mut rt,
602+
conn,
603+
&ArtifactId::Commit(commit),
604+
&BuildKind::all(),
605+
&RunKind::all(),
606+
Compiler::from_sysroot(&sysroot),
607+
&benchmarks,
608+
3,
609+
/* call_home */ true,
610+
self_profile,
611+
);
612+
613+
client.post(&format!("{}/perf/onpush", site_url)).send()?;
614+
615+
res.fail_if_nonzero()?;
624616
Ok(0)
625617
}
626618

@@ -677,7 +669,7 @@ fn main_result() -> anyhow::Result<i32> {
677669
let mut benchmarks = get_benchmarks(&benchmark_dir, None, None)?;
678670
benchmarks.retain(|b| b.supports_stable());
679671

680-
bench(
672+
let res = bench(
681673
&mut rt,
682674
conn,
683675
&ArtifactId::Artifact(toolchain.to_string()),
@@ -695,46 +687,7 @@ fn main_result() -> anyhow::Result<i32> {
695687
/* call_home */ false,
696688
/* self_profile */ false,
697689
);
698-
Ok(0)
699-
}
700-
701-
("bench_test", Some(sub_m)) => {
702-
// Mandatory arguments: (none)
703-
704-
// Options
705-
let db = sub_m.value_of("DB").unwrap_or(default_db);
706-
let exclude = sub_m.value_of("EXCLUDE");
707-
let include = sub_m.value_of("INCLUDE");
708-
709-
let pool = database::Pool::open(db);
710-
let conn = rt.block_on(pool.connection());
711-
712-
let last_sha = Command::new("git")
713-
.arg("ls-remote")
714-
.arg("https://github.com/rust-lang/rust.git")
715-
.arg("master")
716-
.output()
717-
.unwrap();
718-
let last_sha = String::from_utf8(last_sha.stdout).expect("utf8");
719-
let last_sha = last_sha.split_whitespace().next().expect(&last_sha);
720-
let commit = get_commit_or_fake_it(&last_sha).expect("success");
721-
let sysroot = Sysroot::install(commit.sha.to_string(), "x86_64-unknown-linux-gnu")?;
722-
723-
let benchmarks = get_benchmarks(&benchmark_dir, include, exclude)?;
724-
725-
let res = bench(
726-
&mut rt,
727-
conn,
728-
&ArtifactId::Commit(commit),
729-
&[BuildKind::Check, BuildKind::Doc], // no Debug or Opt builds
730-
&RunKind::all(),
731-
Compiler::from_sysroot(&sysroot),
732-
&benchmarks,
733-
1,
734-
/* call_home */ false,
735-
/* self_profile */ false,
736-
);
737-
res.fail_if_error()?;
690+
res.fail_if_nonzero()?;
738691
Ok(0)
739692
}
740693

@@ -767,18 +720,46 @@ fn main_result() -> anyhow::Result<i32> {
767720

768721
eprintln!("Profiling with {:?}", profiler);
769722

723+
let mut errors = BenchmarkErrors::new();
770724
for (i, benchmark) in benchmarks.iter().enumerate() {
771725
eprintln!("{}", n_benchmarks_remaining(benchmarks.len() - i));
772726
let mut processor = execute::ProfileProcessor::new(profiler, &out_dir, &id);
773727
let result =
774728
benchmark.measure(&mut processor, &build_kinds, &run_kinds, compiler, 1);
775729
if let Err(ref s) = result {
730+
errors.incr();
776731
eprintln!(
777732
"collector error: Failed to profile '{}' with {:?}, recorded: {:?}",
778733
benchmark.name, profiler, s
779734
);
780735
}
781736
}
737+
errors.fail_if_nonzero()?;
738+
Ok(0)
739+
}
740+
741+
("install_next", Some(_sub_m)) => {
742+
// Mandatory arguments: (none)
743+
744+
// Options: (none)
745+
746+
let last_sha = Command::new("git")
747+
.arg("ls-remote")
748+
.arg("https://github.com/rust-lang/rust.git")
749+
.arg("master")
750+
.output()
751+
.unwrap();
752+
let last_sha = String::from_utf8(last_sha.stdout).expect("utf8");
753+
let last_sha = last_sha.split_whitespace().next().expect(&last_sha);
754+
let commit = get_commit_or_fake_it(&last_sha).expect("success");
755+
let mut sysroot = Sysroot::install(commit.sha.to_string(), "x86_64-unknown-linux-gnu")?;
756+
sysroot.preserve(); // don't delete it
757+
758+
// Print the directory containing the toolchain.
759+
sysroot.rustc.pop();
760+
let s = format!("{:?}", sysroot.rustc);
761+
println!("{}", &s[1..s.len() - 1]);
762+
782763
Ok(0)
783764
}
784765

collector/src/sysroot.rs

+9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub struct Sysroot {
1919
pub rustdoc: PathBuf,
2020
pub cargo: PathBuf,
2121
pub triple: String,
22+
pub preserve: bool,
2223
}
2324

2425
impl Sysroot {
@@ -42,10 +43,17 @@ impl Sysroot {
4243

4344
Ok(sysroot)
4445
}
46+
47+
pub fn preserve(&mut self) {
48+
self.preserve = true;
49+
}
4550
}
4651

4752
impl Drop for Sysroot {
4853
fn drop(&mut self) {
54+
if self.preserve {
55+
return;
56+
}
4957
fs::remove_dir_all(format!("cache/{}", self.sha)).unwrap_or_else(|err| {
5058
log::info!(
5159
"failed to remove {:?}, please do so manually: {:?}",
@@ -121,6 +129,7 @@ impl SysrootDownload {
121129
cargo: sysroot_bin("cargo")?,
122130
sha: self.rust_sha,
123131
triple: self.triple,
132+
preserve: false,
124133
})
125134
}
126135

0 commit comments

Comments
 (0)