Auto merge of #102487 - Kobzol:rustc-bolt, r= · rust-lang/rust@8debfc8 (original) (raw)

`@@ -27,8 +27,6 @@ const RUSTC_PGO_CRATES: &[&str] = &[

`

27

27

`"bitmaps-3.1.0",

`

28

28

`];

`

29

29

``

30

``

`-

const LLVM_BOLT_CRATES: &[&str] = LLVM_PGO_CRATES;

`

31

``

-

32

30

`fn init_compiler_benchmarks(

`

33

31

`env: &Environment,

`

34

32

`profiles: &[&str],

`

`@@ -113,6 +111,14 @@ fn log_profile_stats(

`

113

111

`Ok(())

`

114

112

`}

`

115

113

``

``

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

+

116

122

`pub struct LlvmPGOProfile(pub Utf8PathBuf);

`

117

123

``

118

124

`pub fn gather_llvm_profiles(

`

`@@ -122,9 +128,7 @@ pub fn gather_llvm_profiles(

`

122

128

` log::info!("Running benchmarks with PGO instrumented LLVM");

`

123

129

``

124

130

`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")

`

128

132

`})?;

`

129

133

``

130

134

`let merged_profile = env.artifact_dir().join("llvm-pgo.profdata");

`

`@@ -157,7 +161,7 @@ pub fn gather_rustc_profiles(

`

157

161

`` // Here we're profiling the rustc frontend, so we also include Check.

``

158

162

`// The benchmark set includes various stress tests that put the frontend under pressure.

`

159

163

`with_log_group("Running benchmarks", || {

`

160

``

`-

init_compiler_benchmarks(env, &["Check", "Debug", "Opt"], &["All"], RUSTC_PGO_CRATES)

`

``

164

`+

rustc_benchmarks(env)

`

161

165

`.env("LLVM_PROFILE_FILE", profile_template.as_str())

`

162

166

`.run()

`

163

167

`.context("Cannot gather rustc PGO profiles")

`

`@@ -176,23 +180,25 @@ pub fn gather_rustc_profiles(

`

176

180

`Ok(RustcPGOProfile(merged_profile))

`

177

181

`}

`

178

182

``

179

``

`-

pub struct LlvmBoltProfile(pub Utf8PathBuf);

`

``

183

`+

pub struct BoltProfile(pub Utf8PathBuf);

`

180

184

``

181

``

`-

pub fn gather_llvm_bolt_profiles(env: &Environment) -> anyhow::Result {

`

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 {

`

``

191

`+

log::info!("Running benchmarks with BOLT instrumented {name}");

`

183

192

``

184

193

`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")

`

188

195

`})?;

`

189

196

``

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}");

`

193

199

``

194

200

`let profiles: Vec<_> =

`

195

``

`-

glob::glob(&format!("{profile_root}*"))?.collect::<Result<Vec<_>, _>>()?;

`

``

201

`+

glob::glob(&format!("{profile_prefix}*"))?.collect::<Result<Vec<_>, _>>()?;

`

196

202

``

197

203

`let mut merge_args = vec!["merge-fdata"];

`

198

204

` 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

`

204

210

`.context("Cannot merge BOLT profiles")

`

205

211

`})?;

`

206

212

``

207

``

`-

log::info!("LLVM BOLT statistics");

`

``

213

`+

log::info!("{name} BOLT statistics");

`

208

214

` log::info!(

`

209

215

`"{merged_profile}: {}",

`

210

216

` 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

`

216

222

`.collect::<Result<Vec<_>, _>>()?

`

217

223

`.into_iter()

`

218

224

`.sum::();

`

219

``

`-

log::info!("{profile_root}: {}", humansize::format_size(size, BINARY));

`

``

225

`+

log::info!("{profile_prefix}: {}", humansize::format_size(size, BINARY));

`

220

226

` log::info!("Profile file count: {}", profiles.len());

`

221

227

``

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))

`

223

238

`}

`