@@ -28,6 +28,21 @@ enum PerfCommand {
2828 /// Run `profile_local eprintln`.
2929 /// This executes the compiler on the given benchmarks and stores its stderr output.
3030 Eprintln ,
31+ /// Run `profile_local samply`
32+ /// This executes the compiler on the given benchmarks and profiles it with `samply`.
33+ /// You need to install `samply`, e.g. using `cargo install samply`.
34+ Samply ,
35+ /// Run `profile_local cachegrind`.
36+ /// This executes the compiler on the given benchmarks under `Cachegrind`.
37+ Cachegrind ,
38+ }
39+
40+ impl PerfCommand {
41+ fn is_profiling ( & self ) -> bool {
42+ match self {
43+ PerfCommand :: Eprintln | PerfCommand :: Samply | PerfCommand :: Cachegrind => true ,
44+ }
45+ }
3146}
3247
3348#[ derive( Debug , Default , Clone , clap:: Parser ) ]
@@ -111,14 +126,23 @@ Consider setting `rust.debuginfo-level = 1` in `config.toml`."#);
111126 let rustc = sysroot. join ( "bin/rustc" ) ;
112127
113128 let rustc_perf_dir = builder. build . tempdir ( ) . join ( "rustc-perf" ) ;
129+ let profile_results_dir = rustc_perf_dir. join ( "results" ) ;
114130
115131 let mut cmd = Command :: new ( collector) ;
116- match args. cmd {
132+ match & args. cmd {
117133 PerfCommand :: Eprintln => {
118134 cmd. arg ( "profile_local" ) . arg ( "eprintln" ) ;
119- cmd. arg ( "--out-dir" ) . arg ( rustc_perf_dir. join ( "results" ) ) ;
135+ }
136+ PerfCommand :: Samply => {
137+ cmd. arg ( "profile_local" ) . arg ( "samply" ) ;
138+ }
139+ PerfCommand :: Cachegrind => {
140+ cmd. arg ( "profile_local" ) . arg ( "cachegrind" ) ;
120141 }
121142 }
143+ if args. cmd . is_profiling ( ) {
144+ cmd. arg ( "--out-dir" ) . arg ( & profile_results_dir) ;
145+ }
122146
123147 if !args. opts . include . is_empty ( ) {
124148 cmd. arg ( "--include" ) . arg ( args. opts . include . join ( "," ) ) ;
@@ -140,5 +164,7 @@ Consider setting `rust.debuginfo-level = 1` in `config.toml`."#);
140164 let cmd = cmd. current_dir ( builder. src . join ( "src/tools/rustc-perf" ) ) ;
141165 builder. run ( cmd) ;
142166
143- builder. info ( & format ! ( "You can find the results at `{}`" , rustc_perf_dir. display( ) ) ) ;
167+ if args. cmd . is_profiling ( ) {
168+ builder. info ( & format ! ( "You can find the results at `{}`" , profile_results_dir. display( ) ) ) ;
169+ }
144170}
0 commit comments