Skip to content

Print artifact sizes in opt-dist #113685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/tools/opt-dist/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(())
}
16 changes: 15 additions & 1 deletion src/tools/opt-dist/src/utils/io.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Context;
use camino::Utf8Path;
use camino::{Utf8Path, Utf8PathBuf};
use fs_extra::dir::CopyOptions;
use std::fs::File;

Expand Down Expand Up @@ -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<_>, _>>()?)
}
26 changes: 24 additions & 2 deletions src/tools/opt-dist/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
Expand Down