Skip to content

os/tools/memstats_gnueabil.py : Show all section details dynamically#7352

Open
anjana348 wants to merge 1 commit into
Samsung:masterfrom
anjana348:memstats
Open

os/tools/memstats_gnueabil.py : Show all section details dynamically#7352
anjana348 wants to merge 1 commit into
Samsung:masterfrom
anjana348:memstats

Conversation

@anjana348
Copy link
Copy Markdown
Contributor

@anjana348 anjana348 commented May 19, 2026

os/tools/memstats_gnueabil.py : Show all section details dynamically

  1. The updated script dynamically discovers all memory sections from the map file instead of hardcoding only 3 sections '.text/.data/.bss',
    revealing previously invisible sections like '.iram', '.psram_bss', '.psram_data' that contain significant memory usage

  2. Size of sections like(.text) were smaller than actual previously

  3. Added total RAM/FLASH memory usage

Previous output:
.data .bss .text Total
6100 4920 187469 198489 libboard.a

Current output:
Library/Binary .vectors .text .iram .data .bss .psram_data .psram_bss SRAM PSRAM Flash Other Total
libboard.a 416 332210 7408 6100 4920 0 11700 18428 11700 332626 0 362754

Usage:
python3 os/tools/memstats_gnueabil.py --help -----> It will give all command details
For ex - to see memory information

python3 os/tools/memstats_gnueabil.py -m -f ../Beken/xip_all/tinyara.map

Detected Board: bk7239n

Section Categories (dynamically detected from map file):
FLASH: .text, .vectors
SRAM: .bss, .data, .iram
PSRAM: .psram_bss, .psram_data

Memory Distribution
SRAM: 288685 bytes (18.95%)
PSRAM: 38080 bytes (2.50%)
Flash: 1196883 bytes (78.55%)

@sunghan-chang
Copy link
Copy Markdown
Contributor

  1. Let's add the example you wrote at the commit description as well.
  2. Sorry, but I don't know usage of new information. What can we know using them more for?

@seokhun-eom24
Copy link
Copy Markdown
Contributor

seokhun-eom24 commented May 19, 2026

Automated nightly Codex PR review
PR: #7352 — os/tools/memstats_gnueabil.py : Show all section details dynamically
PR URL: #7352
GitHub updatedAt: 2026-05-22T11:30:58Z
Refreshed (UTC): 2026-05-22 17:40:13 UTC
Refreshed (KST): 2026-05-23 02:40:13 KST
Comment model: single evolving Codex-authored PR comment

PR #7352 — os/tools/memstats_gnueabil.py : Show all section details dynamically

This review done by codex. AI reviews can be inaccurate.
UTC: 2026-05-22 17:39 UTC
KST (UTC+9): 2026-05-23 02:39 KST


Repository: Samsung/TizenRT

Base → Head: master (eb85fed9d49bf108bce4ca17cae77a1d9336b02f) → pr/7352

HEAD Commit: 9ea23ae67af5c239466a103279d05922c322f0a8

Scope: os/tools/memstats_gnueabil.py dynamic section discovery and board-aware memory reporting.


Review Summary

Category Status
Build / Compile Status ⚠️ python3 -m py_compile succeeds, but emits SyntaxWarning from new regex strings
Functional Correctness ❌ Memory summary can under-report allocated RAM/PSRAM totals
Validation Coverage ⚠️ Local checks used existing map files; no PR-owned regression fixture was added

Final Verdict: ❗ Request Changes


Must-Fix Issues

1. Memory summary omits non-library allocated sections from RAM/PSRAM totals
Item Details
Location os/tools/memstats_gnueabil.py:650
Severity High
Type Functional correctness

Problem
The new -m/--memory report is advertised as total SRAM/DRAM/PSRAM/Flash usage, but it builds the section list and grand total only from sectionLibSizes. Sections that consume memory but are not attributed to an archive/object entry are excluded from the category totals and percentages.

Impact

  • BK7239N reports can show a very small PSRAM total even when the linker map reserves a large PSRAM heap.
  • The final "Memory Distribution" percentages can mislead release/build reviewers about actual memory pressure.
  • This is especially risky for embedded footprint checks because heap, stack, and reserved memory windows are part of the image's memory layout even when they do not belong to a library.

Evidence

  • os/tools/memstats_gnueabil.py:650 to os/tools/memstats_gnueabil.py:669 only categorizes sections returned by getActiveSections(), and getActiveSections() only returns sections that have non-zero sectionLibSizes.
  • os/tools/memstats_gnueabil.py:693 to os/tools/memstats_gnueabil.py:704 accumulates SRAM/DRAM/PSRAM/Flash from per-library entries, not from top-level sectionInfo sizes.
  • os/tools/memstats_gnueabil.py:727 computes grandTotal from libMemory, so the distribution denominator also excludes non-library sections.
  • Local validation on /home/seokhun/public/TizenRT/master/build/output/bin/tinyara.map showed -s listing .psram_heap as 0x276b40 bytes, but -m reported PSRAM as only 38080 bytes because the heap section has no library ownership.

Required Fix
Files to edit:

  • os/tools/memstats_gnueabil.pyprintMemorySummary() and the helper that selects active/categorized sections

Change outline:

  • Keep the per-library table if desired, but compute the category totals from top-level sectionInfo for all allocated display sections.
  • Include sections without library ownership, such as .heap, .stack, .psram_heap, and board-specific reserved windows, in the summary totals.
  • If the table remains library-oriented, add a clear Unattributed row or a separate "Section Total" summary so the displayed totals equal the section-category totals.

Example patch:

diff --git a/os/tools/memstats_gnueabil.py b/os/tools/memstats_gnueabil.py
@@
-    activeSections = getActiveSections()
+    activeSections = [
+        sec for sec in displaySections
+        if sectionInfo.get(sec, {}).get('size', 0) > 0 or sec in sectionLibSizes
+    ]
@@
-    grandTotal = sum(libMemory[lib]['total'] for lib in sortedLibs)
+    categoryTotals = {'SRAM': 0, 'DRAM': 0, 'PSRAM': 0, 'FLASH': 0, 'OTHER': 0}
+    for secName in activeSections:
+        categoryTotals[categorizeSection(secName)] += sectionInfo.get(secName, {}).get('size', 0)
+    grandTotal = sum(categoryTotals.values())

Inference:

  • The exact display shape is a review recommendation; the confirmed issue is that current totals are derived from library-attributed sizes and exclude allocated sections visible in the same map file.

Validation Method

  • Run python3 os/tools/memstats_gnueabil.py -s -f build/output/bin/tinyara.map and python3 os/tools/memstats_gnueabil.py -m -f build/output/bin/tinyara.map on a BK7239N map.
  • Verify the PSRAM summary includes .psram_data + .psram_bss + .psram_heap; for the reviewed local map this is 1056 + 37024 + 2583360 = 2621440 bytes, not 38080.
  • Add a small synthetic map fixture with library-owned sections plus .heap/.psram_heap and assert the memory distribution includes both owned and unattributed sections.

Nice-to-Have Improvements

1. New regex literals emit Python 3 SyntaxWarning on every invocation
Item Details
Location os/tools/memstats_gnueabil.py:221
Severity Low
Type Maintainability

Problem
The new regex strings use backslashes inside normal Python string literals. Python 3 emits SyntaxWarning: invalid escape sequence '\*' for the new expressions.

Impact

  • Tool output and CI logs become noisy even when parsing succeeds.
  • The warnings make it harder to spot real script failures in automation.

Recommended Action

  • Use raw string literals for the regex patterns at os/tools/memstats_gnueabil.py:221, os/tools/memstats_gnueabil.py:248, and os/tools/memstats_gnueabil.py:286.
  • For example, change '\*\(.*\)' to r'\*\(.*\)' and '\*fill\*' to r'\*fill\*'.

Example Validation Matrix

Area Example Target / Check Result
Syntax check python3 -m py_compile os/tools/memstats_gnueabil.py Should pass without warnings
Runtime check python3 os/tools/memstats_gnueabil.py -m -f <map> Should not print warning text before the report

Notable Improvements

✔ Dynamic section columns make the library report more complete

  • The new -l output no longer collapses all code into only .text/.data/.bss; it exposes sections such as .vectors, .iram, .psram_data, .psram_bss, and RTL-specific XIP/BT trace sections.

✔ Board-aware category labels improve readability

  • The memory summary distinguishes RTL8730E DRAM-style output from BK7239N PSRAM-style output, which is more useful than a single generic RAM label for these boards.

Final Assessment

Must-Fix Summary

  • Fix the -m/--memory totals so they include allocated non-library sections before merging. The current report can substantially understate PSRAM/RAM usage.

Nice-to-Have Summary

  • Convert new regex strings to raw literals to remove Python 3 warning noise.

Residual Risk

  • I did not run a full board build. The review used static inspection plus local runs against existing BK7239N and RTL8730E map files.

Final Verdict

❗ Request Changes

The dynamic section report is useful, but the memory distribution must be corrected before it is reliable for embedded footprint decisions.

@seokhun-eom24
Copy link
Copy Markdown
Contributor

Could you update commit and PR title?
It's os/tools/memstats_gnueabil.py file.
'a' is missing.

@anjana348 anjana348 changed the title os/tools/memstats_gnuebil.py : Show all section details dynamically os/tools/memstats_gnueabil.py : Show all section details dynamically May 20, 2026
@anjana348
Copy link
Copy Markdown
Contributor Author

  1. Let's add the example you wrote at the commit description as well.
  2. Sorry, but I don't know usage of new information. What can we know using them more for?

Current method shows 3 fixed memory sections(.data, .bss, .text), as Mr Nam asked to check for any missing sections,
we updated code to dynamically identify sections without hardcoding, now we have more info like psram_data, psram_bss memory usage of each library and object file

1. The updated script dynamically discovers all memory sections from the map file instead of hardcoding only 3 sections '.text/.data/.bss',
revealing previously invisible sections like '.iram', '.psram_bss', '.psram_data' that contain significant memory usage

2. Size of sections like(.text) were smaller than actual previously

Previous output:
.data   .bss    .text    Total
 6100    4920    187469  198489  libboard.a

Current output:
Library/Binary   .vectors   .text .iram .data   .bss .psram_data .psram_bss           SRAM          PSRAM          Flash          Other   Total
-----------------------------------------------------------------------------------------------------------------------------------------------
libboard.a            416  332210  7408  6100   4920           0      11700          18428          11700         332626              0  362754

Usage:
python3 os/tools/memstats_gnueabil.py --help -----> It will give all command details
For ex - to see memory information

python3 os/tools/memstats_gnueabil.py -m -f ../Beken/xip_all/tinyara.map

Detected Board: bk7239n

Section Categories (dynamically detected from map file):
  FLASH: .text, .vectors
  SRAM:  .bss, .data, .iram
  PSRAM:  .psram_bss, .psram_data

Library/Binary   .vectors   .text .iram .data   .bss .psram_data .psram_bss           SRAM          PSRAM          Flash          Other   Total
-----------------------------------------------------------------------------------------------------------------------------------------------
libboard.a            416  332210  7408  6100   4920           0      11700          18428          11700         332626              0  362754
libbluetooth.a          0  219020     0    20  70692           0          0          70712              0         219020              0  289732
libwifi.a               0  156281 44945   216  46080           0          0          91241              0         156281              0  247522
libbk_phy.a             0  144848   480   168   2396           0          0           3044              0         144848              0  147892
libnet.a                0   66698 16900   152  56008         296        176          73060            472          66698              0  140230
libmiddleware.a         0   49946  5680   356  10260           0          0          16296              0          49946              0   66242
libfs.a                 0   63669     0     0      0           0         64              0             64          63669              0   63733
libkernel.a             0   44303  4072     0      0           4      13580           4072          13584          44303              0   61959
libkarch.a              0   16847  2060   528   9220         528        860          11808           1388          16847              0   30043
libkmm.a                0   18267     0     0      0          24       9592              0           9616          18267              0   27883
libkc.a                 0   22038     0     0      0          12        296              0            308          22038              0   22346
libcompression.a        0   15776     0     0      0           4         12              0             16          15776              0   15792
libdrivers.a            0   14387     0     0      0           0        360              0            360          14387              0   14747
libse.a                 0    7996     0     0      0         140        256              0            396           7996              0    8392
NOLIB                   0    6256     0     0      0           0          0              0              0           6256              0    6256
libgcc.a                0    5288     0     0      0           0          0              0              0           5288              0    5288
libpm.a                 0    4470     0     0      0          36         60              0             96           4470              0    4566
libbinfmt.a             0    4068     0     0      0          12         40              0             52           4068              0    4120
libstubs.a              0    2182     0     0      0           0          0              0              0           2182              0    2182
libkwque.a              0    1153     0     0      0           0         28              0             28           1153              0    1181
libbk_coex.a            0     764     0     0     24           0          0             24              0            764              0     788
-----------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                 416 1196467 81545  7540 199600        1056      37024         288685          38080        1196883              0 1523648

Memory Distribution:
  SRAM:   288685 bytes (18.95%)
  PSRAM:  38080 bytes (2.50%)
  Flash:  1196883 bytes (78.55%)
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.

3 participants