@@ -28,6 +28,21 @@ enum PerfCommand {
28
28
/// Run `profile_local eprintln`.
29
29
/// This executes the compiler on the given benchmarks and stores its stderr output.
30
30
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
+ }
31
46
}
32
47
33
48
#[ derive( Debug , Default , Clone , clap:: Parser ) ]
@@ -111,14 +126,23 @@ Consider setting `rust.debuginfo-level = 1` in `config.toml`."#);
111
126
let rustc = sysroot. join ( "bin/rustc" ) ;
112
127
113
128
let rustc_perf_dir = builder. build . tempdir ( ) . join ( "rustc-perf" ) ;
129
+ let profile_results_dir = rustc_perf_dir. join ( "results" ) ;
114
130
115
131
let mut cmd = Command :: new ( collector) ;
116
- match args. cmd {
132
+ match & args. cmd {
117
133
PerfCommand :: Eprintln => {
118
134
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" ) ;
120
141
}
121
142
}
143
+ if args. cmd . is_profiling ( ) {
144
+ cmd. arg ( "--out-dir" ) . arg ( & profile_results_dir) ;
145
+ }
122
146
123
147
if !args. opts . include . is_empty ( ) {
124
148
cmd. arg ( "--include" ) . arg ( args. opts . include . join ( "," ) ) ;
@@ -140,5 +164,7 @@ Consider setting `rust.debuginfo-level = 1` in `config.toml`."#);
140
164
let cmd = cmd. current_dir ( builder. src . join ( "src/tools/rustc-perf" ) ) ;
141
165
builder. run ( cmd) ;
142
166
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
+ }
144
170
}
0 commit comments