mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
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 https://github.com/rust-lang/rust/pull/112235. This PR fixes that. r? bootstrap
This commit is contained in:
commit
dae9e40213
@ -7,7 +7,9 @@ use crate::tests::run_tests;
|
||||
use crate::timer::Timer;
|
||||
use crate::training::{gather_llvm_bolt_profiles, gather_llvm_profiles, gather_rustc_profiles};
|
||||
use crate::utils::io::reset_directory;
|
||||
use crate::utils::{clear_llvm_files, format_env_variables, print_free_disk_space};
|
||||
use crate::utils::{
|
||||
clear_llvm_files, format_env_variables, print_binary_sizes, print_free_disk_space,
|
||||
};
|
||||
|
||||
mod environment;
|
||||
mod exec;
|
||||
@ -170,6 +172,8 @@ fn main() -> anyhow::Result<()> {
|
||||
log::info!("Timer results\n{}", timer.format_stats());
|
||||
|
||||
print_free_disk_space()?;
|
||||
result.context("Optimized build pipeline has failed")?;
|
||||
print_binary_sizes(env.as_ref())?;
|
||||
|
||||
result.context("Optimized build pipeline has failed")
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use anyhow::Context;
|
||||
use camino::Utf8Path;
|
||||
use camino::{Utf8Path, Utf8PathBuf};
|
||||
use fs_extra::dir::CopyOptions;
|
||||
use std::fs::File;
|
||||
|
||||
@ -46,3 +46,17 @@ pub fn unpack_archive(path: &Utf8Path, dest_dir: &Utf8Path) -> anyhow::Result<()
|
||||
archive.unpack(dest_dir.as_std_path())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns paths in the given `dir` (non-recursively), optionally with the given `suffix`.
|
||||
/// The `suffix` should contain the leading dot.
|
||||
pub fn get_files_from_dir(
|
||||
dir: &Utf8Path,
|
||||
suffix: Option<&str>,
|
||||
) -> anyhow::Result<Vec<Utf8PathBuf>> {
|
||||
let path = format!("{dir}/*{}", suffix.unwrap_or(""));
|
||||
|
||||
Ok(glob::glob(&path)?
|
||||
.into_iter()
|
||||
.map(|p| p.map(|p| Utf8PathBuf::from_path_buf(p).unwrap()))
|
||||
.collect::<Result<Vec<_>, _>>()?)
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
pub mod io;
|
||||
|
||||
use crate::environment::Environment;
|
||||
use crate::utils::io::delete_directory;
|
||||
use humansize::BINARY;
|
||||
use crate::utils::io::{delete_directory, get_files_from_dir};
|
||||
use humansize::{format_size, BINARY};
|
||||
use sysinfo::{DiskExt, RefreshKind, System, SystemExt};
|
||||
|
||||
pub fn format_env_variables() -> String {
|
||||
@ -25,6 +25,28 @@ pub fn print_free_disk_space() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_binary_sizes(env: &dyn Environment) -> anyhow::Result<()> {
|
||||
use std::fmt::Write;
|
||||
|
||||
let root = env.build_artifacts().join("stage2");
|
||||
|
||||
let mut files = get_files_from_dir(&root.join("bin"), None)?;
|
||||
files.extend(get_files_from_dir(&root.join("lib"), Some(".so"))?);
|
||||
files.sort_unstable();
|
||||
|
||||
let mut output = String::new();
|
||||
for file in files {
|
||||
let size = std::fs::metadata(file.as_std_path())?.len();
|
||||
let size_formatted = format_size(size, BINARY);
|
||||
let name = format!("{}:", file.file_name().unwrap());
|
||||
writeln!(output, "{name:<50}{size_formatted:>10}")?;
|
||||
}
|
||||
|
||||
log::info!("Rustc artifact size\n{output}");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn clear_llvm_files(env: &dyn Environment) -> anyhow::Result<()> {
|
||||
// Bootstrap currently doesn't support rebuilding LLVM when PGO options
|
||||
// change (or any other llvm-related options); so just clear out the relevant
|
||||
|
Loading…
Reference in New Issue
Block a user