Skip to content
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

Added GH Action to show FLASH diff using bloaty #23868

Merged
merged 1 commit into from
Nov 16, 2024
Merged

Conversation

alexcekay
Copy link
Member

@alexcekay alexcekay commented Oct 30, 2024

Solved Problem

Increase awareness of the impact of a code change on FLASH size. Allow developers to see exactly how much and where their change will increase FLASH usage.

Solution

  • In case of a PR:
    • Compile the base revision
    • Compile the current revision of the branch
    • Diff the flash usage using bloaty
  • In case of a commit on main:
    • Compile the previous main revision
    • Compile the current main revision
    • Diff the flash usage using bloaty

Alternatives / Future

This is an initial working version that includes the following two boards:

  • px4_fmu-v5x
  • px4_fmu-v6x

If we want, we can easily add more boards in the future.

This version compiles 2 times for each board (1 compile before / 1 compile after) to create the diff. With two boards this results in 4 compiles, which is fast and only creates a small overhead. If we add many more boards, we should reuse the artifacts created by other jobs. However, this will increase the complexity of the code as an external script will need collect the artifacts from the base and current revisions and unpack them.

In addition bloaty has the tendency to detect non-existing remappings (like in the comment below) when there are no changes. In case of real changes the output is however really useful as can be for example seen here:
image
alexcekay#2

Copy link

FLASH Analysis

px4_fmu-v5x
    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%      +8  +0.0%      +8    .text
  -0.0%      -8  [ = ]       0    [Unmapped]
  [ = ]       0  +0.0%      +8    TOTAL

px4_fmu-v6x
    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%      +8  +0.0%      +8    .text
  -0.0%      -8  [ = ]       0    [Unmapped]
  [ = ]       0  +0.0%      +8    TOTAL

@alexcekay alexcekay marked this pull request as ready for review October 30, 2024 17:32
@alexcekay alexcekay requested review from dagar and niklaut October 30, 2024 17:32
@PetervdPerk-NXP
Copy link
Member

Do you have an example of the bloaty build causing a segfault. It did not happen yet on any of the tests of the action on my fork. With an example of the segfault I can diff which version is used there and in my action.

I don't have a particular example at the moment, but it was related to this bug which was fixed later.
google/bloaty#208
Hence the recommendation to update bloaty so it won't crash.

Regarding RAM: The static RAM part is included in bloaty via .bss and .data. This is however only a rather small part in PX4 due to most of the RAM usage being caused by mallocs. We plan to add a dynamic execution for measuring RAM (heap) usage

I agree that most RAM usage is in malloc(), but if someone prealloc data on the heap where they shouldn't it should be notified.
For example #18380

@alexcekay
Copy link
Member Author

alexcekay commented Nov 1, 2024

Hence the recommendation to update bloaty so it won't crash.

Yes, that sounds reasonable. Bloaty does not seem to make any official releases anymore. So I will create a fork of https://github.com/carlosperate/bloaty-action next week and bump the used bloaty version to one of the recent commits in the bloaty repo.

I agree that most RAM usage is in malloc(), but if someone prealloc data on the heap where they shouldn't it should be notified.

This will be caught by bloaty. As an example, I have compiled the following https://gist.github.com/alexcekay/756864c1f8ace3db3b4fe34c8bf49da7 once with and once without st_h being present. This will be noted in the bloaty diff output:

  +1.2%     +16  +1.2%     +16    .data                                                              
    [NEW]     +12  [NEW]     +12    ram.c
    +0.3%      +4  +0.3%      +4    [section .data]

@DronecodeBot
Copy link

This pull request has been mentioned on Discussion Forum for PX4, Pixhawk, QGroundControl, MAVSDK, MAVLink. There might be relevant details there:

https://discuss.px4.io/t/px4-sync-q-a-nov-6-2024/42264/1

Copy link
Contributor

@niklaut niklaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please!

@dagar
Copy link
Member

dagar commented Nov 16, 2024

I also find the symbols size change helpful for comparison.

FYI we have some helpers for bloaty in tree. https://github.com/PX4/PX4-Autopilot/blob/main/cmake/bloaty.cmake

@dagar dagar merged commit 101384e into main Nov 16, 2024
58 of 60 checks passed
@dagar dagar deleted the pr-ci-flash-diff branch November 16, 2024 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants