1+ use std:: fmt:: { Display , Formatter } ;
12use std:: process:: Command ;
23
34use crate :: core:: build_steps:: compile:: { Std , Sysroot } ;
@@ -11,6 +12,15 @@ use crate::core::config::DebuginfoLevel;
1112pub struct PerfArgs {
1213 #[ clap( subcommand) ]
1314 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+ }
1424}
1525
1626#[ derive( Debug , Clone , clap:: Parser ) ]
@@ -20,9 +30,66 @@ enum PerfCommand {
2030 Eprintln ,
2131}
2232
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)
2693 }
2794}
2895
@@ -43,15 +110,28 @@ Consider setting `rust.debuginfo-level = 1` in `config.toml`."#);
43110 let sysroot = builder. ensure ( Sysroot :: new ( compiler) ) ;
44111 let rustc = sysroot. join ( "bin/rustc" ) ;
45112
46- let results_dir = builder. build . tempdir ( ) . join ( "rustc-perf" ) ;
113+ let rustc_perf_dir = builder. build . tempdir ( ) . join ( "rustc-perf" ) ;
47114
48115 let mut cmd = Command :: new ( collector) ;
49116 match args. cmd {
50117 PerfCommand :: Eprintln => {
51118 cmd. arg ( "profile_local" ) . arg ( "eprintln" ) ;
119+ cmd. arg ( "--out-dir" ) . arg ( rustc_perf_dir. join ( "results" ) ) ;
52120 }
53121 }
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) ;
55135
56136 builder. info ( & format ! ( "Running `rustc-perf` using `{}`" , rustc. display( ) ) ) ;
57137
@@ -60,5 +140,5 @@ Consider setting `rust.debuginfo-level = 1` in `config.toml`."#);
60140 let cmd = cmd. current_dir ( builder. src . join ( "src/tools/rustc-perf" ) ) ;
61141 builder. run ( cmd) ;
62142
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( ) ) ) ;
64144}
0 commit comments