@@ -6,7 +6,7 @@ extern crate clap;
66use anyhow:: { bail, Context } ;
77use collector:: api:: collected;
88use database:: { pool:: Connection , ArtifactId , Commit } ;
9- use log:: { debug, error } ;
9+ use log:: debug;
1010use std:: collections:: HashSet ;
1111use std:: fs;
1212use std:: io:: { stderr, Write } ;
@@ -162,54 +162,6 @@ where
162162 Ok ( v)
163163}
164164
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-
213165fn n_benchmarks_remaining ( n : usize ) -> String {
214166 let suffix = if n == 1 { "" } else { "s" } ;
215167 format ! ( "{} benchmark{} remaining" , n, suffix)
@@ -218,7 +170,15 @@ fn n_benchmarks_remaining(n: usize) -> String {
218170struct BenchmarkErrors ( usize ) ;
219171
220172impl 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 < ( ) > {
222182 if self . 0 > 0 {
223183 anyhow:: bail!( "{} benchmarks failed" , self . 0 )
224184 }
@@ -238,7 +198,7 @@ fn bench(
238198 call_home : bool ,
239199 self_profile : bool ,
240200) -> BenchmarkErrors {
241- let mut errors_recorded = 0 ;
201+ let mut errors = BenchmarkErrors :: new ( ) ;
242202 eprintln ! ( "Benchmarking {} for triple {}" , cid, compiler. triple) ;
243203
244204 if call_home {
@@ -271,7 +231,7 @@ fn bench(
271231 "Note that this behavior is likely to change in the future \
272232 to collect and append the data instead."
273233 ) ;
274- return BenchmarkErrors ( errors_recorded ) ;
234+ return errors ;
275235 }
276236 let interned_cid = rt. block_on ( tx. conn ( ) . artifact_id ( & cid) ) ;
277237
@@ -300,7 +260,7 @@ fn bench(
300260 "collector error: Failed to benchmark '{}', recorded: {}" ,
301261 benchmark. name, s
302262 ) ;
303- errors_recorded += 1 ;
263+ errors . incr ( ) ;
304264 rt. block_on ( tx. conn ( ) . record_error (
305265 interned_cid,
306266 benchmark. name . 0 . as_str ( ) ,
@@ -330,7 +290,7 @@ fn bench(
330290 // This ensures that we're good to go with the just updated data.
331291 conn. maybe_create_indices ( ) . await ;
332292 } ) ;
333- BenchmarkErrors ( errors_recorded )
293+ errors
334294}
335295
336296fn get_benchmarks (
@@ -513,17 +473,6 @@ fn main_result() -> anyhow::Result<i32> {
513473 ( @arg DB : --db +takes_value "Database output file" )
514474 )
515475
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-
527476 ( @subcommand profile_local =>
528477 ( about: "Profiles a local rustc with one of several profilers" )
529478
@@ -547,6 +496,14 @@ fn main_result() -> anyhow::Result<i32> {
547496 'IncrFull', 'IncrUnchanged', 'IncrPatched', 'All'")
548497 ( @arg RUSTDOC : --rustdoc +takes_value "The path to the local rustdoc to benchmark" )
549498 )
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+ )
550507 )
551508 . get_matches ( ) ;
552509
@@ -587,7 +544,7 @@ fn main_result() -> anyhow::Result<i32> {
587544
588545 let benchmarks = get_benchmarks ( & benchmark_dir, include, exclude) ?;
589546
590- bench (
547+ let res = bench (
591548 & mut rt,
592549 conn,
593550 & ArtifactId :: Artifact ( id. to_string ( ) ) ,
@@ -605,6 +562,7 @@ fn main_result() -> anyhow::Result<i32> {
605562 /* call_home */ false ,
606563 self_profile,
607564 ) ;
565+ res. fail_if_nonzero ( ) ?;
608566 Ok ( 0 )
609567 }
610568
@@ -616,11 +574,45 @@ fn main_result() -> anyhow::Result<i32> {
616574 let db = sub_m. value_of ( "DB" ) . unwrap_or ( default_db) ;
617575 let self_profile = sub_m. is_present ( "SELF_PROFILE" ) ;
618576
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+
619592 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) ) ?;
620597
621598 let benchmarks = get_benchmarks ( & benchmark_dir, None , None ) ?;
622599
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 ( ) ?;
624616 Ok ( 0 )
625617 }
626618
@@ -677,7 +669,7 @@ fn main_result() -> anyhow::Result<i32> {
677669 let mut benchmarks = get_benchmarks ( & benchmark_dir, None , None ) ?;
678670 benchmarks. retain ( |b| b. supports_stable ( ) ) ;
679671
680- bench (
672+ let res = bench (
681673 & mut rt,
682674 conn,
683675 & ArtifactId :: Artifact ( toolchain. to_string ( ) ) ,
@@ -695,46 +687,7 @@ fn main_result() -> anyhow::Result<i32> {
695687 /* call_home */ false ,
696688 /* self_profile */ false ,
697689 ) ;
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 ( ) ?;
738691 Ok ( 0 )
739692 }
740693
@@ -767,18 +720,46 @@ fn main_result() -> anyhow::Result<i32> {
767720
768721 eprintln ! ( "Profiling with {:?}" , profiler) ;
769722
723+ let mut errors = BenchmarkErrors :: new ( ) ;
770724 for ( i, benchmark) in benchmarks. iter ( ) . enumerate ( ) {
771725 eprintln ! ( "{}" , n_benchmarks_remaining( benchmarks. len( ) - i) ) ;
772726 let mut processor = execute:: ProfileProcessor :: new ( profiler, & out_dir, & id) ;
773727 let result =
774728 benchmark. measure ( & mut processor, & build_kinds, & run_kinds, compiler, 1 ) ;
775729 if let Err ( ref s) = result {
730+ errors. incr ( ) ;
776731 eprintln ! (
777732 "collector error: Failed to profile '{}' with {:?}, recorded: {:?}" ,
778733 benchmark. name, profiler, s
779734 ) ;
780735 }
781736 }
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+
782763 Ok ( 0 )
783764 }
784765
0 commit comments