WIP: Add code size measurement scripts #246

Draft
davidhorstmann-arm wants to merge 11 commits from davidhorstmann-arm/code-size-measurement-script into main
davidhorstmann-arm commented 2025-12-05 06:12:38 -06:00 (Migrated from github.com)

Add scripts to generate a code size report, display and diff that report.

Add a CMake toolchain file for Cortex-M55 and a script that compiles the library for M55 and measures the code size.

Why 4 scripts instead of just one?

Separating the functionality allows it to later be integrated into the build system so that we can just run make size in the build directory to get the code size. See Mbed-TLS/TF-PSA-Crypto#590 for that.

PR checklist

Please add the numbers (or links) of the associated pull requests for consuming branches. You can omit branches where this pull request is not needed.

  • TF-PSA-Crypto PR provided # | not required because:
  • development PR provided # | not required because:
  • 3.6 PR provided # | not required because:
Add scripts to generate a code size report, display and diff that report. Add a CMake toolchain file for Cortex-M55 and a script that compiles the library for M55 and measures the code size. #### Why 4 scripts instead of just one? Separating the functionality allows it to later be integrated into the build system so that we can just run `make size` in the build directory to get the code size. See Mbed-TLS/TF-PSA-Crypto#590 for that. ## PR checklist Please add the numbers (or links) of the associated pull requests for consuming branches. You can omit branches where this pull request is not needed. - [ ] **TF-PSA-Crypto PR** provided # | not required because: - [ ] **development PR** provided # | not required because: - [ ] **3.6 PR** provided # | not required because:
gilles-peskine-arm (Migrated from github.com) reviewed 2025-12-08 11:33:05 -06:00
gilles-peskine-arm (Migrated from github.com) commented 2025-12-08 11:33:05 -06:00

This script feels like it's doing both too much and too little. Too much: why not take the cmake script as an argument, so you can use it for different targets/compilers? Too little: it's cross-compiling to a bare-metal target so the build fails because it's missing e.g. an entropy source: it should probably take a config as an option, with baremetal_size as the default.

This script feels like it's doing both too much and too little. Too much: why not take the cmake script as an argument, so you can use it for different targets/compilers? Too little: it's cross-compiling to a bare-metal target so the build fails because it's missing e.g. an entropy source: it should probably take a config as an option, with `baremetal_size` as the default.
gilles-peskine-arm (Migrated from github.com) reviewed 2025-12-08 11:36:08 -06:00
@ -0,0 +1,89 @@
#!/usr/bin/env python3
"""Examine 2 code size reports and print the difference between them.
gilles-peskine-arm (Migrated from github.com) commented 2025-12-08 11:36:08 -06:00

What's your typical workflow with this script?

I use mbedtls-size-dwim, where my workflow is to set up one or more build directories and run e.g. mbedtls-size-dwim build-m0plus each time I commit and at any point while I'm developing. It shows the code size differences with the last commit.

With diff_code_size.py, where would I typically find the files to compare?

What's your typical workflow with this script? I use [`mbedtls-size-dwim`](https://github.com/Mbed-TLS/mbedtls-docs/blob/main/tools/bin/mbedtls-size-dwim), where my workflow is to set up one or more build directories and run e.g. `mbedtls-size-dwim build-m0plus` each time I commit and at any point while I'm developing. It shows the code size differences with the last commit. With `diff_code_size.py`, where would I typically find the files to compare?
davidhorstmann-arm (Migrated from github.com) reviewed 2025-12-09 03:46:29 -06:00
davidhorstmann-arm (Migrated from github.com) commented 2025-12-09 03:46:29 -06:00

Ah yes it's meant to be an all-in-one demonstrator script that does everything for M55. I was planning to add ./scripts/config.py baremetal to the start but then I used it to test the code size impact of a config option (MBEDTLS_RSA_NO_CRT) and realised that would not be possible if I set the config upfront.

I'm happy to add it now though, I agree it would make this script easier to use.

Ah yes it's meant to be an all-in-one demonstrator script that does everything for M55. I was planning to add `./scripts/config.py baremetal` to the start but then I used it to test the code size impact of a config option (`MBEDTLS_RSA_NO_CRT`) and realised that would not be possible if I set the config upfront. I'm happy to add it now though, I agree it would make this script easier to use.
davidhorstmann-arm (Migrated from github.com) reviewed 2025-12-09 03:51:46 -06:00
@ -0,0 +1,89 @@
#!/usr/bin/env python3
"""Examine 2 code size reports and print the difference between them.
davidhorstmann-arm (Migrated from github.com) commented 2025-12-09 03:51:46 -06:00

If working in conjunction with Mbed-TLS/TF-PSA-Crypto#590 it would be something like:

# Build version A
cmake -B build-A .
cmake --build build-A --target size # or (cd build-A && make size)
# Build version B
cmake -B build-B .
cmake --build build-B --target size # or (cd build-B && make size)

# Compare code size
framework/scripts/diff_code_size.py build-A/core/code_size.json build-B/core/code_size.json

It might be easier if it found the code size report itself, should I add that feature?

If working in conjunction with Mbed-TLS/TF-PSA-Crypto#590 it would be something like: ``` # Build version A cmake -B build-A . cmake --build build-A --target size # or (cd build-A && make size) # Build version B cmake -B build-B . cmake --build build-B --target size # or (cd build-B && make size) # Compare code size framework/scripts/diff_code_size.py build-A/core/code_size.json build-B/core/code_size.json ``` It might be easier if it found the code size report itself, should I add that feature?
gilles-peskine-arm (Migrated from github.com) reviewed 2025-12-09 05:04:17 -06:00
@ -0,0 +1,89 @@
#!/usr/bin/env python3
"""Examine 2 code size reports and print the difference between them.
gilles-peskine-arm (Migrated from github.com) commented 2025-12-09 05:04:17 -06:00

Ah, ok, you're typically comparing different build options? I find that I mostly want to compare different versions of the same code. That's why mbedtls-size-dwim stores sizes in a file named after the git head sha.

Ah, ok, you're typically comparing different build options? I find that I mostly want to compare different versions of the same code. That's why mbedtls-size-dwim stores sizes in a file named after the git head sha.
gilles-peskine-arm (Migrated from github.com) reviewed 2025-12-09 05:05:07 -06:00
gilles-peskine-arm (Migrated from github.com) commented 2025-12-09 05:05:07 -06:00

The changed config should be only in the build directory, not in the source directory. Otherwise the script isn't really usable outside the CI.

The changed config should be only in the build directory, not in the source directory. Otherwise the script isn't really usable outside the CI.
davidhorstmann-arm (Migrated from github.com) reviewed 2025-12-18 08:42:00 -06:00
@ -0,0 +1,89 @@
#!/usr/bin/env python3
"""Examine 2 code size reports and print the difference between them.
davidhorstmann-arm (Migrated from github.com) commented 2025-12-18 08:42:00 -06:00

Usually I need to compare different options but assessing the code size impact of a config option happens often enough that I value the flexibility.

Usually I need to compare different options but assessing the code size impact of a config option happens often enough that I value the flexibility.
davidhorstmann-arm (Migrated from github.com) reviewed 2025-12-18 09:40:01 -06:00
davidhorstmann-arm (Migrated from github.com) commented 2025-12-18 09:40:01 -06:00

I have added a switch --config-name allowing a config to be specified. config.py is run on a copy of the config file in the build directory that is then used. This can be implemented in a 20% more nifty way once Mbed-TLS/TF-PSA-Crypto#531 is merged.

I have added a switch `--config-name` allowing a config to be specified. `config.py` is run on a copy of the config file in the build directory that is then used. This can be implemented in a 20% more nifty way once Mbed-TLS/TF-PSA-Crypto#531 is merged.
davidhorstmann-arm (Migrated from github.com) reviewed 2026-01-09 10:49:32 -06:00
davidhorstmann-arm (Migrated from github.com) commented 2026-01-09 10:49:32 -06:00

Reimplemented using TF_PSA_CRYPTO_CONFIG_NAME

Reimplemented using `TF_PSA_CRYPTO_CONFIG_NAME`
This pull request is broken due to missing fork information.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'davidhorstmann-arm/code-size-measurement-script:davidhorstmann-arm/code-size-measurement-script'
git switch 'davidhorstmann-arm/code-size-measurement-script'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'davidhorstmann-arm/code-size-measurement-script'
git switch 'davidhorstmann-arm/code-size-measurement-script'
git rebase 'main'
git switch 'main'
git merge --ff-only 'davidhorstmann-arm/code-size-measurement-script'
git switch 'davidhorstmann-arm/code-size-measurement-script'
git rebase 'main'
git switch 'main'
git merge --no-ff 'davidhorstmann-arm/code-size-measurement-script'
git switch 'main'
git merge --squash 'davidhorstmann-arm/code-size-measurement-script'
git switch 'main'
git merge --ff-only 'davidhorstmann-arm/code-size-measurement-script'
git switch 'main'
git merge 'davidhorstmann-arm/code-size-measurement-script'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-Mbed-TLS/mbedtls-framework!246
No description provided.