Skip to content

Commit 209789e

Browse files
committed
Add artifact size and step duration summaries from opt-dist to github job summary
1 parent b0889cb commit 209789e

File tree

6 files changed

+160
-28
lines changed

6 files changed

+160
-28
lines changed

Cargo.lock

+60
Original file line numberDiff line numberDiff line change
@@ -2634,6 +2634,7 @@ dependencies = [
26342634
"serde",
26352635
"serde_json",
26362636
"sysinfo",
2637+
"tabled",
26372638
"tar",
26382639
"tempfile",
26392640
"xz",
@@ -2694,6 +2695,17 @@ dependencies = [
26942695
"unwind",
26952696
]
26962697

2698+
[[package]]
2699+
name = "papergrid"
2700+
version = "0.10.0"
2701+
source = "registry+https://github.com/rust-lang/crates.io-index"
2702+
checksum = "a2ccbe15f2b6db62f9a9871642746427e297b0ceb85f9a7f1ee5ff47d184d0c8"
2703+
dependencies = [
2704+
"bytecount",
2705+
"fnv",
2706+
"unicode-width",
2707+
]
2708+
26972709
[[package]]
26982710
name = "parking_lot"
26992711
version = "0.11.2"
@@ -2902,6 +2914,30 @@ dependencies = [
29022914
"pad",
29032915
]
29042916

2917+
[[package]]
2918+
name = "proc-macro-error"
2919+
version = "1.0.4"
2920+
source = "registry+https://github.com/rust-lang/crates.io-index"
2921+
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
2922+
dependencies = [
2923+
"proc-macro-error-attr",
2924+
"proc-macro2",
2925+
"quote",
2926+
"syn 1.0.109",
2927+
"version_check",
2928+
]
2929+
2930+
[[package]]
2931+
name = "proc-macro-error-attr"
2932+
version = "1.0.4"
2933+
source = "registry+https://github.com/rust-lang/crates.io-index"
2934+
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
2935+
dependencies = [
2936+
"proc-macro2",
2937+
"quote",
2938+
"version_check",
2939+
]
2940+
29052941
[[package]]
29062942
name = "proc-macro-hack"
29072943
version = "0.5.20+deprecated"
@@ -5153,6 +5189,30 @@ dependencies = [
51535189
"test",
51545190
]
51555191

5192+
[[package]]
5193+
name = "tabled"
5194+
version = "0.13.0"
5195+
source = "registry+https://github.com/rust-lang/crates.io-index"
5196+
checksum = "4d38d39c754ae037a9bc3ca1580a985db7371cd14f1229172d1db9093feb6739"
5197+
dependencies = [
5198+
"papergrid",
5199+
"tabled_derive",
5200+
"unicode-width",
5201+
]
5202+
5203+
[[package]]
5204+
name = "tabled_derive"
5205+
version = "0.6.0"
5206+
source = "registry+https://github.com/rust-lang/crates.io-index"
5207+
checksum = "99f688a08b54f4f02f0a3c382aefdb7884d3d69609f785bd253dc033243e3fe4"
5208+
dependencies = [
5209+
"heck",
5210+
"proc-macro-error",
5211+
"proc-macro2",
5212+
"quote",
5213+
"syn 1.0.109",
5214+
]
5215+
51565216
[[package]]
51575217
name = "tar"
51585218
version = "0.4.38"

src/ci/docker/run.sh

+6
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ else
264264
BASE_COMMIT=""
265265
fi
266266

267+
SUMMARY_FILE=github-summary.md
268+
touch $objdir/${SUMMARY_FILE}
269+
267270
docker \
268271
run \
269272
--workdir /checkout/obj \
@@ -275,6 +278,7 @@ docker \
275278
--env CI \
276279
--env GITHUB_ACTIONS \
277280
--env GITHUB_REF \
281+
--env GITHUB_STEP_SUMMARY="/checkout/obj/${SUMMARY_FILE}" \
278282
--env TOOLSTATE_REPO_ACCESS_TOKEN \
279283
--env TOOLSTATE_REPO \
280284
--env TOOLSTATE_PUBLISH \
@@ -289,6 +293,8 @@ docker \
289293
rust-ci \
290294
$command
291295

296+
cat $objdir/${SUMMARY_FILE} >> "${GITHUB_STEP_SUMMARY}"
297+
292298
if [ -f /.dockerenv ]; then
293299
rm -rf $objdir
294300
docker cp checkout:/checkout/obj $objdir

src/tools/opt-dist/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ glob = "0.3"
2323
tempfile = "3.5"
2424
derive_builder = "0.12"
2525
clap = { version = "4", features = ["derive"] }
26+
tabled = "0.13"

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ use crate::exec::{cmd, Bootstrap};
1313
use crate::tests::run_tests;
1414
use crate::timer::Timer;
1515
use crate::training::{gather_llvm_bolt_profiles, gather_llvm_profiles, gather_rustc_profiles};
16+
use crate::utils::artifact_size::print_binary_sizes;
1617
use crate::utils::io::{copy_directory, move_directory, reset_directory};
1718
use crate::utils::{
18-
clear_llvm_files, format_env_variables, print_binary_sizes, print_free_disk_space,
19-
retry_action, with_log_group,
19+
clear_llvm_files, format_env_variables, print_free_disk_space, retry_action, with_log_group,
20+
write_timer_to_summary,
2021
};
2122

2223
mod bolt;
@@ -359,6 +360,10 @@ fn main() -> anyhow::Result<()> {
359360
let result = execute_pipeline(&env, &mut timer, build_args);
360361
log::info!("Timer results\n{}", timer.format_stats());
361362

363+
if let Ok(summary_path) = std::env::var("GITHUB_STEP_SUMMARY") {
364+
write_timer_to_summary(&summary_path, &timer)?;
365+
}
366+
362367
print_free_disk_space()?;
363368
result.context("Optimized build pipeline has failed")?;
364369
print_binary_sizes(&env)?;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use std::io::Write;
2+
3+
use tabled::builder::Builder;
4+
use tabled::settings::object::Columns;
5+
use tabled::settings::style::{BorderChar, Offset};
6+
use tabled::settings::{Modify, Style};
7+
8+
use crate::environment::Environment;
9+
use crate::utils::io::get_files_from_dir;
10+
11+
pub fn print_binary_sizes(env: &Environment) -> anyhow::Result<()> {
12+
use humansize::format_size;
13+
use humansize::BINARY;
14+
use std::fmt::Write;
15+
16+
let root = env.build_artifacts().join("stage2");
17+
18+
let mut files = get_files_from_dir(&root.join("bin"), None)?;
19+
files.extend(get_files_from_dir(&root.join("lib"), Some(".so"))?);
20+
files.sort_unstable();
21+
22+
let items: Vec<_> = files
23+
.into_iter()
24+
.map(|file| {
25+
let size = std::fs::metadata(file.as_std_path()).map(|m| m.len()).unwrap_or(0);
26+
let size_formatted = format_size(size, BINARY);
27+
let name = file.file_name().unwrap().to_string();
28+
(name, size_formatted)
29+
})
30+
.collect();
31+
32+
// Write to log
33+
let mut output = String::new();
34+
for (name, size_formatted) in items.iter() {
35+
let name = format!("{}:", name);
36+
writeln!(output, "{name:<50}{size_formatted:>10}")?;
37+
}
38+
log::info!("Rustc artifact size\n{output}");
39+
40+
// Write to GitHub summary
41+
if let Ok(summary_path) = std::env::var("GITHUB_STEP_SUMMARY") {
42+
let mut builder = Builder::default();
43+
for (name, size_formatted) in items {
44+
builder.push_record(vec![name, size_formatted]);
45+
}
46+
47+
builder.set_header(vec!["Artifact", "Size"]);
48+
let mut table = builder.build();
49+
50+
let mut file = std::fs::File::options().append(true).create(true).open(summary_path)?;
51+
writeln!(
52+
file,
53+
"# Artifact size\n{}\n",
54+
table.with(Style::markdown()).with(
55+
Modify::new(Columns::single(1)).with(BorderChar::horizontal(':', Offset::End(0))),
56+
)
57+
)?;
58+
}
59+
60+
Ok(())
61+
}

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

+25-26
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
pub mod io;
1+
use sysinfo::{DiskExt, RefreshKind, System, SystemExt};
22

33
use crate::environment::Environment;
4-
use crate::utils::io::{delete_directory, get_files_from_dir};
5-
use humansize::{format_size, BINARY};
4+
use crate::timer::Timer;
5+
use crate::utils::io::delete_directory;
6+
use humansize::BINARY;
67
use std::time::Duration;
7-
use sysinfo::{DiskExt, RefreshKind, System, SystemExt};
8+
9+
pub mod artifact_size;
10+
pub mod io;
811

912
pub fn format_env_variables() -> String {
1013
let vars = std::env::vars().map(|(key, value)| format!("{key}={value}")).collect::<Vec<_>>();
@@ -26,28 +29,6 @@ pub fn print_free_disk_space() -> anyhow::Result<()> {
2629
Ok(())
2730
}
2831

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

42+
/// Write the formatted statistics of the timer to a Github Actions summary.
43+
pub fn write_timer_to_summary(path: &str, timer: &Timer) -> anyhow::Result<()> {
44+
use std::io::Write;
45+
46+
let mut file = std::fs::File::options().append(true).create(true).open(path)?;
47+
writeln!(
48+
file,
49+
r#"# Step durations
50+
51+
```
52+
{}
53+
```
54+
"#,
55+
timer.format_stats()
56+
)?;
57+
Ok(())
58+
}
59+
6160
/// Wraps all output produced within the `func` closure in a CI output group, if we're running in
6261
/// CI.
6362
pub fn with_log_group<F: FnOnce() -> R, R>(group: &str, func: F) -> R {

0 commit comments

Comments
 (0)