@@ -6,7 +6,7 @@ extern crate clap;
6
6
use anyhow:: { bail, Context } ;
7
7
use collector:: api:: collected;
8
8
use database:: { pool:: Connection , ArtifactId , Commit } ;
9
- use log:: { debug, error } ;
9
+ use log:: debug;
10
10
use std:: collections:: HashSet ;
11
11
use std:: fs;
12
12
use std:: io:: { stderr, Write } ;
@@ -162,54 +162,6 @@ where
162
162
Ok ( v)
163
163
}
164
164
165
- fn bench_next (
166
- rt : & mut Runtime ,
167
- site_url : & str ,
168
- pool : & database:: Pool ,
169
- benchmarks : & [ Benchmark ] ,
170
- self_profile : bool ,
171
- ) -> anyhow:: Result < ( ) > {
172
- println ! ( "processing commits" ) ;
173
- let client = reqwest:: blocking:: Client :: new ( ) ;
174
- let response: collector:: api:: next_commit:: Response = client
175
- . get ( & format ! ( "{}/perf/next_commit" , site_url) )
176
- . send ( ) ?
177
- . json ( ) ?;
178
- let commit = if let Some ( c) = response. commit {
179
- c
180
- } else {
181
- println ! ( "no commit to benchmark" ) ;
182
- // no missing commits
183
- return Ok ( ( ) ) ;
184
- } ;
185
-
186
- let commit = get_commit_or_fake_it ( & commit) ?;
187
- match Sysroot :: install ( commit. sha . to_string ( ) , "x86_64-unknown-linux-gnu" ) {
188
- Ok ( sysroot) => {
189
- let conn = rt. block_on ( pool. connection ( ) ) ;
190
- bench (
191
- rt,
192
- conn,
193
- & ArtifactId :: Commit ( commit) ,
194
- & BuildKind :: all ( ) ,
195
- & RunKind :: all ( ) ,
196
- Compiler :: from_sysroot ( & sysroot) ,
197
- & benchmarks,
198
- 3 ,
199
- /* call_home */ true ,
200
- self_profile,
201
- ) ;
202
- }
203
- Err ( err) => {
204
- error ! ( "failed to install sysroot for {:?}: {:?}" , commit, err) ;
205
- }
206
- }
207
-
208
- client. post ( & format ! ( "{}/perf/onpush" , site_url) ) . send ( ) ?;
209
-
210
- Ok ( ( ) )
211
- }
212
-
213
165
fn n_benchmarks_remaining ( n : usize ) -> String {
214
166
let suffix = if n == 1 { "" } else { "s" } ;
215
167
format ! ( "{} benchmark{} remaining" , n, suffix)
@@ -218,7 +170,15 @@ fn n_benchmarks_remaining(n: usize) -> String {
218
170
struct BenchmarkErrors ( usize ) ;
219
171
220
172
impl BenchmarkErrors {
221
- fn fail_if_error ( self ) -> anyhow:: Result < ( ) > {
173
+ fn new ( ) -> BenchmarkErrors {
174
+ BenchmarkErrors ( 0 )
175
+ }
176
+
177
+ fn incr ( & mut self ) {
178
+ self . 0 += 1 ;
179
+ }
180
+
181
+ fn fail_if_nonzero ( self ) -> anyhow:: Result < ( ) > {
222
182
if self . 0 > 0 {
223
183
anyhow:: bail!( "{} benchmarks failed" , self . 0 )
224
184
}
@@ -238,7 +198,7 @@ fn bench(
238
198
call_home : bool ,
239
199
self_profile : bool ,
240
200
) -> BenchmarkErrors {
241
- let mut errors_recorded = 0 ;
201
+ let mut errors = BenchmarkErrors :: new ( ) ;
242
202
eprintln ! ( "Benchmarking {} for triple {}" , cid, compiler. triple) ;
243
203
244
204
if call_home {
@@ -271,7 +231,7 @@ fn bench(
271
231
"Note that this behavior is likely to change in the future \
272
232
to collect and append the data instead."
273
233
) ;
274
- return BenchmarkErrors ( errors_recorded ) ;
234
+ return errors ;
275
235
}
276
236
let interned_cid = rt. block_on ( tx. conn ( ) . artifact_id ( & cid) ) ;
277
237
@@ -300,7 +260,7 @@ fn bench(
300
260
"collector error: Failed to benchmark '{}', recorded: {}" ,
301
261
benchmark. name, s
302
262
) ;
303
- errors_recorded += 1 ;
263
+ errors . incr ( ) ;
304
264
rt. block_on ( tx. conn ( ) . record_error (
305
265
interned_cid,
306
266
benchmark. name . 0 . as_str ( ) ,
@@ -330,7 +290,7 @@ fn bench(
330
290
// This ensures that we're good to go with the just updated data.
331
291
conn. maybe_create_indices ( ) . await ;
332
292
} ) ;
333
- BenchmarkErrors ( errors_recorded )
293
+ errors
334
294
}
335
295
336
296
fn get_benchmarks (
@@ -513,17 +473,6 @@ fn main_result() -> anyhow::Result<i32> {
513
473
( @arg DB : --db +takes_value "Database output file" )
514
474
)
515
475
516
- ( @subcommand bench_test =>
517
- ( about: "Benchmarks the most recent commit for testing purposes" )
518
-
519
- // Mandatory arguments: (none)
520
-
521
- // Options
522
- ( @arg DB : --db +takes_value "Database output file" )
523
- ( @arg EXCLUDE : --exclude +takes_value "Exclude benchmarks matching these" )
524
- ( @arg INCLUDE : --include +takes_value "Include benchmarks matching these" )
525
- )
526
-
527
476
( @subcommand profile_local =>
528
477
( about: "Profiles a local rustc with one of several profilers" )
529
478
@@ -547,6 +496,14 @@ fn main_result() -> anyhow::Result<i32> {
547
496
'IncrFull', 'IncrUnchanged', 'IncrPatched', 'All'")
548
497
( @arg RUSTDOC : --rustdoc +takes_value "The path to the local rustdoc to benchmark" )
549
498
)
499
+
500
+ ( @subcommand install_next =>
501
+ ( about: "Installs the next commit for perf.rust-lang.org" )
502
+
503
+ // Mandatory arguments: (none)
504
+
505
+ // Options: (none)
506
+ )
550
507
)
551
508
. get_matches ( ) ;
552
509
@@ -587,7 +544,7 @@ fn main_result() -> anyhow::Result<i32> {
587
544
588
545
let benchmarks = get_benchmarks ( & benchmark_dir, include, exclude) ?;
589
546
590
- bench (
547
+ let res = bench (
591
548
& mut rt,
592
549
conn,
593
550
& ArtifactId :: Artifact ( id. to_string ( ) ) ,
@@ -605,6 +562,7 @@ fn main_result() -> anyhow::Result<i32> {
605
562
/* call_home */ false ,
606
563
self_profile,
607
564
) ;
565
+ res. fail_if_nonzero ( ) ?;
608
566
Ok ( 0 )
609
567
}
610
568
@@ -616,11 +574,45 @@ fn main_result() -> anyhow::Result<i32> {
616
574
let db = sub_m. value_of ( "DB" ) . unwrap_or ( default_db) ;
617
575
let self_profile = sub_m. is_present ( "SELF_PROFILE" ) ;
618
576
577
+ println ! ( "processing commits" ) ;
578
+ let client = reqwest:: blocking:: Client :: new ( ) ;
579
+ let response: collector:: api:: next_commit:: Response = client
580
+ . get ( & format ! ( "{}/perf/next_commit" , site_url) )
581
+ . send ( ) ?
582
+ . json ( ) ?;
583
+ let commit = if let Some ( c) = response. commit {
584
+ c
585
+ } else {
586
+ println ! ( "no commit to benchmark" ) ;
587
+ // no missing commits
588
+ return Ok ( 0 ) ;
589
+ } ;
590
+ let commit = get_commit_or_fake_it ( & commit) ?;
591
+
619
592
let pool = database:: Pool :: open ( db) ;
593
+ let conn = rt. block_on ( pool. connection ( ) ) ;
594
+
595
+ let sysroot = Sysroot :: install ( commit. sha . to_string ( ) , "x86_64-unknown-linux-gnu" )
596
+ . with_context ( || format ! ( "failed to install sysroot for {:?}" , commit) ) ?;
620
597
621
598
let benchmarks = get_benchmarks ( & benchmark_dir, None , None ) ?;
622
599
623
- bench_next ( & mut rt, & site_url, & pool, & benchmarks, self_profile) ?;
600
+ let res = bench (
601
+ & mut rt,
602
+ conn,
603
+ & ArtifactId :: Commit ( commit) ,
604
+ & BuildKind :: all ( ) ,
605
+ & RunKind :: all ( ) ,
606
+ Compiler :: from_sysroot ( & sysroot) ,
607
+ & benchmarks,
608
+ 3 ,
609
+ /* call_home */ true ,
610
+ self_profile,
611
+ ) ;
612
+
613
+ client. post ( & format ! ( "{}/perf/onpush" , site_url) ) . send ( ) ?;
614
+
615
+ res. fail_if_nonzero ( ) ?;
624
616
Ok ( 0 )
625
617
}
626
618
@@ -677,7 +669,7 @@ fn main_result() -> anyhow::Result<i32> {
677
669
let mut benchmarks = get_benchmarks ( & benchmark_dir, None , None ) ?;
678
670
benchmarks. retain ( |b| b. supports_stable ( ) ) ;
679
671
680
- bench (
672
+ let res = bench (
681
673
& mut rt,
682
674
conn,
683
675
& ArtifactId :: Artifact ( toolchain. to_string ( ) ) ,
@@ -695,46 +687,7 @@ fn main_result() -> anyhow::Result<i32> {
695
687
/* call_home */ false ,
696
688
/* self_profile */ false ,
697
689
) ;
698
- Ok ( 0 )
699
- }
700
-
701
- ( "bench_test" , Some ( sub_m) ) => {
702
- // Mandatory arguments: (none)
703
-
704
- // Options
705
- let db = sub_m. value_of ( "DB" ) . unwrap_or ( default_db) ;
706
- let exclude = sub_m. value_of ( "EXCLUDE" ) ;
707
- let include = sub_m. value_of ( "INCLUDE" ) ;
708
-
709
- let pool = database:: Pool :: open ( db) ;
710
- let conn = rt. block_on ( pool. connection ( ) ) ;
711
-
712
- let last_sha = Command :: new ( "git" )
713
- . arg ( "ls-remote" )
714
- . arg ( "https://github.com/rust-lang/rust.git" )
715
- . arg ( "master" )
716
- . output ( )
717
- . unwrap ( ) ;
718
- let last_sha = String :: from_utf8 ( last_sha. stdout ) . expect ( "utf8" ) ;
719
- let last_sha = last_sha. split_whitespace ( ) . next ( ) . expect ( & last_sha) ;
720
- let commit = get_commit_or_fake_it ( & last_sha) . expect ( "success" ) ;
721
- let sysroot = Sysroot :: install ( commit. sha . to_string ( ) , "x86_64-unknown-linux-gnu" ) ?;
722
-
723
- let benchmarks = get_benchmarks ( & benchmark_dir, include, exclude) ?;
724
-
725
- let res = bench (
726
- & mut rt,
727
- conn,
728
- & ArtifactId :: Commit ( commit) ,
729
- & [ BuildKind :: Check , BuildKind :: Doc ] , // no Debug or Opt builds
730
- & RunKind :: all ( ) ,
731
- Compiler :: from_sysroot ( & sysroot) ,
732
- & benchmarks,
733
- 1 ,
734
- /* call_home */ false ,
735
- /* self_profile */ false ,
736
- ) ;
737
- res. fail_if_error ( ) ?;
690
+ res. fail_if_nonzero ( ) ?;
738
691
Ok ( 0 )
739
692
}
740
693
@@ -767,18 +720,46 @@ fn main_result() -> anyhow::Result<i32> {
767
720
768
721
eprintln ! ( "Profiling with {:?}" , profiler) ;
769
722
723
+ let mut errors = BenchmarkErrors :: new ( ) ;
770
724
for ( i, benchmark) in benchmarks. iter ( ) . enumerate ( ) {
771
725
eprintln ! ( "{}" , n_benchmarks_remaining( benchmarks. len( ) - i) ) ;
772
726
let mut processor = execute:: ProfileProcessor :: new ( profiler, & out_dir, & id) ;
773
727
let result =
774
728
benchmark. measure ( & mut processor, & build_kinds, & run_kinds, compiler, 1 ) ;
775
729
if let Err ( ref s) = result {
730
+ errors. incr ( ) ;
776
731
eprintln ! (
777
732
"collector error: Failed to profile '{}' with {:?}, recorded: {:?}" ,
778
733
benchmark. name, profiler, s
779
734
) ;
780
735
}
781
736
}
737
+ errors. fail_if_nonzero ( ) ?;
738
+ Ok ( 0 )
739
+ }
740
+
741
+ ( "install_next" , Some ( _sub_m) ) => {
742
+ // Mandatory arguments: (none)
743
+
744
+ // Options: (none)
745
+
746
+ let last_sha = Command :: new ( "git" )
747
+ . arg ( "ls-remote" )
748
+ . arg ( "https://github.com/rust-lang/rust.git" )
749
+ . arg ( "master" )
750
+ . output ( )
751
+ . unwrap ( ) ;
752
+ let last_sha = String :: from_utf8 ( last_sha. stdout ) . expect ( "utf8" ) ;
753
+ let last_sha = last_sha. split_whitespace ( ) . next ( ) . expect ( & last_sha) ;
754
+ let commit = get_commit_or_fake_it ( & last_sha) . expect ( "success" ) ;
755
+ let mut sysroot = Sysroot :: install ( commit. sha . to_string ( ) , "x86_64-unknown-linux-gnu" ) ?;
756
+ sysroot. preserve ( ) ; // don't delete it
757
+
758
+ // Print the directory containing the toolchain.
759
+ sysroot. rustc . pop ( ) ;
760
+ let s = format ! ( "{:?}" , sysroot. rustc) ;
761
+ println ! ( "{}" , & s[ 1 ..s. len( ) - 1 ] ) ;
762
+
782
763
Ok ( 0 )
783
764
}
784
765
0 commit comments