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