Skip to content

Commit dae9e40

Browse files
authored
Rollup merge of #113685 - Kobzol:opt-dist-binary-sizes, r=Mark-Simulacrum
Print artifact sizes in `opt-dist` The Python PGO script printed a nice table of artifact sizes (`librustc_driver.so`, `libLLVM.so`, ...) at the end of the CI run, which was useful to quickly see the sizes of important files. I forgot to port this functionality into the Rust (`opt-dist`) version in #112235. This PR fixes that. r? bootstrap
2 parents b539eb8 + 18305ea commit dae9e40

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use crate::tests::run_tests;
77
use crate::timer::Timer;
88
use crate::training::{gather_llvm_bolt_profiles, gather_llvm_profiles, gather_rustc_profiles};
99
use crate::utils::io::reset_directory;
10-
use crate::utils::{clear_llvm_files, format_env_variables, print_free_disk_space};
10+
use crate::utils::{
11+
clear_llvm_files, format_env_variables, print_binary_sizes, print_free_disk_space,
12+
};
1113

1214
mod environment;
1315
mod exec;
@@ -170,6 +172,8 @@ fn main() -> anyhow::Result<()> {
170172
log::info!("Timer results\n{}", timer.format_stats());
171173

172174
print_free_disk_space()?;
175+
result.context("Optimized build pipeline has failed")?;
176+
print_binary_sizes(env.as_ref())?;
173177

174-
result.context("Optimized build pipeline has failed")
178+
Ok(())
175179
}

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

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use anyhow::Context;
2-
use camino::Utf8Path;
2+
use camino::{Utf8Path, Utf8PathBuf};
33
use fs_extra::dir::CopyOptions;
44
use std::fs::File;
55

@@ -46,3 +46,17 @@ pub fn unpack_archive(path: &Utf8Path, dest_dir: &Utf8Path) -> anyhow::Result<()
4646
archive.unpack(dest_dir.as_std_path())?;
4747
Ok(())
4848
}
49+
50+
/// Returns paths in the given `dir` (non-recursively), optionally with the given `suffix`.
51+
/// The `suffix` should contain the leading dot.
52+
pub fn get_files_from_dir(
53+
dir: &Utf8Path,
54+
suffix: Option<&str>,
55+
) -> anyhow::Result<Vec<Utf8PathBuf>> {
56+
let path = format!("{dir}/*{}", suffix.unwrap_or(""));
57+
58+
Ok(glob::glob(&path)?
59+
.into_iter()
60+
.map(|p| p.map(|p| Utf8PathBuf::from_path_buf(p).unwrap()))
61+
.collect::<Result<Vec<_>, _>>()?)
62+
}

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

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
pub mod io;
22

33
use crate::environment::Environment;
4-
use crate::utils::io::delete_directory;
5-
use humansize::BINARY;
4+
use crate::utils::io::{delete_directory, get_files_from_dir};
5+
use humansize::{format_size, BINARY};
66
use sysinfo::{DiskExt, RefreshKind, System, SystemExt};
77

88
pub fn format_env_variables() -> String {
@@ -25,6 +25,28 @@ pub fn print_free_disk_space() -> anyhow::Result<()> {
2525
Ok(())
2626
}
2727

28+
pub fn print_binary_sizes(env: &dyn Environment) -> anyhow::Result<()> {
29+
use std::fmt::Write;
30+
31+
let root = env.build_artifacts().join("stage2");
32+
33+
let mut files = get_files_from_dir(&root.join("bin"), None)?;
34+
files.extend(get_files_from_dir(&root.join("lib"), Some(".so"))?);
35+
files.sort_unstable();
36+
37+
let mut output = String::new();
38+
for file in files {
39+
let size = std::fs::metadata(file.as_std_path())?.len();
40+
let size_formatted = format_size(size, BINARY);
41+
let name = format!("{}:", file.file_name().unwrap());
42+
writeln!(output, "{name:<50}{size_formatted:>10}")?;
43+
}
44+
45+
log::info!("Rustc artifact size\n{output}");
46+
47+
Ok(())
48+
}
49+
2850
pub fn clear_llvm_files(env: &dyn Environment) -> anyhow::Result<()> {
2951
// Bootstrap currently doesn't support rebuilding LLVM when PGO options
3052
// change (or any other llvm-related options); so just clear out the relevant

0 commit comments

Comments
 (0)