@@ -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.
11361185async fn init_collection (
11371186 connection : & mut dyn Connection ,
0 commit comments