@@ -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
@@ -552,6 +573,15 @@ enum Commands {
552573
553574 /// Download a crate into collector/benchmarks.
554575 Download ( DownloadCommand ) ,
576+
577+ /// Removes all data associated with artifact(s) with the given name.
578+ PurgeArtifact {
579+ /// Name of the artifact.
580+ name : String ,
581+
582+ #[ command( flatten) ]
583+ db : DbOption ,
584+ } ,
555585}
556586
557587#[ derive( Debug , clap:: Parser ) ]
@@ -620,6 +650,7 @@ fn main_result() -> anyhow::Result<i32> {
620650 iterations,
621651 db,
622652 no_isolate,
653+ purge,
623654 } => {
624655 log_db ( & db) ;
625656 let toolchain = get_local_toolchain_for_runtime_benchmarks ( & local, & target_triple) ?;
@@ -633,6 +664,8 @@ fn main_result() -> anyhow::Result<i32> {
633664
634665 let mut conn = rt. block_on ( pool. connection ( ) ) ;
635666 let artifact_id = ArtifactId :: Tag ( toolchain. id . clone ( ) ) ;
667+ rt. block_on ( purge_old_data ( conn. as_mut ( ) , & artifact_id, purge. purge ) ) ;
668+
636669 let runtime_suite = rt. block_on ( load_runtime_benchmarks (
637670 conn. as_mut ( ) ,
638671 & runtime_benchmark_dir,
@@ -747,6 +780,7 @@ fn main_result() -> anyhow::Result<i32> {
747780 bench_rustc,
748781 iterations,
749782 self_profile,
783+ purge,
750784 } => {
751785 log_db ( & db) ;
752786 let profiles = opts. profiles . 0 ;
@@ -775,7 +809,9 @@ fn main_result() -> anyhow::Result<i32> {
775809 benchmarks. retain ( |b| b. category ( ) . is_primary_or_secondary ( ) ) ;
776810
777811 let artifact_id = ArtifactId :: Tag ( toolchain. id . clone ( ) ) ;
778- 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+
779815 let shared = SharedBenchmarkConfig {
780816 toolchain,
781817 artifact_id,
@@ -1057,6 +1093,14 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
10571093 ) ;
10581094 Ok ( 0 )
10591095 }
1096+ Commands :: PurgeArtifact { name, db } => {
1097+ let pool = Pool :: open ( & db. db ) ;
1098+ let conn = rt. block_on ( pool. connection ( ) ) ;
1099+ rt. block_on ( conn. purge_artifact ( & ArtifactId :: Tag ( name. clone ( ) ) ) ) ;
1100+
1101+ println ! ( "Data of artifact {name} were removed" ) ;
1102+ Ok ( 0 )
1103+ }
10601104 }
10611105}
10621106
@@ -1115,6 +1159,28 @@ fn log_db(db_option: &DbOption) {
11151159 println ! ( "Using database `{}`" , db_option. db) ;
11161160}
11171161
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+
11181184/// Record a collection entry into the database, specifying which benchmark steps will be executed.
11191185async fn init_collection (
11201186 connection : & mut dyn Connection ,
0 commit comments