Skip to content

Commit c160a58

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

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
@@ -470,6 +470,21 @@ struct BenchRustcOption {
470470
bench_rustc: bool,
471471
}
472472

473+
#[derive(Clone, Debug, clap::ValueEnum)]
474+
enum PurgeMode {
475+
/// Purge all old data associated with the artifact
476+
Old,
477+
/// Purge old data of failed benchmarks associated with the artifact
478+
Failed,
479+
}
480+
481+
#[derive(Debug, clap::Args)]
482+
struct PurgeOption {
483+
/// Removes old data for the specified artifact prior to running the benchmarks.
484+
#[arg(long = "purge")]
485+
purge: Option<PurgeMode>,
486+
}
487+
473488
// For each subcommand we list the mandatory arguments in the required
474489
// order, followed by the options in alphabetical order.
475490
#[derive(Debug, clap::Subcommand)]
@@ -491,6 +506,9 @@ enum Commands {
491506
/// faster.
492507
#[arg(long = "no-isolate")]
493508
no_isolate: bool,
509+
510+
#[command(flatten)]
511+
purge: PurgeOption,
494512
},
495513
/// Benchmarks a local rustc
496514
BenchLocal {
@@ -512,6 +530,9 @@ enum Commands {
512530

513531
#[command(flatten)]
514532
self_profile: SelfProfileOption,
533+
534+
#[command(flatten)]
535+
purge: PurgeOption,
515536
},
516537

517538
/// Benchmarks the next commit or release for perf.rust-lang.org
@@ -647,6 +668,7 @@ fn main_result() -> anyhow::Result<i32> {
647668
iterations,
648669
db,
649670
no_isolate,
671+
purge,
650672
} => {
651673
log_db(&db);
652674
let toolchain = get_local_toolchain(
@@ -668,6 +690,8 @@ fn main_result() -> anyhow::Result<i32> {
668690

669691
let mut conn = rt.block_on(pool.connection());
670692
let artifact_id = ArtifactId::Tag(toolchain.id.clone());
693+
rt.block_on(purge_old_data(conn.as_mut(), &artifact_id, purge.purge));
694+
671695
let runtime_suite = rt.block_on(load_runtime_benchmarks(
672696
conn.as_mut(),
673697
&runtime_benchmark_dir,
@@ -695,6 +719,7 @@ fn main_result() -> anyhow::Result<i32> {
695719
bench_rustc,
696720
iterations,
697721
self_profile,
722+
purge,
698723
} => {
699724
log_db(&db);
700725
let profiles = opts.profiles.0;
@@ -721,7 +746,9 @@ fn main_result() -> anyhow::Result<i32> {
721746
benchmarks.retain(|b| b.category().is_primary_or_secondary());
722747

723748
let artifact_id = ArtifactId::Tag(toolchain.id.clone());
724-
let conn = rt.block_on(pool.connection());
749+
let mut conn = rt.block_on(pool.connection());
750+
rt.block_on(purge_old_data(conn.as_mut(), &artifact_id, purge.purge));
751+
725752
let shared = SharedBenchmarkConfig {
726753
toolchain,
727754
artifact_id,
@@ -1020,6 +1047,28 @@ fn log_db(db_option: &DbOption) {
10201047
println!("Using database `{}`", db_option.db);
10211048
}
10221049

1050+
async fn purge_old_data(
1051+
conn: &mut dyn Connection,
1052+
artifact_id: &ArtifactId,
1053+
purge_mode: Option<PurgeMode>,
1054+
) {
1055+
match purge_mode {
1056+
Some(PurgeMode::Old) => {
1057+
// Delete everything associated with the artifact
1058+
conn.purge_artifact(artifact_id).await;
1059+
}
1060+
Some(PurgeMode::Failed) => {
1061+
// Delete all benchmarks that have an error for the given artifact
1062+
let artifact_row_id = conn.artifact_id(artifact_id).await;
1063+
let errors = conn.get_error(artifact_row_id).await;
1064+
for krate in errors.keys() {
1065+
conn.collector_remove_step(artifact_row_id, krate).await;
1066+
}
1067+
}
1068+
None => {}
1069+
}
1070+
}
1071+
10231072
/// Record a collection entry into the database, specifying which benchmark steps will be executed.
10241073
async fn init_collection(
10251074
connection: &mut dyn Connection,

database/src/pool.rs

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

152+
async fn collector_remove_step(&self, aid: ArtifactIdNumber, step: &str);
153+
152154
async fn in_progress_artifacts(&self) -> Vec<ArtifactId>;
153155

154156
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
@@ -1117,6 +1117,16 @@ where
11171117
log::error!("did not end {} for {:?}", step, aid);
11181118
}
11191119
}
1120+
async fn collector_remove_step(&self, aid: ArtifactIdNumber, step: &str) {
1121+
self.conn()
1122+
.execute(
1123+
"delete from collector_progress \
1124+
where aid = $1 and step = $2;",
1125+
&[&(aid.0 as i32), &step],
1126+
)
1127+
.await
1128+
.unwrap();
1129+
}
11201130
async fn in_progress_artifacts(&self) -> Vec<ArtifactId> {
11211131
let rows = self
11221132
.conn()

database/src/pool/sqlite.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,17 @@ impl Connection for SqliteConnection {
10621062
log::error!("did not end {} for {:?}", step, aid);
10631063
}
10641064
}
1065+
1066+
async fn collector_remove_step(&self, aid: ArtifactIdNumber, step: &str) {
1067+
self.raw_ref()
1068+
.execute(
1069+
"delete from collector_progress \
1070+
where aid = ? and step = ?",
1071+
params![&aid.0, &step],
1072+
)
1073+
.unwrap();
1074+
}
1075+
10651076
async fn in_progress_artifacts(&self) -> Vec<ArtifactId> {
10661077
let conn = self.raw_ref();
10671078
let mut aids = conn

0 commit comments

Comments
 (0)