@@ -5,8 +5,29 @@ use crate::core::build_steps::tool::RustcPerf;
5
5
use crate :: core:: builder:: Builder ;
6
6
use crate :: core:: config:: DebuginfoLevel ;
7
7
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
+
8
29
/// 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 ) {
10
31
let collector = builder. ensure ( RustcPerf {
11
32
compiler : builder. compiler ( 0 , builder. config . build ) ,
12
33
target : builder. config . build ,
@@ -25,21 +46,19 @@ Consider setting `rust.debuginfo-level = 1` in `config.toml`."#);
25
46
let results_dir = builder. build . tempdir ( ) . join ( "rustc-perf" ) ;
26
47
27
48
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) ;
36
55
37
56
builder. info ( & format ! ( "Running `rustc-perf` using `{}`" , rustc. display( ) ) ) ;
38
57
39
58
// We need to set the working directory to `src/tools/perf`, so that it can find the directory
40
59
// with compile-time benchmarks.
41
60
let cmd = cmd. current_dir ( builder. src . join ( "src/tools/rustc-perf" ) ) ;
42
- builder. build . run ( cmd) ;
61
+ builder. run ( cmd) ;
43
62
44
63
builder. info ( & format ! ( "You can find the results at `{}`" , results_dir. display( ) ) ) ;
45
64
}
0 commit comments