[英]c/c++: How can I know the size of used flash memory?
I recently faced flash overflow problem. 我最近遇到了闪存溢出问题。 After doing some optimization in code, I saved some flash memory and executed software successfully. 在对代码进行了一些优化之后,我保存了一些闪存并成功执行了软件。 I want to how much flash memory is saved through my changes. 我想通过更改保存多少闪存。 Please let me know how can I check for used flash / available flash memory. 请让我知道如何检查已使用的闪存/可用闪存。 Also I want to how much flash is utilized by particular function/file. 我也想知道特定功能/文件使用了多少闪存。
Below mentioned are some info about my developing environment. 下面提到的是有关我的开发环境的一些信息。 - Avr microcontroller with 64 k ram and 512 K flash. -具有64 k ram和512 k flash的Avr微控制器。 - Using freeRtos. -使用freeRtos。 - Using GNU C++ compiler. -使用GNU C ++编译器。 - Using AVRATJTAGEICE for programming and Debugging. -使用AVRATJTAGEICE进行编程和调试。
Please let me know the solution. 请让我知道解决方案。
Regards, Jagadeep. 问候,Jagadeep。
Use size
command from binutils on the generated elf file. 在生成的elf文件上使用binutils的size
命令。 As you seem to use an AVR chip, use avr-size
. 当您似乎使用AVR芯片时,请使用avr-size
。
To get the size of functions, use nm
command from binutils ( avr-nm
on AVR chips). 要获取功能的大小,请使用binutils中的nm
命令(AVR芯片上的avr-nm
)。
Please let me know the solution. 请让我知道解决方案。
Sorry, there's no the solution ! 抱歉,没有解决方案 ! You've gotta getting through what's linked to your final ELF, and decide if it was linked by intend, or unwanted default. 您必须了解与最终ELF链接的内容,并确定它是按有意还是无意的默认值进行链接。
Please let me know how can I check for used flash / available flash memory. 请让我知道如何检查已使用的闪存/可用闪存。
That primarily depends on your actual target hardware platform, so you have to manage to get your .text
section fitting in there. 这主要取决于您的实际目标硬件平台,因此您必须设法使.text
部分适合其中。
Also I want to how much flash is utilized by particular function/file. 我也想知道特定功能/文件使用了多少闪存。
The nm
tool of the GCC binutils provides detailed information about any (global) symbol found in an ELF file and the space it occupies in it's associated section. GCC binutils的nm
工具提供了有关ELF文件中找到的任何(全局)符号的详细信息,以及该符号在其相关部分中占用的空间。 You'll just need to grep
the results for particular functions/classes/namespaces (best demangled!) to accumulate section type and symbol filtered outputs for analysis. 您只需要grep
特定函数/类/命名空间的结果(最好已分解!)以累积节类型和符号过滤后的输出以进行分析。
That's the approach, I've been using for a little tool called nmalyzr
. 这就是方法,我一直在使用一个名为nmalyzr
的小工具。 Sorry to say, as it stands on the GIT repo, its not really working as intended (I've got working versions, that aren't pushed back). 抱歉地说,它位于GIT仓库中,实际上并没有按预期工作(我有工作版本,没有被推迟)。
In general, it's a good strategy to chase for code that has #include <iostream>
statements (no matter if std::cout
or alike are used or not, static instances are provided!), or unwanted newlib/libstdc++ bindings as for eg default exception handling. 通常,追逐具有#include <iostream>
语句(无论是否使用std::cout
之类的东西,提供静态实例!)或不需要的newlib / libstdc ++绑定(例如)的代码都是一个很好的策略。默认异常处理。
GCC's size
program is what you're looking for. 您正在寻找GCC的size
计划。
size
can be passed the full compiled .elf
file. size
可以传递完整的已编译.elf
文件。 It will, by default, output something like this: 默认情况下,它将输出如下内容:
$ size linked-file.elf
text data bss dec hex filename
11228 112 1488 12828 321c linked-file.elf
This is saying: 这是说:
There are
11228
bytes in the.text
"section" of this file. 该文件的.text
“节”中有11228
个字节。 This is generally for functions. 这通常用于功能。
There are112
bytes of initialized data : global variables in the program with initial values. 初始化数据有112
个字节:程序中带有初始值的全局变量。
There are1488
bytes of uninitialized data : global variables without initial values. 有1488
个字节的未初始化数据 :不含初始值的全局变量。
dec
is simply the sum of the previous 3 values: 11228 + 112 + 1488 = 12828
. dec
只是前三个值的总和: 11228 + 112 + 1488 = 12828
。
hex
is simply the hexadecimal representation of the dec
value: 0x321c == 12828
. hex
只是dec
值的十六进制表示形式: 0x321c == 12828
。
For embedded systems, generally dec
needs to be smaller than the flash size of your target device (or the available space on the device). 对于嵌入式系统,通常dec
需要小于目标设备的闪存大小(或设备上的可用空间)。
It is generally sufficient to simply watch the dec
or text
outputs of GCC's size
command to monitor the size of your compiled code over time. 通常,仅需观看GCC的size
命令的dec
或text
输出即可监视一段时间内已编译代码的大小。 A large jump in size often indicates a poorly implemented new feature or constexpr
that are not getting compiled away. 较大的跳跃通常表示未实现的新功能或constexpr
实施不佳。 (Don't forget function-sections
and data-sections
). (不要忘记function-sections
和data-sections
)。
Note : For AVR's, you'll want to use avr-size
for checking the linked size of AVR .elf
files. 注意 :对于AVR,您需要使用avr-size
来检查AVR .elf
文件的链接大小。 avr-size
takes an extra argument of the target chip and will automatically calculate the percentage of used flash for your chosen chip. avr-size
会额外增加目标芯片的参数,并将自动计算所选芯片的已用闪存百分比。
GCC's size
also works directly on intermediate object files. GCC的size
也可以直接作用于中间目标文件。
This is particularly useful if you want to check the compiled size of functions. 如果要检查函数的编译大小,此功能特别有用。
You should see something like this excerpt: 您应该看到类似以下摘录的内容:
$ size -A main.cpp.o
main.cpp.o :
section size addr
.group 8 0
.group 8 0
.text 0 0
.data 0 0
.bss 0 0
.text._Z8sendByteh 8 0
.text._ZN3XMC5IOpin7setModeENS0_4ModeE 64 0
.text._ZN7NamSpac6OptionIN5Clock4TimeEEmmEi 76 0
.text.Default_Handler 24 0
.text.HardFault_Handler 16 0
.text.SVC_Handler 16 0
.text.PendSV_Handler 16 0
.text.SysTick_Handler 28 0
.text._Z5errorPKc 8 0
.text._ZN7NamSpac5Motor2goEi 368 0
.text._ZN7NamSpac5Motor3getEv 12 0
.rodata.cst1 1 0
.text.startup.main 632 0
.text._ZN7NamSpac7Program3runEv 380 0
.text._ZN7NamSpac8Position4tickEv 24 0
.text.startup._GLOBAL__sub_I__ZN7NamSpac7displayE 292 0
.init_array 4 0
.bss._ZN5Debug9formatterE 4 0
.rodata._ZL10dispDigits 8 0
.bss.position 4 0
.bss.motorState 4 0
.bss.count 4 0
.rodata._ZL9diameters 20 0
.bss._ZN7NamSpac8diameterE 16 0
.bss._ZN5Debug3pinE 12 0
.bss._ZN7NamSpac7displayE 24 0
.rodata.str1.4 153 0
.rodata._ZL12dispSegments 32 0
.bss._ZL16diametersDisplay 10 0
.bss.loadAggregate 4 0
.bss.startCount 4 0
.bss._ZL15runtimesDisplay 10 0
.bss._ZN7NamSpac7runtimeE 16 0
.bss.startTime 4 0
.rodata._ZL8runtimes 20 0
.comment 111 0
.ARM.attributes 49 0
Total 2494
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.