Skip to content

Commit 3a1ba95

Browse files
committed
Add --purge=[old/failed] flag to bench_local and bench_runtime_local
1 parent 8aca666 commit 3a1ba95

File tree

4 files changed

+74
-2
lines changed

4 files changed

+74
-2
lines changed

collector/src/bin/collector.rs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,21 @@ struct BenchRustcOption {
469469
bench_rustc: bool,
470470
}
471471

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

512530
#[command(flatten)]
513531
self_profile: SelfProfileOption,
532+
533+
#[command(flatten)]
534+
purge: PurgeOption,
514535
},
515536

516537
/// Benchmarks the next commit or release for perf.rust-lang.org
@@ -642,6 +663,7 @@ fn main_result() -> anyhow::Result<i32> {
642663
iterations,
643664
db,
644665
no_isolate,
666+
purge,
645667
} => {
646668
log_db(&db);
647669
let toolchain = get_local_toolchain(
@@ -666,6 +688,8 @@ fn main_result() -> anyhow::Result<i32> {
666688
isolation_mode,
667689
)?;
668690
let artifact_id = ArtifactId::Tag(toolchain.id.clone());
691+
let mut conn = rt.block_on(pool.connection());
692+
rt.block_on(purge_old_data(conn.as_mut(), &artifact_id, purge.purge));
669693

670694
let shared = SharedBenchmarkConfig {
671695
artifact_id,
@@ -676,7 +700,7 @@ fn main_result() -> anyhow::Result<i32> {
676700
filter: BenchmarkFilter::new(local.exclude, local.include),
677701
iterations,
678702
};
679-
let conn = rt.block_on(pool.connection());
703+
680704
run_benchmarks(&mut rt, conn, shared, None, Some(config))?;
681705
Ok(0)
682706
}
@@ -687,6 +711,7 @@ fn main_result() -> anyhow::Result<i32> {
687711
bench_rustc,
688712
iterations,
689713
self_profile,
714+
purge,
690715
} => {
691716
log_db(&db);
692717
let profiles = opts.profiles.0;
@@ -713,7 +738,9 @@ fn main_result() -> anyhow::Result<i32> {
713738
benchmarks.retain(|b| b.category().is_primary_or_secondary());
714739

715740
let artifact_id = ArtifactId::Tag(toolchain.id.clone());
716-
let conn = rt.block_on(pool.connection());
741+
let mut conn = rt.block_on(pool.connection());
742+
rt.block_on(purge_old_data(conn.as_mut(), &artifact_id, purge.purge));
743+
717744
let shared = SharedBenchmarkConfig {
718745
toolchain,
719746
artifact_id,
@@ -977,6 +1004,28 @@ fn log_db(db_option: &DbOption) {
9771004
println!("Using database `{}`", db_option.db);
9781005
}
9791006

1007+
async fn purge_old_data(
1008+
conn: &mut dyn Connection,
1009+
artifact_id: &ArtifactId,
1010+
purge_mode: Option<PurgeMode>,
1011+
) {
1012+
match purge_mode {
1013+
Some(PurgeMode::Old) => {
1014+
// Delete everything associated with the artifact
1015+
conn.purge_artifact(artifact_id).await;
1016+
}
1017+
Some(PurgeMode::Failed) => {
1018+
// Delete all benchmarks that have an error for the given artifact
1019+
let artifact_row_id = conn.artifact_id(artifact_id).await;
1020+
let errors = conn.get_error(artifact_row_id).await;
1021+
for krate in errors.keys() {
1022+
conn.collector_remove_step(artifact_row_id, krate).await;
1023+
}
1024+
}
1025+
None => {}
1026+
}
1027+
}
1028+
9801029
/// Record a collection entry into the database, specifying which benchmark steps will be executed.
9811030
async fn init_collection(
9821031
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
@@ -1061,6 +1061,17 @@ impl Connection for SqliteConnection {
10611061
log::error!("did not end {} for {:?}", step, aid);
10621062
}
10631063
}
1064+
1065+
async fn collector_remove_step(&self, aid: ArtifactIdNumber, step: &str) {
1066+
self.raw_ref()
1067+
.execute(
1068+
"delete from collector_progress \
1069+
where aid = ? and step = ?",
1070+
params![&aid.0, &step],
1071+
)
1072+
.unwrap();
1073+
}
1074+
10641075
async fn in_progress_artifacts(&self) -> Vec<ArtifactId> {
10651076
let conn = self.raw_ref();
10661077
let mut aids = conn

0 commit comments

Comments
 (0)