Skip to content

Commit e0b6574

Browse files
authored
[CI][binary-size] Wire bloaty measurement into linux size jobs (pytorch#19990)
### Summary Extracts the bloaty-measure shell fragment into .ci/scripts/bloaty-measure.sh and calls it from all three size jobs (arm-bare-metal/zephyr matrix + linux-gcc + linux-clang). Each job now uploads a bloaty-<job> artifact with metadata.json + full.txt + head_only.txt and emits a per-bucket markdown table to its GitHub Actions step summary. No gate change. The existing `ls -la` threshold checks are untouched and will be replaced by per-bucket gating in a later PR in this stack. ### Test plan Validate remaining size jobs now have step summaries and bloaty artifacts. Authored with Claude.
1 parent c74df67 commit e0b6574

2 files changed

Lines changed: 64 additions & 22 deletions

File tree

.ci/scripts/bloaty-measure.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
# Usage: bash .ci/scripts/bloaty-measure.sh <job_name> <head_elf> <strip_tool>
9+
#
10+
# Runs bloaty against the head ELF, writes metadata.json + full.txt +
11+
# head_only.txt to artifacts-to-be-uploaded/, and appends a markdown table
12+
# to $GITHUB_STEP_SUMMARY.
13+
#
14+
# Best-effort: never exits non-zero — the size jobs that source this should
15+
# not fail because of a bloaty hiccup.
16+
17+
set -uo pipefail
18+
19+
job_name=$1
20+
head_elf=$2
21+
strip_tool=$3
22+
head_sha=${GITHUB_HEAD_SHA:-${GITHUB_SHA:-unknown}}
23+
24+
(
25+
# conda-forge bloaty depends on a newer libstdc++ than the ubuntu-22.04
26+
# docker images ship, so pull libstdcxx-ng into the same env and invoke
27+
# via `conda run` so library paths are set correctly.
28+
bloaty_env=/tmp/bloaty-conda-env
29+
if [[ ! -x "${bloaty_env}/bin/bloaty" ]]; then
30+
conda create -y -p "${bloaty_env}" -c conda-forge bloaty libstdcxx-ng || exit 1
31+
fi
32+
bloaty_cmd=("conda" "run" "--no-capture-output" "-p" "${bloaty_env}" "bloaty")
33+
"${bloaty_cmd[@]}" --version || exit 1
34+
35+
tmp_out=/tmp/bloaty-out
36+
rm -rf "${tmp_out}" && mkdir -p "${tmp_out}"
37+
BLOATY="${bloaty_cmd[*]}" python3 .github/scripts/bloaty_diff.py measure \
38+
--head "${head_elf}" \
39+
--job "${job_name}" \
40+
--binary-name size_test \
41+
--head-sha "${head_sha}" \
42+
--strip-tool "${strip_tool}" \
43+
--out "${tmp_out}" || exit 1
44+
mkdir -p artifacts-to-be-uploaded
45+
mv "${tmp_out}"/* artifacts-to-be-uploaded/
46+
) || echo "bloaty report failed; continuing"

.github/workflows/pull.yml

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ jobs:
484484
submodules: 'recursive'
485485
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
486486
timeout: 90
487+
upload-artifact: bloaty-linux-gcc
487488
script: |
488489
# The generic Linux job chooses to use base env, not the one setup by the image
489490
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
@@ -492,6 +493,13 @@ jobs:
492493
./install_requirements.sh
493494
# build module for executorch.extension.pybindings.portable_lib
494495
bash test/build_size_test.sh
496+
497+
# Bloaty per-bucket size report (best-effort; never fails the size job).
498+
mkdir -p /tmp/bloaty-elfs
499+
cp cmake-out/test/size_test /tmp/bloaty-elfs/head.elf
500+
GITHUB_HEAD_SHA="${{ github.event.pull_request.head.sha || github.sha }}" \
501+
bash .ci/scripts/bloaty-measure.sh "linux-gcc" /tmp/bloaty-elfs/head.elf strip
502+
495503
strip cmake-out/test/size_test
496504
output=$(ls -la cmake-out/test/size_test)
497505
arr=($output)
@@ -519,6 +527,7 @@ jobs:
519527
submodules: 'recursive'
520528
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
521529
timeout: 90
530+
upload-artifact: bloaty-linux-clang
522531
script: |
523532
# The generic Linux job chooses to use base env, not the one setup by the image
524533
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
@@ -528,6 +537,13 @@ jobs:
528537
529538
# build module for executorch.extension.pybindings.portable_lib
530539
bash test/build_size_test.sh
540+
541+
# Bloaty per-bucket size report (best-effort; never fails the size job).
542+
mkdir -p /tmp/bloaty-elfs
543+
cp cmake-out/test/size_test /tmp/bloaty-elfs/head.elf
544+
GITHUB_HEAD_SHA="${{ github.event.pull_request.head.sha || github.sha }}" \
545+
bash .ci/scripts/bloaty-measure.sh "linux-clang" /tmp/bloaty-elfs/head.elf strip
546+
531547
strip cmake-out/test/size_test
532548
output=$(ls -la cmake-out/test/size_test)
533549
arr=($output)
@@ -618,28 +634,8 @@ jobs:
618634
# Runs BEFORE the in-place strip below so the head ELF is still unstripped.
619635
mkdir -p /tmp/bloaty-elfs
620636
cp "${elf}" /tmp/bloaty-elfs/head.elf
621-
(
622-
# conda-forge bloaty depends on a newer libstdc++ than the docker image
623-
# ships, so pull libstdcxx-ng into the same env and invoke via `conda run`.
624-
bloaty_env=/tmp/bloaty-conda-env
625-
if [[ ! -x "${bloaty_env}/bin/bloaty" ]]; then
626-
conda create -y -p "${bloaty_env}" -c conda-forge bloaty libstdcxx-ng || exit 1
627-
fi
628-
bloaty_cmd=("conda" "run" "--no-capture-output" "-p" "${bloaty_env}" "bloaty")
629-
"${bloaty_cmd[@]}" --version || exit 1
630-
631-
tmp_out=/tmp/bloaty-out
632-
rm -rf "${tmp_out}" && mkdir -p "${tmp_out}"
633-
BLOATY="${bloaty_cmd[*]}" python3 .github/scripts/bloaty_diff.py measure \
634-
--head /tmp/bloaty-elfs/head.elf \
635-
--job "arm-${{ matrix.os }}" \
636-
--binary-name size_test \
637-
--head-sha "${{ github.event.pull_request.head.sha || github.sha }}" \
638-
--strip-tool "${toolchain_prefix}strip" \
639-
--out "${tmp_out}" || exit 1
640-
mkdir -p artifacts-to-be-uploaded
641-
mv "${tmp_out}"/* artifacts-to-be-uploaded/
642-
) || echo "bloaty report failed; continuing"
637+
GITHUB_HEAD_SHA="${{ github.event.pull_request.head.sha || github.sha }}" \
638+
bash .ci/scripts/bloaty-measure.sh "arm-${{ matrix.os }}" /tmp/bloaty-elfs/head.elf "${toolchain_prefix}strip"
643639
644640
# Add basic guard - TODO: refine this!
645641
${toolchain_prefix}strip ${elf}

0 commit comments

Comments
 (0)