mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-25 16:51:16 +08:00
fix(ci): report flash and static RAM usage separately (#28789)
* fix(ci): report flash and static RAM usage separately Bloaty's VM total includes zero-initialized RAM and understates the combined cost of data and code copied from flash into RAM. Report the flash load image and static RAM allocations independently so the PR headline reflects each resource's actual change. Assisted-by: Codex * docs(ci): trim memory analysis comment Assisted-by: Codex * fix(ci): diff PR flash usage against the merge commit's base The base branch tip is fetched when the job runs, so a PR merged while its job was queued was compared against itself and reported a near-zero change, and commits landed in the meantime showed up as reverted. * fix(ci): measure flash image from section headers ld maps the ELF header into the first LOAD segment when its max page size exceeds the flash origin's alignment (binutils 2.34 defaults to 64 KiB), so segment-based accounting rejected valid firmware as outside the flash region. * feat(ci): flag notable flash and RAM changes Growth over 100 B and 1000 B gets yellow and red markers, savings over 100 B green, so reviewers can spot size regressions without reading the numbers. * refactor(ci): derive flash and RAM totals without per-target constants The matrix duplicated each board's flash-analysis linker region, which would drift silently. Section headers alone distinguish code executing in place (VMA == LMA) from data copied to or reserved in RAM, and the image span matches objcopy -O binary. * fix(ci): limit the bloaty breakdown to VM sizes Debug, symbol and string table rows only change the file size and made up most of the comment. * fix(ci): post flash analysis only when size changes A push that puts flash and static RAM back to zero was still rewriting the sticky comment, so a PR with no size change carried a zero report. Remove that comment instead. Fork tokens cannot delete it, so those PRs hand a delete artifact to the poster. Assisted-by: Grok:grok-4.7 Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com> * fix(ci): retain zero-delta flash analysis comments Existing reports can be updated when size deltas return to zero, avoiding a separate privileged deletion path. Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com> Assisted-by: Codex:gpt-6 --------- Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
This commit is contained in:
1 parent
85459fae96
commit
1d761cdf2e
3 files changed
+261
-25
No files matched your search
@@ -28,9 +28,9 @@ jobs:
|
||||
target: [px4_fmu-v5x, px4_fmu-v6x]
|
||||
outputs:
|
||||
px4_fmu-v5x-bloaty-output: ${{ steps.gen-output.outputs.px4_fmu-v5x-bloaty-output }}
|
||||
px4_fmu-v5x-bloaty-summary-map: ${{ steps.gen-output.outputs.px4_fmu-v5x-bloaty-summary-map }}
|
||||
px4_fmu-v5x-memory-summary: ${{ steps.gen-output.outputs.px4_fmu-v5x-memory-summary }}
|
||||
px4_fmu-v6x-bloaty-output: ${{ steps.gen-output.outputs.px4_fmu-v6x-bloaty-output }}
|
||||
px4_fmu-v6x-bloaty-summary-map: ${{ steps.gen-output.outputs.px4_fmu-v6x-bloaty-summary-map }}
|
||||
px4_fmu-v6x-memory-summary: ${{ steps.gen-output.outputs.px4_fmu-v6x-memory-summary }}
|
||||
steps:
|
||||
- uses: runs-on/action@v2
|
||||
- uses: actions/checkout@v6
|
||||
@@ -40,6 +40,12 @@ jobs:
|
||||
- name: Configure Git Safe Directory
|
||||
run: git config --system --add safe.directory '*'
|
||||
|
||||
- name: Test and preserve memory reporter
|
||||
# The baseline checkout may not contain this version of the reporter.
|
||||
run: |
|
||||
python3 -m unittest discover -s Tools/ci -p test_firmware_size.py
|
||||
cp Tools/ci/firmware_size.py "$RUNNER_TEMP/firmware_size.py"
|
||||
|
||||
- name: Cache - Restore ccache (current)
|
||||
id: cache_current
|
||||
uses: actions/cache/restore@v5
|
||||
@@ -85,10 +91,10 @@ jobs:
|
||||
make submodulesclean
|
||||
ccache -C
|
||||
|
||||
- name: If it's a PR checkout the base branch
|
||||
- name: If it's a PR checkout the base of the merge commit
|
||||
if: ${{ github.event.pull_request }}
|
||||
# As checkout creates a merge commit (merging the base branch into the PR branch), the base branch is the base for a diff of the PR changes.
|
||||
run: git checkout ${{ github.event.pull_request.base.ref }}
|
||||
# The base branch tip may already contain this PR (merged while the job was queued) or unrelated commits.
|
||||
run: git checkout ${{ github.sha }}^1
|
||||
|
||||
- name: If it's a push checkout the previous commit
|
||||
if: github.event_name == 'push'
|
||||
@@ -130,29 +136,35 @@ jobs:
|
||||
id: bloaty-step
|
||||
with:
|
||||
bloaty-file-args: ./with-change.elf -- ./before-change.elf
|
||||
bloaty-additional-args: -d sections,symbols -s vm -n 20
|
||||
bloaty-additional-args: -d sections,symbols -s vm -n 20 --domain=vm
|
||||
output-to-summary: true
|
||||
|
||||
- name: Generate output
|
||||
id: gen-output
|
||||
env:
|
||||
BLOATY_OUTPUT: ${{ steps.bloaty-step.outputs.bloaty-output }}
|
||||
run: |
|
||||
summary=$(python3 "$RUNNER_TEMP/firmware_size.py" \
|
||||
--before before-change.elf --after with-change.elf)
|
||||
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
|
||||
echo "${{ matrix.target }}-bloaty-output<<$EOF" >> $GITHUB_OUTPUT
|
||||
echo "${{ steps.bloaty-step.outputs.bloaty-output-encoded }}" >> $GITHUB_OUTPUT
|
||||
echo "$EOF" >> $GITHUB_OUTPUT
|
||||
echo "${{ matrix.target }}-bloaty-summary-map<<$EOF" >> $GITHUB_OUTPUT
|
||||
echo '${{ steps.bloaty-step.outputs.bloaty-summary-map }}' >> $GITHUB_OUTPUT
|
||||
echo "$EOF" >> $GITHUB_OUTPUT
|
||||
{
|
||||
echo "${{ matrix.target }}-memory-summary=$summary"
|
||||
echo "${{ matrix.target }}-bloaty-output<<$EOF"
|
||||
printf '%s\n' "$BLOATY_OUTPUT"
|
||||
echo "$EOF"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
|
||||
post_pr_comment:
|
||||
name: Publish Results
|
||||
runs-on: [runs-on,runner=1cpu-linux-x64,image=ubuntu24-full-x64,"run-id=${{ github.run_id }}"]
|
||||
needs: [analyze_flash]
|
||||
env:
|
||||
V5X-SUMMARY-MAP-ABS: ${{ fromJSON(fromJSON(needs.analyze_flash.outputs.px4_fmu-v5x-bloaty-summary-map).vm-absolute) }}
|
||||
V5X-SUMMARY-MAP-PERC: ${{ fromJSON(fromJSON(needs.analyze_flash.outputs.px4_fmu-v5x-bloaty-summary-map).vm-percentage) }}
|
||||
V6X-SUMMARY-MAP-ABS: ${{ fromJSON(fromJSON(needs.analyze_flash.outputs.px4_fmu-v6x-bloaty-summary-map).vm-absolute) }}
|
||||
V6X-SUMMARY-MAP-PERC: ${{ fromJSON(fromJSON(needs.analyze_flash.outputs.px4_fmu-v6x-bloaty-summary-map).vm-percentage) }}
|
||||
V5X_FLASH: ${{ fromJSON(needs.analyze_flash.outputs.px4_fmu-v5x-memory-summary).flash }}
|
||||
V5X_RAM: ${{ fromJSON(needs.analyze_flash.outputs.px4_fmu-v5x-memory-summary).ram }}
|
||||
V5X_CHANGED: ${{ fromJSON(needs.analyze_flash.outputs.px4_fmu-v5x-memory-summary).changed }}
|
||||
V6X_FLASH: ${{ fromJSON(needs.analyze_flash.outputs.px4_fmu-v6x-memory-summary).flash }}
|
||||
V6X_RAM: ${{ fromJSON(needs.analyze_flash.outputs.px4_fmu-v6x-memory-summary).ram }}
|
||||
V6X_CHANGED: ${{ fromJSON(needs.analyze_flash.outputs.px4_fmu-v6x-memory-summary).changed }}
|
||||
if: github.event.pull_request
|
||||
steps:
|
||||
- name: Find Comment
|
||||
@@ -166,15 +178,15 @@ jobs:
|
||||
- name: Set Build Time
|
||||
id: bt
|
||||
run: |
|
||||
echo "timestamp=$(date +'%Y-%m-%dT%H:%M:%S')" >> $GITHUB_OUTPUT
|
||||
echo "timestamp=$(date +'%Y-%m-%dT%H:%M:%S')" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Write pr-comment artifact
|
||||
# Skip only when the diff is exactly 0 bytes on all targets and no comment exists yet.
|
||||
# Update existing comments even when both deltas return to zero.
|
||||
# This can't be moved to the job-level conditions, as GH actions don't allow a job-level if condition to access the env.
|
||||
if: |
|
||||
steps.fc.outputs.comment-id != '' ||
|
||||
env.V5X-SUMMARY-MAP-ABS != 0 ||
|
||||
env.V6X-SUMMARY-MAP-ABS != 0
|
||||
env.V5X_CHANGED == 'true' ||
|
||||
env.V6X_CHANGED == 'true'
|
||||
run: |
|
||||
mkdir -p pr-comment
|
||||
cat > pr-comment/manifest.json <<EOF
|
||||
@@ -186,9 +198,15 @@ jobs:
|
||||
EOF
|
||||
cat > pr-comment/body.md <<'PR_COMMENT_BODY_EOF'
|
||||
<!-- pr-comment-poster:flash-analysis -->
|
||||
## 🔎 FLASH Analysis
|
||||
## 🔎 Flash and RAM Analysis
|
||||
|
||||
| Target | Flash change | Static RAM change |
|
||||
| --- | ---: | ---: |
|
||||
| px4_fmu-v5x | ${{ env.V5X_FLASH }} | ${{ env.V5X_RAM }} |
|
||||
| px4_fmu-v6x | ${{ env.V6X_FLASH }} | ${{ env.V6X_RAM }} |
|
||||
|
||||
<details>
|
||||
<summary>px4_fmu-v5x [Total VM Diff: ${{ env.V5X-SUMMARY-MAP-ABS }} byte (${{ env.V5X-SUMMARY-MAP-PERC}} %)]</summary>
|
||||
<summary>px4_fmu-v5x — Bloaty section/symbol breakdown</summary>
|
||||
|
||||
```
|
||||
${{ needs.analyze_flash.outputs.px4_fmu-v5x-bloaty-output }}
|
||||
@@ -196,7 +214,7 @@ jobs:
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>px4_fmu-v6x [Total VM Diff: ${{ env.V6X-SUMMARY-MAP-ABS }} byte (${{ env.V6X-SUMMARY-MAP-PERC }} %)]</summary>
|
||||
<summary>px4_fmu-v6x — Bloaty section/symbol breakdown</summary>
|
||||
|
||||
```
|
||||
${{ needs.analyze_flash.outputs.px4_fmu-v6x-bloaty-output }}
|
||||
@@ -209,8 +227,8 @@ jobs:
|
||||
- name: Upload pr-comment artifact
|
||||
if: |
|
||||
steps.fc.outputs.comment-id != '' ||
|
||||
env.V5X-SUMMARY-MAP-ABS != 0 ||
|
||||
env.V6X-SUMMARY-MAP-ABS != 0
|
||||
env.V5X_CHANGED == 'true' ||
|
||||
env.V6X_CHANGED == 'true'
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: pr-comment
|
||||
|
||||
Reference in new issue
Block a user