1
+ use std:: fmt:: { Display , Formatter } ;
1
2
use std:: process:: Command ;
2
3
3
4
use crate :: core:: build_steps:: compile:: { Std , Sysroot } ;
@@ -11,6 +12,15 @@ use crate::core::config::DebuginfoLevel;
11
12
pub struct PerfArgs {
12
13
#[ clap( subcommand) ]
13
14
cmd : PerfCommand ,
15
+
16
+ #[ clap( flatten) ]
17
+ opts : SharedOpts ,
18
+ }
19
+
20
+ impl Default for PerfArgs {
21
+ fn default ( ) -> Self {
22
+ Self { cmd : PerfCommand :: Eprintln , opts : SharedOpts :: default ( ) }
23
+ }
14
24
}
15
25
16
26
#[ derive( Debug , Clone , clap:: Parser ) ]
@@ -20,9 +30,66 @@ enum PerfCommand {
20
30
Eprintln ,
21
31
}
22
32
23
- impl Default for PerfArgs {
24
- fn default ( ) -> Self {
25
- Self { cmd : PerfCommand :: Eprintln }
33
+ #[ derive( Debug , Default , Clone , clap:: Parser ) ]
34
+ struct SharedOpts {
35
+ /// Select the benchmarks that you want to run (separated by commas).
36
+ /// If unspecified, all benchmarks will be executed.
37
+ #[ clap( long, global = true , value_delimiter = ',' ) ]
38
+ include : Vec < String > ,
39
+ /// Select the scenarios that should be benchmarked.
40
+ #[ clap(
41
+ long,
42
+ global = true ,
43
+ value_delimiter = ',' ,
44
+ default_value = "Full,IncrFull,IncrUnchanged,IncrPatched"
45
+ ) ]
46
+ scenarios : Vec < Scenario > ,
47
+ /// Select the profiles that should be benchmarked.
48
+ #[ clap( long, global = true , value_delimiter = ',' , default_value = "Check,Debug,Opt" ) ]
49
+ profiles : Vec < Profile > ,
50
+ }
51
+
52
+ #[ derive( Clone , Copy , Debug , clap:: ValueEnum ) ]
53
+ #[ value( rename_all = "PascalCase" ) ]
54
+ enum Profile {
55
+ Check ,
56
+ Debug ,
57
+ Doc ,
58
+ Opt ,
59
+ Clippy ,
60
+ }
61
+
62
+ impl Display for Profile {
63
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
64
+ let name = match self {
65
+ Profile :: Check => "Check" ,
66
+ Profile :: Debug => "Debug" ,
67
+ Profile :: Doc => "Doc" ,
68
+ Profile :: Opt => "Opt" ,
69
+ Profile :: Clippy => "Clippy" ,
70
+ } ;
71
+ f. write_str ( name)
72
+ }
73
+ }
74
+
75
+ #[ derive( Clone , Copy , Debug , clap:: ValueEnum ) ]
76
+ #[ value( rename_all = "PascalCase" ) ]
77
+ enum Scenario {
78
+ Full ,
79
+ IncrFull ,
80
+ IncrUnchanged ,
81
+ IncrPatched ,
82
+ }
83
+
84
+ impl Display for Scenario {
85
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
86
+ let name = match self {
87
+ Scenario :: Full => "Full" ,
88
+ Scenario :: IncrFull => "IncrFull" ,
89
+ Scenario :: IncrUnchanged => "IncrUnchanged" ,
90
+ Scenario :: IncrPatched => "IncrPatched" ,
91
+ } ;
92
+ f. write_str ( name)
26
93
}
27
94
}
28
95
@@ -43,15 +110,28 @@ Consider setting `rust.debuginfo-level = 1` in `config.toml`."#);
43
110
let sysroot = builder. ensure ( Sysroot :: new ( compiler) ) ;
44
111
let rustc = sysroot. join ( "bin/rustc" ) ;
45
112
46
- let results_dir = builder. build . tempdir ( ) . join ( "rustc-perf" ) ;
113
+ let rustc_perf_dir = builder. build . tempdir ( ) . join ( "rustc-perf" ) ;
47
114
48
115
let mut cmd = Command :: new ( collector) ;
49
116
match args. cmd {
50
117
PerfCommand :: Eprintln => {
51
118
cmd. arg ( "profile_local" ) . arg ( "eprintln" ) ;
119
+ cmd. arg ( "--out-dir" ) . arg ( rustc_perf_dir. join ( "results" ) ) ;
52
120
}
53
121
}
54
- cmd. arg ( "--out-dir" ) . arg ( & results_dir) . arg ( "--include" ) . arg ( "helloworld" ) . arg ( & rustc) ;
122
+
123
+ if !args. opts . include . is_empty ( ) {
124
+ cmd. arg ( "--include" ) . arg ( args. opts . include . join ( "," ) ) ;
125
+ }
126
+ if !args. opts . profiles . is_empty ( ) {
127
+ cmd. arg ( "--profiles" )
128
+ . arg ( args. opts . profiles . iter ( ) . map ( |p| p. to_string ( ) ) . collect :: < Vec < _ > > ( ) . join ( "," ) ) ;
129
+ }
130
+ if !args. opts . scenarios . is_empty ( ) {
131
+ cmd. arg ( "--scenarios" )
132
+ . arg ( args. opts . scenarios . iter ( ) . map ( |p| p. to_string ( ) ) . collect :: < Vec < _ > > ( ) . join ( "," ) ) ;
133
+ }
134
+ cmd. arg ( & rustc) ;
55
135
56
136
builder. info ( & format ! ( "Running `rustc-perf` using `{}`" , rustc. display( ) ) ) ;
57
137
@@ -60,5 +140,5 @@ Consider setting `rust.debuginfo-level = 1` in `config.toml`."#);
60
140
let cmd = cmd. current_dir ( builder. src . join ( "src/tools/rustc-perf" ) ) ;
61
141
builder. run ( cmd) ;
62
142
63
- builder. info ( & format ! ( "You can find the results at `{}`" , results_dir . display( ) ) ) ;
143
+ builder. info ( & format ! ( "You can find the results at `{}`" , rustc_perf_dir . display( ) ) ) ;
64
144
}
0 commit comments