@@ -413,6 +413,21 @@ struct BenchRustcOption {
413
413
bench_rustc : bool ,
414
414
}
415
415
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
+
416
431
// For each subcommand we list the mandatory arguments in the required
417
432
// order, followed by the options in alphabetical order.
418
433
#[ derive( Debug , clap:: Subcommand ) ]
@@ -437,6 +452,9 @@ enum Commands {
437
452
/// faster.
438
453
#[ arg( long = "no-isolate" ) ]
439
454
no_isolate : bool ,
455
+
456
+ #[ command( flatten) ]
457
+ purge : PurgeOption ,
440
458
} ,
441
459
442
460
/// Profiles a runtime benchmark.
@@ -493,6 +511,9 @@ enum Commands {
493
511
494
512
#[ command( flatten) ]
495
513
self_profile : SelfProfileOption ,
514
+
515
+ #[ command( flatten) ]
516
+ purge : PurgeOption ,
496
517
} ,
497
518
498
519
/// Benchmarks the next commit or release for perf.rust-lang.org
@@ -629,6 +650,7 @@ fn main_result() -> anyhow::Result<i32> {
629
650
iterations,
630
651
db,
631
652
no_isolate,
653
+ purge,
632
654
} => {
633
655
log_db ( & db) ;
634
656
let toolchain = get_local_toolchain_for_runtime_benchmarks ( & local, & target_triple) ?;
@@ -642,6 +664,8 @@ fn main_result() -> anyhow::Result<i32> {
642
664
643
665
let mut conn = rt. block_on ( pool. connection ( ) ) ;
644
666
let artifact_id = ArtifactId :: Tag ( toolchain. id . clone ( ) ) ;
667
+ rt. block_on ( purge_old_data ( conn. as_mut ( ) , & artifact_id, purge. purge ) ) ;
668
+
645
669
let runtime_suite = rt. block_on ( load_runtime_benchmarks (
646
670
conn. as_mut ( ) ,
647
671
& runtime_benchmark_dir,
@@ -756,6 +780,7 @@ fn main_result() -> anyhow::Result<i32> {
756
780
bench_rustc,
757
781
iterations,
758
782
self_profile,
783
+ purge,
759
784
} => {
760
785
log_db ( & db) ;
761
786
let profiles = opts. profiles . 0 ;
@@ -784,7 +809,9 @@ fn main_result() -> anyhow::Result<i32> {
784
809
benchmarks. retain ( |b| b. category ( ) . is_primary_or_secondary ( ) ) ;
785
810
786
811
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
+
788
815
let shared = SharedBenchmarkConfig {
789
816
toolchain,
790
817
artifact_id,
@@ -1132,6 +1159,28 @@ fn log_db(db_option: &DbOption) {
1132
1159
println ! ( "Using database `{}`" , db_option. db) ;
1133
1160
}
1134
1161
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
+
1135
1184
/// Record a collection entry into the database, specifying which benchmark steps will be executed.
1136
1185
async fn init_collection (
1137
1186
connection : & mut dyn Connection ,
0 commit comments