Skip to content

Commit cc7d9d5

Browse files
committed
Auto merge of #113749 - Kobzol:opt-dist-ci-group, r=clubby789
Use log groups in `opt-dist` Some of the output was quite verbose in CI logs, this should help with that. r? bootstrap
2 parents 11da267 + e04b915 commit cc7d9d5

File tree

3 files changed

+53
-20
lines changed

3 files changed

+53
-20
lines changed

src/tools/opt-dist/src/main.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::training::{gather_llvm_bolt_profiles, gather_llvm_profiles, gather_ru
99
use crate::utils::io::reset_directory;
1010
use crate::utils::{
1111
clear_llvm_files, format_env_variables, print_binary_sizes, print_free_disk_space,
12+
with_log_group,
1213
};
1314

1415
mod environment;
@@ -29,7 +30,8 @@ fn execute_pipeline(
2930
dist_args: Vec<String>,
3031
) -> anyhow::Result<()> {
3132
reset_directory(&env.opt_artifacts())?;
32-
env.prepare_rustc_perf()?;
33+
34+
with_log_group("Building rustc-perf", || env.prepare_rustc_perf())?;
3335

3436
// Stage 1: Build PGO instrumented rustc
3537
// We use a normal build of LLVM, because gathering PGO profiles for LLVM and `rustc` at the
@@ -141,12 +143,17 @@ fn main() -> anyhow::Result<()> {
141143
.init();
142144

143145
let mut build_args: Vec<String> = std::env::args().skip(1).collect();
144-
log::info!("Running optimized build pipeline with args `{}`", build_args.join(" "));
145-
log::info!("Environment values\n{}", format_env_variables());
146+
println!("Running optimized build pipeline with args `{}`", build_args.join(" "));
146147

147-
if let Ok(config) = std::fs::read_to_string("config.toml") {
148-
log::info!("Contents of `config.toml`:\n{config}");
149-
}
148+
with_log_group("Environment values", || {
149+
println!("Environment values\n{}", format_env_variables());
150+
});
151+
152+
with_log_group("Printing config.toml", || {
153+
if let Ok(config) = std::fs::read_to_string("config.toml") {
154+
println!("Contents of `config.toml`:\n{config}");
155+
}
156+
});
150157

151158
// Skip components that are not needed for try builds to speed them up
152159
if is_try_build() {

src/tools/opt-dist/src/training.rs

+23-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::environment::Environment;
22
use crate::exec::{cmd, CmdBuilder};
33
use crate::utils::io::{count_files, delete_directory};
4+
use crate::utils::with_log_group;
45
use anyhow::Context;
56
use camino::{Utf8Path, Utf8PathBuf};
67
use humansize::BINARY;
@@ -108,9 +109,11 @@ pub fn gather_llvm_profiles(
108109
) -> anyhow::Result<LlvmPGOProfile> {
109110
log::info!("Running benchmarks with PGO instrumented LLVM");
110111

111-
init_compiler_benchmarks(env, &["Debug", "Opt"], &["Full"], LLVM_PGO_CRATES)
112-
.run()
113-
.context("Cannot gather LLVM PGO profiles")?;
112+
with_log_group("Running benchmarks", || {
113+
init_compiler_benchmarks(env, &["Debug", "Opt"], &["Full"], LLVM_PGO_CRATES)
114+
.run()
115+
.context("Cannot gather LLVM PGO profiles")
116+
})?;
114117

115118
let merged_profile = env.opt_artifacts().join("llvm-pgo.profdata");
116119
log::info!("Merging LLVM PGO profiles to {merged_profile}");
@@ -141,10 +144,12 @@ pub fn gather_rustc_profiles(
141144

142145
// Here we're profiling the `rustc` frontend, so we also include `Check`.
143146
// The benchmark set includes various stress tests that put the frontend under pressure.
144-
init_compiler_benchmarks(env, &["Check", "Debug", "Opt"], &["All"], RUSTC_PGO_CRATES)
145-
.env("LLVM_PROFILE_FILE", profile_template.as_str())
146-
.run()
147-
.context("Cannot gather rustc PGO profiles")?;
147+
with_log_group("Running benchmarks", || {
148+
init_compiler_benchmarks(env, &["Check", "Debug", "Opt"], &["All"], RUSTC_PGO_CRATES)
149+
.env("LLVM_PROFILE_FILE", profile_template.as_str())
150+
.run()
151+
.context("Cannot gather rustc PGO profiles")
152+
})?;
148153

149154
let merged_profile = env.opt_artifacts().join("rustc-pgo.profdata");
150155
log::info!("Merging Rustc PGO profiles to {merged_profile}");
@@ -164,9 +169,11 @@ pub struct LlvmBoltProfile(pub Utf8PathBuf);
164169
pub fn gather_llvm_bolt_profiles(env: &dyn Environment) -> anyhow::Result<LlvmBoltProfile> {
165170
log::info!("Running benchmarks with BOLT instrumented LLVM");
166171

167-
init_compiler_benchmarks(env, &["Check", "Debug", "Opt"], &["Full"], LLVM_BOLT_CRATES)
168-
.run()
169-
.context("Cannot gather LLVM BOLT profiles")?;
172+
with_log_group("Running benchmarks", || {
173+
init_compiler_benchmarks(env, &["Check", "Debug", "Opt"], &["Full"], LLVM_BOLT_CRATES)
174+
.run()
175+
.context("Cannot gather LLVM BOLT profiles")
176+
})?;
170177

171178
let merged_profile = env.opt_artifacts().join("bolt.profdata");
172179
let profile_root = Utf8PathBuf::from("/tmp/prof.fdata");
@@ -178,10 +185,12 @@ pub fn gather_llvm_bolt_profiles(env: &dyn Environment) -> anyhow::Result<LlvmBo
178185
let mut merge_args = vec!["merge-fdata"];
179186
merge_args.extend(profiles.iter().map(|p| p.to_str().unwrap()));
180187

181-
cmd(&merge_args)
182-
.redirect_output(merged_profile.clone())
183-
.run()
184-
.context("Cannot merge BOLT profiles")?;
188+
with_log_group("Merging BOLT profiles", || {
189+
cmd(&merge_args)
190+
.redirect_output(merged_profile.clone())
191+
.run()
192+
.context("Cannot merge BOLT profiles")
193+
})?;
185194

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

src/tools/opt-dist/src/utils/mod.rs

+17
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,20 @@ pub fn clear_llvm_files(env: &dyn Environment) -> anyhow::Result<()> {
5656
delete_directory(&env.build_artifacts().join("lld"))?;
5757
Ok(())
5858
}
59+
60+
/// Wraps all output produced within the `func` closure in a CI output group, if we're running in
61+
/// CI.
62+
pub fn with_log_group<F: FnOnce() -> R, R>(group: &str, func: F) -> R {
63+
if is_in_ci() {
64+
println!("::group::{group}");
65+
let result = func();
66+
println!("::endgroup::");
67+
result
68+
} else {
69+
func()
70+
}
71+
}
72+
73+
fn is_in_ci() -> bool {
74+
std::env::var("GITHUB_ACTIONS").is_ok()
75+
}

0 commit comments

Comments
 (0)