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

The printed total size differs from calculated from .json #33967

Closed
wangnuannuan opened this issue Apr 2, 2021 · 4 comments · Fixed by #35078
Closed

The printed total size differs from calculated from .json #33967

wangnuannuan opened this issue Apr 2, 2021 · 4 comments · Fixed by #35078
Assignees
Labels
area: Build System bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug Waiting for response Waiting for author's response

Comments

@wangnuannuan
Copy link
Collaborator

Describe the bug
I want to get the rom and ram size by reading the JSON file, so I use the script https:/zephyrproject-rtos/zephyr/blob/master/scripts/footprint/size_report to parse the elf file.

Take rom size as example, the script will print the total size in the terminal and generate a file rom.json. But when I use the following code to calculate the rom size in the JSON file, the printed total size differs from calculated from JSON file.

from anytree.importer import JsonImporter

importer = JsonImporter()
size = 0
with open("./rom.json", "r") as fp:
    root = importer.read(fp)

    for leave in root.leaves:
        size += leave.size
print(size)

@dcpleung @nashif

@wangnuannuan wangnuannuan added the bug The issue is a bug, or the PR is fixing a bug label Apr 2, 2021
@tejlmand
Copy link
Collaborator

tejlmand commented Apr 6, 2021

One reason for this is because the size report itself will take the rom_start, datas and devices sections into consideration, which means the final size reported:

...
├── mpu_config                                                                                      8 0.05%
└── transitions.10586                                                                              12 0.07%
==============================================================================================================
                                                                                                16974

will be larger than the sum of the sizes of the individual symbols.

When you sum the json, it is the sum of the size of each symbol, but the rom_start, datas and devices sections are not having symbols in flash. Furthermore the datas and devices are loaded into ram at startup, so any symbols would be referring to ram addresses.
Everything that takes up space in flash are included in the total sum, but cannot be presented as a symbol in the overview and the json file.

If you compare to objdump, you should find some of the missing size:

$ objdump -h zephyr/zephyr.elf 
Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 rom_start     00000100  00000000  00000000  000000c0  2**2
                  CONTENTS, ALLOC, LOAD, CODE
...
  8 datas         00000040  20000000  00004190  00004250  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  9 devices       00000090  20000040  000041d0  00004290  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA

Note, the section list above is not necessarily complete.

@galak galak added the priority: low Low impact/importance bug label Apr 6, 2021
@galak galak assigned dcpleung and tejlmand and unassigned tejlmand Apr 6, 2021
@dcpleung
Copy link
Member

dcpleung commented Apr 6, 2021

The sizes of individual items are of the items themselves, while the total size takes into account of alignments and padding. That's why the total size is larger.

And one important thing to remember, not all symbols are itemized. There are symbols in the image (for example, strings) that do not appear in the symbol table, and thus not in the list but counted towards total size.

@galak
Copy link
Collaborator

galak commented May 11, 2021

@wangnuannuan any updates on this

@dcpleung dcpleung linked a pull request May 11, 2021 that will close this issue
@wangnuannuan
Copy link
Collaborator Author

#33112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Build System bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug Waiting for response Waiting for author's response
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants