Skip to content

Commit a6b43bc

Browse files
committed
Add size reports
1 parent 42ea8c2 commit a6b43bc

11 files changed

Lines changed: 241 additions & 54 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Checkout submodules & Bootstrap Matter CPP SDK
2+
description: Checkout submodules & Bootstrap Matter CPP SDK
3+
inputs:
4+
platform:
5+
description: "Platform name"
6+
required: true
7+
extra-submodule-parameters:
8+
description: "extra submodule parameters"
9+
required: false
10+
default: ""
11+
bootstrap-log-name:
12+
description: "Bootstrap log name"
13+
required: false
14+
default: bootstrap-logs-${{ github.job }}
15+
runs:
16+
using: "composite"
17+
steps:
18+
- name: Maximize runner disk
19+
uses: ./.github/actions/maximize-runner-disk
20+
- name: Dump disk info
21+
uses: ./.github/actions/dump-disk-info
22+
- name: Set git safe directory for local act runs
23+
uses: ./.github/actions/git-safe-directory
24+
- name: Checkout submodules
25+
uses: ./.github/actions/checkout-submodules
26+
with:
27+
platform: ${{ inputs.platform }}
28+
extra-parameters: ${{ inputs.extra-submodule-parameters }}
29+
- name: Bootstrap
30+
uses: ./.github/actions/bootstrap
31+
with:
32+
platform: ${{ inputs.platform }}
33+
bootstrap-log-name: ${{ inputs.bootstrap-log-name }}
34+
- name: Dump disk info after checkout submodule & Bootstrap
35+
shell: bash
36+
run: scripts/dump_diskspace_info.sh
37+
- name: Work around TSAN ASLR issues
38+
if: runner.os == 'Linux' && !env.ACT
39+
shell: bash
40+
run: |
41+
# See https://stackoverflow.com/a/77856955/2365113
42+
if [[ "$UID" == 0 ]]; then function sudo() { "$@"; }; fi
43+
sudo sysctl vm.mmap_rnd_bits=28
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Dump disk space info
2+
description: Help debug running out of disk space on github CI
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Collect disk info
7+
# Unfortunately current syntax for github wrapper actions only work for
8+
# Javascript actions, and Docker container actions, which doesn't make it
9+
# possible to wrap a shell script like the one below. The action below
10+
# essentially wraps the shell commands we want to run into a Javascript
11+
# wrapped action. This allow us to get the disk info usage before a job
12+
# is run and after the job is run regardless if the job succeeds or
13+
# fails.
14+
uses: pyTooling/Actions/with-post-step@v0.4.5
15+
if: ${{ runner.os == 'Linux' }}
16+
with:
17+
main: |-
18+
exec ./scripts/dump_diskspace_info.sh
19+
post: |-
20+
exec ./scripts/dump_diskspace_info.sh
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: Git safe directory
2+
description: For running act with checkout owned by non-root user
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Set git safe.directory to "*"
7+
if: ${{ env.ACT }}
8+
shell: bash
9+
run: git config --system --add safe.directory '*'
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Maximize runner disk
2+
description: Free up disk space on the github runner
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Free up disk space on the github runner
7+
if: runner.os == 'Linux' && !env.ACT
8+
shell: bash
9+
run: |
10+
# maximize-runner-disk
11+
# Directories to prune to free up space. Candidates:
12+
# 1.6G /usr/share/dotnet
13+
# 1.1G /usr/local/lib/android/sdk/platforms
14+
# 1000M /usr/local/lib/android/sdk/build-tools
15+
# 8.9G /usr/local/lib/android/sdk
16+
# This list can be amended later to change the trade-off between the amount of
17+
# disk space freed up, and how long it takes to do so (deleting many files is slow).
18+
prune=(/usr/share/dotnet /usr/local/lib/android/sdk/platforms /usr/local/lib/android/sdk/build-tools)
19+
20+
if [[ "$UID" -eq 0 && -d /__w ]]; then
21+
root=/runner-root-volume
22+
if [[ ! -d "$root" ]]; then
23+
echo "Unable to maximize disk space, job is running inside a container and $root is not mounted"
24+
exit 0
25+
fi
26+
function sudo() { "$@"; } # we're already root (and sudo is probably unavailable)
27+
elif [[ "$UID" -ne 0 && "$RUNNER_ENVIRONMENT" == github-hosted ]]; then
28+
root=
29+
else
30+
echo "Unable to maximize disk space, unknown runner environment"
31+
exit 0
32+
fi
33+
34+
echo "Freeing up runner disk space on ${root:-/}"
35+
function avail() { df -k --output=avail "${root:-/}" | grep '^[0-9]*$'; }
36+
function now() { date '+%s'; }
37+
before="$(avail)" start="$(now)"
38+
for dir in "${prune[@]}"; do
39+
if [[ -d "${root}${dir}" ]]; then
40+
echo "- $dir"
41+
# du -sh -- "${root}${dir}"
42+
sudo rm -rf -- "${root}${dir}"
43+
else
44+
echo "- $dir (not found)"
45+
fi
46+
done
47+
after="$(avail)" end="$(now)"
48+
echo "Done, freed up $(( (after - before) / 1024 ))M of disk space in $(( end - start )) seconds."
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Setup size reports
2+
description: Setup size reports
3+
inputs:
4+
gh-context:
5+
description: "GH Context"
6+
required: true
7+
8+
runs:
9+
using: "composite"
10+
steps:
11+
- name: Set up environment for size reports
12+
shell: bash
13+
env:
14+
GH_CONTEXT: ${{ inputs.gh-context }}
15+
run: matter_cpp/repo/scripts/tools/memory/gh_sizes_environment.py "${GH_CONTEXT}"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: upload-size-reports
2+
description: upload-size-reports
3+
inputs:
4+
platform-name:
5+
description: "Platform name Name"
6+
required: true
7+
8+
runs:
9+
using: "composite"
10+
steps:
11+
- name: Uploading Size Reports
12+
uses: actions/upload-artifact@v4
13+
if: ${{ !env.ACT }}
14+
with:
15+
name: Size,${{ inputs.platform-name }}-Examples,${{ env.GH_EVENT_PR }},${{ env.GH_EVENT_HASH }},${{ env.GH_EVENT_PARENT }},${{ github.event_name }}
16+
path: |
17+
/tmp/bloat_reports/
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
schedule:
9+
- cron: "50 6 * * *"
10+
workflow_dispatch:
11+
12+
env:
13+
RUST_TOOLCHAIN: stable
14+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15+
CARGO_TERM_COLOR: always
16+
17+
jobs:
18+
build_and_run_size_report:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Rust
23+
uses: dtolnay/rust-toolchain@v1
24+
with:
25+
toolchain: ${{ env.RUST_TOOLCHAIN }}
26+
components: rustfmt, clippy, rust-src
27+
28+
- name: Setup | Rust no-std target
29+
run: rustup target add riscv32imac-unknown-none-elf
30+
31+
- name: Install libdbus
32+
run: sudo apt-get install -y libdbus-1-dev
33+
34+
- name: Checkout
35+
uses: actions/checkout@v3
36+
37+
- name: Checkout submodules & Matter CPP Bootstrap
38+
uses: ./.github/actions/checkout-submodules-and-cpp-bootstrap
39+
with:
40+
platform: linux
41+
42+
- name: Set up environment for size reports
43+
uses: ./.github/actions/setup-size-reports
44+
if: ${{ !env.ACT }}
45+
with:
46+
gh-context: ${{ toJson(github) }}
47+
48+
- name: Examples
49+
run: cargo build --examples --release --no-default-features --features os,rustcrypto,log
50+
51+
- name: Prepare bloat report from the previous builds
52+
run: |
53+
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
54+
linux rs-matter onoff-light-bt \
55+
target/release/onoff_light_bt \
56+
/tmp/bloat_reports/
57+
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
58+
linux rs-matter dimmable_light \
59+
target/release/dimmable_light \
60+
/tmp/bloat_reports/
61+
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
62+
linux rs-matter speaker \
63+
target/release/speaker \
64+
/tmp/bloat_reports/
65+
66+
- name: Uploading Size Reports
67+
uses: ./.github/actions/upload-size-reports
68+
if: ${{ !env.ACT }}
69+
with:
70+
platform-name: linux

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "matter_cpp/repo"]
2+
path = matter_cpp/repo
3+
url = https://github.com/project-chip/connectedhomeip.git
4+
branch = v1.3-branch

xtask/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ From the rs-matter root directory:
99
```bash
1010
cargo xtask --help
1111
```
12+
13+
To get necessary environment configs (such as `gn`), you may also need to run:
14+
```base
15+
source matter_cpp/repo/scripts/bootstrap.sh
16+
```

xtask/src/itest.rs

Lines changed: 9 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ const DEFAULT_TESTS: &[&str] = &[
4343
"TestCommissioningWindow",
4444
];
4545

46-
/// The default Git reference to use for the Chip repository
47-
pub const CHIP_DEFAULT_GITREF: &str = "v1.3.0.0"; //"master";
4846
/// The directory where the Chip repository will be cloned
49-
const CHIP_DIR: &str = ".build/itest/connectedhomeip";
47+
const CHIP_DIR: &str = "matter_cpp/repo";
5048

5149
/// The tooling that is checked for presence in the command line
5250
const REQUIRED_TOOLING: &[&str] = &[
@@ -138,8 +136,8 @@ impl ITests {
138136
/// - Clone the Chip repo if it doesn't exist, or updates it if it does
139137
/// - Activate the Chip environment
140138
/// - Build `chip-tool`
141-
pub fn setup(&self, chip_gitref: Option<&str>, force_rebuild: bool) -> anyhow::Result<()> {
142-
self.setup_chip_tool(chip_gitref, force_rebuild)
139+
pub fn setup(&self, force_rebuild: bool) -> anyhow::Result<()> {
140+
self.setup_chip_tool(force_rebuild)
143141
}
144142

145143
/// Build the executable (`chip-tool-tests`) that is to be tested with the Chip integration tests.
@@ -166,64 +164,25 @@ impl ITests {
166164

167165
fn setup_chip_tool(
168166
&self,
169-
chip_gitref: Option<&str>,
170167
force_rebuild: bool,
171168
) -> anyhow::Result<()> {
172169
warn!("Setting up Chip environment...");
173170

174171
let chip_dir = self.workspace_dir.join(CHIP_DIR);
175-
let chip_gitref = chip_gitref.unwrap_or(CHIP_DEFAULT_GITREF);
176172

177173
// Check system dependencies
178174
self.check_tooling()?;
179175

180-
// Clone or update Chip repository
181-
if !chip_dir.exists() {
182-
info!("Cloning Chip repository...");
183-
184-
// Ensure parent directories exist
185-
if let Some(parent) = chip_dir.parent() {
186-
fs::create_dir_all(parent)
187-
.context("Failed to create parent directories for Chip")?;
188-
}
189-
190-
let mut cmd = Command::new("git");
191-
192-
cmd.arg("clone")
193-
.arg("https://github.com/project-chip/connectedhomeip.git")
194-
.arg(&chip_dir);
195-
196-
if !self.print_cmd_output {
197-
cmd.arg("--quiet");
198-
}
199-
200-
self.run_command(&mut cmd)?;
201-
} else {
202-
info!("Chip repository already exists");
203-
204-
if force_rebuild {
205-
info!("Force rebuild requested, cleaning build artifacts...");
176+
if force_rebuild {
177+
info!("Force rebuild requested, cleaning build artifacts...");
206178

207-
let out_dir = chip_dir.join("out");
208-
if out_dir.exists() {
209-
fs::remove_dir_all(&out_dir)
210-
.context("Failed to remove existing out directory")?;
211-
}
179+
let out_dir = chip_dir.join("out");
180+
if out_dir.exists() {
181+
fs::remove_dir_all(&out_dir)
182+
.context("Failed to remove existing out directory")?;
212183
}
213184
}
214185

215-
// Checkout the specified reference
216-
info!("Checking out Chip GIT reference: {chip_gitref}...");
217-
218-
let mut cmd = Command::new("git");
219-
220-
cmd.current_dir(&chip_dir).arg("checkout").arg(chip_gitref);
221-
222-
if !self.print_cmd_output {
223-
cmd.arg("--quiet");
224-
}
225-
226-
self.run_command(&mut cmd)?;
227186

228187
// Detect host platform for selective submodule initialization
229188
let platform = self.host_platform()?;

0 commit comments

Comments
 (0)