@@ -469,6 +469,21 @@ struct BenchRustcOption {
469
469
bench_rustc : bool ,
470
470
}
471
471
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
+
472
487
// For each subcommand we list the mandatory arguments in the required
473
488
// order, followed by the options in alphabetical order.
474
489
#[ derive( Debug , clap:: Subcommand ) ]
@@ -490,6 +505,9 @@ enum Commands {
490
505
/// faster.
491
506
#[ arg( long = "no-isolate" ) ]
492
507
no_isolate : bool ,
508
+
509
+ #[ command( flatten) ]
510
+ purge : PurgeOption ,
493
511
} ,
494
512
/// Benchmarks a local rustc
495
513
BenchLocal {
@@ -511,6 +529,9 @@ enum Commands {
511
529
512
530
#[ command( flatten) ]
513
531
self_profile : SelfProfileOption ,
532
+
533
+ #[ command( flatten) ]
534
+ purge : PurgeOption ,
514
535
} ,
515
536
516
537
/// Benchmarks the next commit or release for perf.rust-lang.org
@@ -642,6 +663,7 @@ fn main_result() -> anyhow::Result<i32> {
642
663
iterations,
643
664
db,
644
665
no_isolate,
666
+ purge,
645
667
} => {
646
668
log_db ( & db) ;
647
669
let toolchain = get_local_toolchain (
@@ -666,6 +688,8 @@ fn main_result() -> anyhow::Result<i32> {
666
688
isolation_mode,
667
689
) ?;
668
690
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 ) ) ;
669
693
670
694
let shared = SharedBenchmarkConfig {
671
695
artifact_id,
@@ -676,7 +700,7 @@ fn main_result() -> anyhow::Result<i32> {
676
700
filter : BenchmarkFilter :: new ( local. exclude , local. include ) ,
677
701
iterations,
678
702
} ;
679
- let conn = rt . block_on ( pool . connection ( ) ) ;
703
+
680
704
run_benchmarks ( & mut rt, conn, shared, None , Some ( config) ) ?;
681
705
Ok ( 0 )
682
706
}
@@ -687,6 +711,7 @@ fn main_result() -> anyhow::Result<i32> {
687
711
bench_rustc,
688
712
iterations,
689
713
self_profile,
714
+ purge,
690
715
} => {
691
716
log_db ( & db) ;
692
717
let profiles = opts. profiles . 0 ;
@@ -713,7 +738,9 @@ fn main_result() -> anyhow::Result<i32> {
713
738
benchmarks. retain ( |b| b. category ( ) . is_primary_or_secondary ( ) ) ;
714
739
715
740
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
+
717
744
let shared = SharedBenchmarkConfig {
718
745
toolchain,
719
746
artifact_id,
@@ -977,6 +1004,28 @@ fn log_db(db_option: &DbOption) {
977
1004
println ! ( "Using database `{}`" , db_option. db) ;
978
1005
}
979
1006
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
+
980
1029
/// Record a collection entry into the database, specifying which benchmark steps will be executed.
981
1030
async fn init_collection (
982
1031
connection : & mut dyn Connection ,
0 commit comments