Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12621 Discussions

Profiling total memory usage in Nios II

Honored Contributor II

Hi, everybody! 

A C program is running on a Nios II processor. At the rate of 100 ns, for instance, I need to catch the total memory the program is using, including there the text memory, the data memory, the bss, the heap and the stack. I'm talking about embedded systems, if you understand what I mean about total memory usage in this case. 

Do I need to have any Operating System running on this processor to get this kind of information? Is there any memory-related service I can call to obtain this information? 

Using a procedure like this, my intention is to get the largest amount of memory used by each function of the program, so I can find the critical functions in terms of memory usage. 

Yes, it sounds like profiling with GProf in GCC. I want to implement, now, a basic resource to profile total memory usage with GCC and, further, get the usage of each kind of memory (text, data, bss, heap, stack). 

Any help will be welcome.
0 Kudos
1 Reply
Honored Contributor II

1) If you are worried about memory footprint, it is best to avoid malloc() (ok malloc() is ok - just don't call free()!) then it memory can't run out at inopportune moments. 


2) Code, data, bss and other segments sizes can be found from 'objdump -h' or 'size -A' (and other requests) on the final image. 


3) Stack use is more problematic. If you have no recursive calls and no calls via function pointers it is possible to write a C program to analise the generated code to sort out the call graph and stack level at each call. I process the output of 'gcc -S -fverbose-asm ...' in order to statically count the worst case execution time of my code (there are no function calls in it!) I also use a few asm statements to mark some paths as 'to be ignored'.
0 Kudos