Skip to content

Commit e201ed7

Browse files
committed
Add --purge=[old/failed] flag to bench_local and bench_runtime_local
1 parent b38e9e2 commit e201ed7

File tree

4 files changed

+73
-1
lines changed

4 files changed

+73
-1
lines changed

collector/src/bin/collector.rs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,21 @@ struct BenchRustcOption {
413413
bench_rustc: bool,
414414
}
415415

416+
#[derive(Clone, Debug, clap::ValueEnum)]
417+
enum PurgeMode {
418+
/// Purge all old data associated with the artifact
419+
Old,
420+
/// Purge old data of failed benchmarks associated with the artifact
421+
Failed,
422+
}
423+
424+
#[derive(Debug, clap::Args)]
425+
struct PurgeOption {
426+
/// Removes old data for the specified artifact prior to running the benchmarks.
427+
#[arg(long = "purge")]
428+
purge: Option<PurgeMode>,
429+
}
430+
416431
// For each subcommand we list the mandatory arguments in the required
417432
// order, followed by the options in alphabetical order.
418433
#[derive(Debug, clap::Subcommand)]
@@ -437,6 +452,9 @@ enum Commands {
437452
/// faster.
438453
#[arg(long = "no-isolate")]
439454
no_isolate: bool,
455+
456+
#[command(flatten)]
457+
purge: PurgeOption,
440458
},
441459

442460
/// Profiles a runtime benchmark.
@@ -493,6 +511,9 @@ enum Commands {
493511

494512
#[command(flatten)]
495513
self_profile: SelfProfileOption,
514+
515+
#[command(flatten)]
516+
purge: PurgeOption,
496517
},
497518

498519
/// Benchmarks the next commit or release for perf.rust-lang.org
@@ -629,6 +650,7 @@ fn main_result() -> anyhow::Result<i32> {
629650
iterations,
630651
db,
631652
no_isolate,
653+
purge,
632654
} => {
633655
log_db(&db);
634656
let toolchain = get_local_toolchain_for_runtime_benchmarks(&local, &target_triple)?;
@@ -642,6 +664,8 @@ fn main_result() -> anyhow::Result<i32> {
642664

643665
let mut conn = rt.block_on(pool.connection());
644666
let artifact_id = ArtifactId::Tag(toolchain.id.clone());
667+
rt.block_on(purge_old_data(conn.as_mut(), &artifact_id, purge.purge));
668+
645669
let runtime_suite = rt.block_on(load_runtime_benchmarks(
646670
conn.as_mut(),
647671
&runtime_benchmark_dir,
@@ -756,6 +780,7 @@ fn main_result() -> anyhow::Result<i32> {
756780
bench_rustc,
757781
iterations,
758782
self_profile,
783+
purge,
759784
} => {
760785
log_db(&db);
761786
let profiles = opts.profiles.0;
@@ -784,7 +809,9 @@ fn main_result() -> anyhow::Result<i32> {
784809
benchmarks.retain(|b| b.category().is_primary_or_secondary());
785810

786811
let artifact_id = ArtifactId::Tag(toolchain.id.clone());
787-
let conn = rt.block_on(pool.connection());
812+
let mut conn = rt.block_on(pool.connection());
813+
rt.block_on(purge_old_data(conn.as_mut(), &artifact_id, purge.purge));
814+
788815
let shared = SharedBenchmarkConfig {
789816
toolchain,
790817
artifact_id,
@@ -1132,6 +1159,28 @@ fn log_db(db_option: &DbOption) {
11321159
println!("Using database `{}`", db_option.db);
11331160
}
11341161

1162+
async fn purge_old_data(
1163+
conn: &mut dyn Connection,
1164+
artifact_id: &ArtifactId,
1165+
purge_mode: Option<PurgeMode>,
1166+
) {
1167+
match purge_mode {
1168+
Some(PurgeMode::Old) => {
1169+
// Delete everything associated with the artifact
1170+
conn.purge_artifact(artifact_id).await;
1171+
}
1172+
Some(PurgeMode::Failed) => {
1173+
// Delete all benchmarks that have an error for the given artifact
1174+
let artifact_row_id = conn.artifact_id(artifact_id).await;
1175+
let errors = conn.get_error(artifact_row_id).await;
1176+
for krate in errors.keys() {
1177+
conn.collector_remove_step(artifact_row_id, krate).await;
1178+
}
1179+
}
1180+
None => {}
1181+
}
1182+
}
1183+
11351184
/// Record a collection entry into the database, specifying which benchmark steps will be executed.
11361185
async fn init_collection(
11371186
connection: &mut dyn Connection,

database/src/pool.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ pub trait Connection: Send + Sync {
152152
async fn collector_start_step(&self, aid: ArtifactIdNumber, step: &str) -> bool;
153153
async fn collector_end_step(&self, aid: ArtifactIdNumber, step: &str);
154154

155+
async fn collector_remove_step(&self, aid: ArtifactIdNumber, step: &str);
156+
155157
async fn in_progress_artifacts(&self) -> Vec<ArtifactId>;
156158

157159
async fn in_progress_steps(&self, aid: &ArtifactId) -> Vec<Step>;

database/src/pool/postgres.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,16 @@ where
11341134
log::error!("did not end {} for {:?}", step, aid);
11351135
}
11361136
}
1137+
async fn collector_remove_step(&self, aid: ArtifactIdNumber, step: &str) {
1138+
self.conn()
1139+
.execute(
1140+
"delete from collector_progress \
1141+
where aid = $1 and step = $2;",
1142+
&[&(aid.0 as i32), &step],
1143+
)
1144+
.await
1145+
.unwrap();
1146+
}
11371147
async fn in_progress_artifacts(&self) -> Vec<ArtifactId> {
11381148
let rows = self
11391149
.conn()

database/src/pool/sqlite.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,17 @@ impl Connection for SqliteConnection {
10741074
log::error!("did not end {} for {:?}", step, aid);
10751075
}
10761076
}
1077+
1078+
async fn collector_remove_step(&self, aid: ArtifactIdNumber, step: &str) {
1079+
self.raw_ref()
1080+
.execute(
1081+
"delete from collector_progress \
1082+
where aid = ? and step = ?",
1083+
params![&aid.0, &step],
1084+
)
1085+
.unwrap();
1086+
}
1087+
10771088
async fn in_progress_artifacts(&self) -> Vec<ArtifactId> {
10781089
let conn = self.raw_ref();
10791090
let mut aids = conn

0 commit comments

Comments
 (0)