@@ -27,8 +27,6 @@ const RUSTC_PGO_CRATES: &[&str] = &[
2727 "bitmaps-3.1.0" ,
2828] ;
2929
30- const LLVM_BOLT_CRATES : & [ & str ] = LLVM_PGO_CRATES ;
31-
3230fn init_compiler_benchmarks (
3331 env : & Environment ,
3432 profiles : & [ & str ] ,
@@ -113,6 +111,14 @@ fn log_profile_stats(
113111 Ok ( ( ) )
114112}
115113
114+ pub fn llvm_benchmarks ( env : & Environment ) -> CmdBuilder {
115+ init_compiler_benchmarks ( env, & [ "Debug" , "Opt" ] , & [ "Full" ] , LLVM_PGO_CRATES )
116+ }
117+
118+ pub fn rustc_benchmarks ( env : & Environment ) -> CmdBuilder {
119+ init_compiler_benchmarks ( env, & [ "Check" , "Debug" , "Opt" ] , & [ "All" ] , RUSTC_PGO_CRATES )
120+ }
121+
116122pub struct LlvmPGOProfile ( pub Utf8PathBuf ) ;
117123
118124pub fn gather_llvm_profiles (
@@ -122,9 +128,7 @@ pub fn gather_llvm_profiles(
122128 log:: info!( "Running benchmarks with PGO instrumented LLVM" ) ;
123129
124130 with_log_group ( "Running benchmarks" , || {
125- init_compiler_benchmarks ( env, & [ "Debug" , "Opt" ] , & [ "Full" ] , LLVM_PGO_CRATES )
126- . run ( )
127- . context ( "Cannot gather LLVM PGO profiles" )
131+ llvm_benchmarks ( env) . run ( ) . context ( "Cannot gather LLVM PGO profiles" )
128132 } ) ?;
129133
130134 let merged_profile = env. artifact_dir ( ) . join ( "llvm-pgo.profdata" ) ;
@@ -157,7 +161,7 @@ pub fn gather_rustc_profiles(
157161 // Here we're profiling the `rustc` frontend, so we also include `Check`.
158162 // The benchmark set includes various stress tests that put the frontend under pressure.
159163 with_log_group ( "Running benchmarks" , || {
160- init_compiler_benchmarks ( env, & [ "Check" , "Debug" , "Opt" ] , & [ "All" ] , RUSTC_PGO_CRATES )
164+ rustc_benchmarks ( env)
161165 . env ( "LLVM_PROFILE_FILE" , profile_template. as_str ( ) )
162166 . run ( )
163167 . context ( "Cannot gather rustc PGO profiles" )
@@ -176,23 +180,25 @@ pub fn gather_rustc_profiles(
176180 Ok ( RustcPGOProfile ( merged_profile) )
177181}
178182
179- pub struct LlvmBoltProfile ( pub Utf8PathBuf ) ;
183+ pub struct BoltProfile ( pub Utf8PathBuf ) ;
180184
181- pub fn gather_llvm_bolt_profiles ( env : & Environment ) -> anyhow:: Result < LlvmBoltProfile > {
182- log:: info!( "Running benchmarks with BOLT instrumented LLVM" ) ;
185+ pub fn gather_bolt_profiles (
186+ env : & Environment ,
187+ name : & str ,
188+ benchmarks : CmdBuilder ,
189+ profile_prefix : & Utf8Path ,
190+ ) -> anyhow:: Result < BoltProfile > {
191+ log:: info!( "Running benchmarks with BOLT instrumented {name}" ) ;
183192
184193 with_log_group ( "Running benchmarks" , || {
185- init_compiler_benchmarks ( env, & [ "Check" , "Debug" , "Opt" ] , & [ "Full" ] , LLVM_BOLT_CRATES )
186- . run ( )
187- . context ( "Cannot gather LLVM BOLT profiles" )
194+ benchmarks. run ( ) . with_context ( || "Cannot gather {name} BOLT profiles" )
188195 } ) ?;
189196
190- let merged_profile = env. artifact_dir ( ) . join ( "llvm-bolt.profdata" ) ;
191- let profile_root = Utf8PathBuf :: from ( "/tmp/prof.fdata" ) ;
192- log:: info!( "Merging LLVM BOLT profiles to {merged_profile}" ) ;
197+ let merged_profile = env. artifact_dir ( ) . join ( format ! ( "{name}-bolt.profdata" ) ) ;
198+ log:: info!( "Merging {name} BOLT profiles from {profile_prefix} to {merged_profile}" ) ;
193199
194200 let profiles: Vec < _ > =
195- glob:: glob ( & format ! ( "{profile_root }*" ) ) ?. collect :: < Result < Vec < _ > , _ > > ( ) ?;
201+ glob:: glob ( & format ! ( "{profile_prefix }*" ) ) ?. collect :: < Result < Vec < _ > , _ > > ( ) ?;
196202
197203 let mut merge_args = vec ! [ "merge-fdata" ] ;
198204 merge_args. extend ( profiles. iter ( ) . map ( |p| p. to_str ( ) . unwrap ( ) ) ) ;
@@ -204,7 +210,7 @@ pub fn gather_llvm_bolt_profiles(env: &Environment) -> anyhow::Result<LlvmBoltPr
204210 . context ( "Cannot merge BOLT profiles" )
205211 } ) ?;
206212
207- log:: info!( "LLVM BOLT statistics" ) ;
213+ log:: info!( "{name} BOLT statistics" ) ;
208214 log:: info!(
209215 "{merged_profile}: {}" ,
210216 humansize:: format_size( std:: fs:: metadata( merged_profile. as_std_path( ) ) ?. len( ) , BINARY )
@@ -216,8 +222,17 @@ pub fn gather_llvm_bolt_profiles(env: &Environment) -> anyhow::Result<LlvmBoltPr
216222 . collect :: < Result < Vec < _ > , _ > > ( ) ?
217223 . into_iter ( )
218224 . sum :: < u64 > ( ) ;
219- log:: info!( "{profile_root }: {}" , humansize:: format_size( size, BINARY ) ) ;
225+ log:: info!( "{profile_prefix }: {}" , humansize:: format_size( size, BINARY ) ) ;
220226 log:: info!( "Profile file count: {}" , profiles. len( ) ) ;
221227
222- Ok ( LlvmBoltProfile ( merged_profile) )
228+ // Delete the gathered profiles
229+ for profile in glob:: glob ( & format ! ( "{profile_prefix}*" ) ) ?. into_iter ( ) {
230+ if let Ok ( profile) = profile {
231+ if let Err ( error) = std:: fs:: remove_file ( & profile) {
232+ log:: error!( "Cannot delete BOLT profile {}: {error:?}" , profile. display( ) ) ;
233+ }
234+ }
235+ }
236+
237+ Ok ( BoltProfile ( merged_profile) )
223238}
0 commit comments