@@ -5,8 +5,29 @@ use crate::core::build_steps::tool::RustcPerf;
55use crate :: core:: builder:: Builder ;
66use crate :: core:: config:: DebuginfoLevel ;
77
8+ /// Performs profiling or benchmarking with [`rustc-perf`](https://github.com/rust-lang/rustc-perf)
9+ /// using a locally built compiler.
10+ #[ derive( Debug , Clone , clap:: Parser ) ]
11+ pub struct PerfArgs {
12+ #[ clap( subcommand) ]
13+ cmd : PerfCommand ,
14+ }
15+
16+ #[ derive( Debug , Clone , clap:: Parser ) ]
17+ enum PerfCommand {
18+ /// Run `profile_local eprintln`.
19+ /// This executes the compiler on the given benchmarks and stores its stderr output.
20+ Eprintln ,
21+ }
22+
23+ impl Default for PerfArgs {
24+ fn default ( ) -> Self {
25+ Self { cmd : PerfCommand :: Eprintln }
26+ }
27+ }
28+
829/// Performs profiling using `rustc-perf` on a built version of the compiler.
9- pub fn perf ( builder : & Builder < ' _ > ) {
30+ pub fn perf ( builder : & Builder < ' _ > , args : & PerfArgs ) {
1031 let collector = builder. ensure ( RustcPerf {
1132 compiler : builder. compiler ( 0 , builder. config . build ) ,
1233 target : builder. config . build ,
@@ -25,21 +46,19 @@ Consider setting `rust.debuginfo-level = 1` in `config.toml`."#);
2546 let results_dir = builder. build . tempdir ( ) . join ( "rustc-perf" ) ;
2647
2748 let mut cmd = Command :: new ( collector) ;
28- let cmd = cmd
29- . arg ( "profile_local" )
30- . arg ( "eprintln" )
31- . arg ( "--out-dir" )
32- . arg ( & results_dir)
33- . arg ( "--include" )
34- . arg ( "helloworld" )
35- . arg ( & rustc) ;
49+ match args. cmd {
50+ PerfCommand :: Eprintln => {
51+ cmd. arg ( "profile_local" ) . arg ( "eprintln" ) ;
52+ }
53+ }
54+ cmd. arg ( "--out-dir" ) . arg ( & results_dir) . arg ( "--include" ) . arg ( "helloworld" ) . arg ( & rustc) ;
3655
3756 builder. info ( & format ! ( "Running `rustc-perf` using `{}`" , rustc. display( ) ) ) ;
3857
3958 // We need to set the working directory to `src/tools/perf`, so that it can find the directory
4059 // with compile-time benchmarks.
4160 let cmd = cmd. current_dir ( builder. src . join ( "src/tools/rustc-perf" ) ) ;
42- builder. build . run ( cmd) ;
61+ builder. run ( cmd) ;
4362
4463 builder. info ( & format ! ( "You can find the results at `{}`" , results_dir. display( ) ) ) ;
4564}
0 commit comments