memory-report

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

LOCI Memory Report

LOCI 内存报告

Read these values from the LOCI session context (system-reminder block at session start) and substitute them wherever the placeholders appear below:
  • asm-analyze command: <path>
    → use as
    <asm-analyze-cmd>
  • venv python: <path>
    → use as
    <venv-python>
  • plugin dir: <path>
    → use as
    <plugin-dir>
从LOCI会话上下文(会话启动时的system-reminder块)中读取以下值,并替换下方所有对应占位符:
  • asm-analyze command: <path>
    → 用作
    <asm-analyze-cmd>
  • venv python: <path>
    → 用作
    <venv-python>
  • plugin dir: <path>
    → 用作
    <plugin-dir>

Step 0: Check Session Context

步骤0:检查会话上下文

Read architecture and compiler from the LOCI session context (the
system-reminder
block emitted at session start). Look for:
Target: <target>, Compiler: <compiler>, Build: <build>
LOCI target: <loci_target>
Map the LOCI target to supported architectures:
LOCI targetCPU
aarch64A53
armv7e-mCortexM4
armv6-mCortexM0P
tc3xxTC399
If the architecture is not in this table, emit and stop:
Supported: aarch64, armv7e-m, armv6-m, tc3xx
If no compiler was detected, inform the user and stop.
Do not re-run detection scripts — use the values already in the session context.
If the user provides their own binary (.elf, .out, .o, .axf), asm_analyze.py auto-detects architecture from the ELF.
从LOCI会话上下文(会话启动时输出的
system-reminder
块)中读取架构和编译器信息,查找以下内容:
Target: <target>, Compiler: <compiler>, Build: <build>
LOCI target: <loci_target>
将LOCI目标映射到支持的架构:
LOCI targetCPU
aarch64A53
armv7e-mCortexM4
armv6-mCortexM0P
tc3xxTC399
如果架构不在此表中,输出以下内容并终止流程:
Supported: aarch64, armv7e-m, armv6-m, tc3xx
如果未检测到编译器,告知用户后终止流程。
不要重新运行检测脚本,直接使用会话上下文中已有的值。
如果用户自行提供二进制文件(.elf、.out、.o、.axf),asm_analyze.py会自动从ELF中检测架构。

Step 1: Identify the Binary and Optional Map File

步骤1:识别二进制文件和可选映射文件

Determine which binary to analyze:
  1. User provides a binary — use it directly
  2. Build from source — cross-compile for the resolved architecture: <compiler> <flags> -o .loci-build/<arch>/<basename>.elf <source> For per-file analysis, compile with
    -c
    to get a
    .o
    file.
If a linker
.map
file is available (often next to the ELF), the user may provide its path for region budget analysis. Supported map file formats:
  • GCC / GNU ld (also used by TI toolchains) — "Memory Configuration" section
  • IAR EWARM — "PLACEMENT SUMMARY" section with
    place in [start-end]
    entries
  • Keil / ARM Compiler (armlink) — "Execution Region" entries with Base/Max
The parser auto-detects the format. If the format is not recognized, the report completes without region budgets.
确定要分析的二进制文件:
  1. 用户提供二进制文件 —— 直接使用
  2. 从源码构建 —— 针对解析出的架构进行交叉编译: <compiler> <flags> -o .loci-build/<arch>/<basename>.elf <source> 如需单文件分析,添加
    -c
    参数编译得到
    .o
    文件即可。
如果有链接器
.map
文件(通常和ELF文件同目录),用户可提供其路径用于区域预算分析。支持的映射文件格式:
  • GCC / GNU ld(TI工具链也使用该格式)—— 包含"Memory Configuration"段
  • IAR EWARM —— 包含带
    place in [start-end]
    条目的"PLACEMENT SUMMARY"段
  • Keil / ARM Compiler (armlink) —— 包含带Base/Max参数的"Execution Region"条目
解析器会自动检测格式,如果格式无法识别,报告将跳过区域预算部分。

Step 2: Run Memory Map Analysis

步骤2:运行内存映射分析

Single report — full ELF binary

单报告 —— 完整ELF二进制文件

<asm-analyze-cmd> memmap --elf-path <binary> [--map-file <path.map>] [--top-n 10]
<asm-analyze-cmd> memmap --elf-path <binary> [--map-file <path.map>] [--top-n 10]

Single report — relocatable .o file

单报告 —— 可重定位.o文件

<asm-analyze-cmd> memmap --elf-path <file.o>
For
.o
files: section sizes are reported but memory regions are not available (no linker placement). Map files are not applicable.
<asm-analyze-cmd> memmap --elf-path <file.o>
针对
.o
文件:仅报告段大小,无内存区域信息(未经过链接器布局),映射文件不适用。

Delta comparison — two ELF binaries or two .o files

差异对比 —— 两个ELF二进制文件或两个.o文件

<asm-analyze-cmd> memmap --elf-path <new_binary> --comparing-elf-path <old_binary> [--map-file <path.map>]
Use this to compare before/after a code change. The
--elf-path
is the current (new) binary and
--comparing-elf-path
is the base (old) binary.
<asm-analyze-cmd> memmap --elf-path <new_binary> --comparing-elf-path <old_binary> [--map-file <path.map>]
用于对比代码变更前后的内存占用,
--elf-path
当前(新)二进制文件,
--comparing-elf-path
基准(旧)二进制文件。

Incremental .o delta (preferred for per-file checks)

增量.o差异对比(单文件检查首选)

Use this when checking if a change to a single file affected memory usage. Works on individual
.o
object files without needing a fully linked binary.
  1. If a previous
    .o
    exists, save it as
    .o.prev
  2. Compile only the changed source with
    -c
    . Always include
    -g
    to emit DWARF debug info (required by asm-analyze): <compiler> -g <flags> -c <source> -o .loci-build/<arch>/<basename>.o
  3. Run delta comparison: <asm-analyze-cmd> memmap --elf-path .loci-build/<arch>/<basename>.o --comparing-elf-path .loci-build/<arch>/<basename>.o.prev
This gives fast feedback on whether a change grew ROM/RAM without needing a full link.
用于检查单个文件的变更是否影响内存占用,无需完整链接的二进制文件,仅针对单个
.o
目标文件生效。
  1. 如果存在之前编译的
    .o
    文件,将其重命名为
    .o.prev
    保存
  2. 仅编译变更后的源码,添加
    -c
    参数,务必携带
    -g
    参数输出DWARF调试信息(asm-analyze要求): <compiler> -g <flags> -c <source> -o .loci-build/<arch>/<basename>.o
  3. 运行差异对比: <asm-analyze-cmd> memmap --elf-path .loci-build/<arch>/<basename>.o --comparing-elf-path .loci-build/<arch>/<basename>.o.prev
无需完整链接即可快速反馈变更是否增加了ROM/RAM占用。

Optional flags

可选参数

  • --comparing-elf-path <path>
    — base ELF for delta comparison
  • --map-file <path>
    — GCC linker map file; enables region budgets with usage %
  • --top-n <N>
    — number of top consumers per category (default 10)
  • --comparing-elf-path <path>
    —— 差异对比的基准ELF文件
  • --map-file <path>
    —— GCC链接器映射文件,可展示带使用率百分比的区域预算
  • --top-n <N>
    —— 每个分类下展示的Top占用对象数量(默认10)

JSON output

JSON输出

Single report (
mode: "report"
):
  • sections
    — per-section breakdown (name, address, size, type, flags, memory region)
  • summary
    — ROM total, RAM static total, code/rodata/data/bss sizes
  • top_consumers
    — largest functions (ROM) and variables (RAM)
  • memory_regions
    — only when
    --map-file
    provided: per-region origin, length, used, usage_pct
Delta report (
mode: "delta"
):
  • section_deltas
    — per-section before/after/delta/delta_pct
  • summary_delta
    — ROM/RAM totals with before/after/delta
  • symbol_deltas
    — added/removed/changed symbols sorted by delta size
  • memory_regions_delta
    — only when
    --map-file
    provided
单报告
mode: "report"
):
  • sections
    —— 各段明细(名称、地址、大小、类型、标志、内存区域)
  • summary
    —— ROM总大小、RAM静态总大小、code/rodata/data/bss各段大小
  • top_consumers
    —— 占用最大的函数(ROM)和变量(RAM)
  • memory_regions
    —— 仅提供
    --map-file
    时返回:各区域起始地址、总大小、已用大小、使用率
差异报告
mode: "delta"
):
  • section_deltas
    —— 各段变更前后大小、差值、变化百分比
  • summary_delta
    —— ROM/RAM总大小变更前后数值、差值
  • symbol_deltas
    —— 新增/删除/变更的符号,按差值大小排序
  • memory_regions_delta
    —— 仅提供
    --map-file
    时返回

Step 3: Report Results

步骤3:输出结果报告

Section Breakdown

段明细

Memory Report: <binary_name>

Architecture: <arch>
ELF type:     <executable | relocatable>

### Section Breakdown

Section          Address      Size       Type     Region
.text            0x08000000   14,832 B   code     ROM
.rodata          0x0800XXXX    2,048 B   rodata   ROM
.data            0x20000000      512 B   data     RAM
.bss             0x20000200    4,096 B   bss      RAM

内存报告: <binary_name>

架构: <arch>
ELF类型:     <executable | relocatable>

### 段明细

段名              地址         大小        类型     区域
.text            0x08000000   14,832 B   code     ROM
.rodata          0x0800XXXX    2,048 B   rodata   ROM
.data            0x20000000      512 B   data     RAM
.bss             0x20000200    4,096 B   bss      RAM

Summary

摘要

ROM/RAM Summary

ROM total:        16,896 B  (code: 14,832  rodata: 2,064)
RAM static total:  4,608 B  (data: 512  bss: 4,096)

ROM/RAM摘要

ROM总大小:        16,896 B  (code: 14,832  rodata: 2,064)
RAM静态总大小:     4,608 B  (data: 512  bss: 4,096)

Top Consumers

Top占用对象

Top ROM Consumers (by size)

  1. main                    1,248 B  (function)
  2. process_data              896 B  (function)
  3. init_peripherals          784 B  (function)

### Top RAM Consumers (by size)

  1. rx_buffer               2,048 B  (variable)
  2. config                    512 B  (variable)

ROM占用Top(按大小排序)

  1. main                    1,248 B  (函数)
  2. process_data              896 B  (函数)
  3. init_peripherals          784 B  (函数)

### RAM占用Top(按大小排序)

  1. rx_buffer               2,048 B  (变量)
  2. config                    512 B  (变量)

With Map File (region budgets)

带映射文件时的区域预算

Memory Region Budgets

Region    Used / Total          Usage
FLASH     16,896 / 1,048,576   1.6%
RAM        4,608 /   131,072   3.5%
CCMRAM         0 /    65,536   0.0%

内存区域预算

区域      已用/总大小           使用率
FLASH     16,896 / 1,048,576   1.6%
RAM        4,608 /   131,072   3.5%
CCMRAM         0 /    65,536   0.0%

For .o files (no linked addresses)

.o文件报告(无链接地址)

Memory Report: sensor_driver.o (relocatable)

Note: Addresses are zero-based (no linker placement).
Memory regions are not available for object files.

Section          Size       Type
.text            1,248 B    code
.rodata            128 B    rodata
.data               32 B    data
.bss               256 B    bss

ROM estimate:   1,376 B  (code: 1,248  rodata: 128)
RAM estimate:     288 B  (data: 32  bss: 256)

内存报告: sensor_driver.o (可重定位)

备注:地址为零基地址(未经过链接器布局),目标文件无内存区域信息。

段名              大小        类型
.text            1,248 B    code
.rodata            128 B    rodata
.data               32 B    data
.bss               256 B    bss

ROM预估:   1,376 B  (code: 1,248  rodata: 128)
RAM预估:     288 B  (data: 32  bss: 256)

Delta report (two binaries compared)

差异报告(两个二进制文件对比)

Memory Delta: old.elf -> new.elf

Architecture: cortexm

### Section Deltas

Section          Before       After        Delta
.text            14,832 B     15,200 B     +368 B  (+2.5%)
.rodata           2,048 B      2,048 B        0 B  (0.0%)
.data               512 B        640 B     +128 B  (+25.0%)
.bss              4,096 B      4,096 B        0 B  (0.0%)

### Summary

ROM total:       16,880 B -> 17,248 B   +368 B  (+2.2%)
RAM static:       4,608 B ->  4,736 B   +128 B  (+2.8%)

### Top ROM Growth (by delta)

  1. new_function         +368 B  (added)
  2. process_data         +128 B  (896 -> 1024)

### Top RAM Growth (by delta)

  1. new_buffer           +128 B  (added)

内存差异: old.elf -> new.elf

架构: cortexm

### 段差异

段名              变更前       变更后        差值
.text            14,832 B     15,200 B     +368 B  (+2.5%)
.rodata           2,048 B      2,048 B        0 B  (0.0%)
.data               512 B        640 B     +128 B  (+25.0%)
.bss              4,096 B      4,096 B        0 B  (0.0%)

### 摘要

ROM总大小:       16,880 B -> 17,248 B   +368 B  (+2.2%)
RAM静态总大小:    4,608 B ->  4,736 B   +128 B  (+2.8%)

### ROM增长Top(按差值排序)

  1. new_function         +368 B  (新增)
  2. process_data         +128 B  (896 -> 1024)

### RAM增长Top(按差值排序)

  1. new_buffer           +128 B  (新增)

Incremental .o delta

增量.o差异报告

Memory Delta: driver.o.prev -> driver.o

Section          Before       After        Delta
.text               896 B      1,024 B     +128 B  (+14.3%)
.bss                256 B        256 B        0 B  (0.0%)

ROM estimate:    +128 B  (+14.3%)
RAM estimate:       0 B  (0.0%)

### Changed Symbols

  process_data:   +128 B  (896 -> 1024)

内存差异: driver.o.prev -> driver.o

段名              变更前       变更后        差值
.text               896 B      1,024 B     +128 B  (+14.3%)
.bss                256 B        256 B        0 B  (0.0%)

ROM预估变化:    +128 B  (+14.3%)
RAM预估变化:       0 B  (0.0%)

### 变更符号

  process_data:   +128 B  (896 -> 1024)

With map file in delta mode

差异模式下带映射文件的区域预算

Memory Region Budget Delta

Region    Before             After              Delta
FLASH     16,880 / 2,097,152 (0.8%)   17,248 / 2,097,152 (0.8%)   +368 B
RAM        4,608 /   262,144 (1.8%)    4,736 /   262,144 (1.8%)   +128 B

内存区域预算差异

区域      变更前                     变更后                      差值
FLASH     16,880 / 2,097,152 (0.8%)   17,248 / 2,097,152 (0.8%)   +368 B
RAM        4,608 /   262,144 (1.8%)    4,736 /   262,144 (1.8%)   +128 B

LOCI voice remark

LOCI语音备注

Before the footer, add one short LOCI voice remark (max 15 words) that acknowledges the user's work grounded in a specific number from the analysis. Attribute improvements to the user ("clean work", "smart move", "tight code"). For concerns, be honest and constructive with specifics. Skip if the analysis produced no results or the user needs raw data only.
在页脚前添加一条简短的LOCI语音备注(最多15字),结合分析中的具体数值认可用户的工作,将优化成果归功于用户(如“干得漂亮”、“操作很聪明”、“代码很精简”);如果存在问题,给出具体、诚实、有建设性的反馈。如果分析无结果或用户仅需要原始数据可跳过该部分。

LOCI footer

LOCI页脚

After emitting the memory report (single or delta), append this footer once as the very last thing printed — only if N > 0. If no functions were processed, do NOT emit the footer.
Record cumulative stats (run via Bash before rendering the footer):
<venv-python> <plugin-dir>/lib/loci_stats.py record --skill memory-report --functions <N> --mcp-calls 0 --co-reasoning 0
Read cumulative summary (run via Bash; capture output):
<venv-python> <plugin-dir>/lib/loci_stats.py summary
Render the footer — include the summary line only if the command produced output:
─── LOCI · memory-report ──────────────
  <N> symbols (functions + variables) analyzed
    <cumulative-summary-output>        ← omit if empty
────────────────────────────────────────
  • N = unique symbols (functions + variables) reported in the top consumers or changed symbols sections
输出内存报告(单报告或差异报告)后,仅当N>0时在末尾追加以下页脚,如果未处理任何函数则不要输出页脚。
记录累计统计数据(渲染页脚前通过Bash运行):
<venv-python> <plugin-dir>/lib/loci_stats.py record --skill memory-report --functions <N> --mcp-calls 0 --co-reasoning 0
读取累计摘要(通过Bash运行,捕获输出):
<venv-python> <plugin-dir>/lib/loci_stats.py summary
渲染页脚,仅当命令有输出时包含摘要行:
─── LOCI · memory-report ──────────────
  <N> 个符号(函数+变量)已分析
    <cumulative-summary-output>        ← 为空则省略
────────────────────────────────────────
  • N = Top占用对象或变更符号部分中报告的唯一符号(函数+变量)数量