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