cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
cerilet
Explorer
Explorer
12,056 Views
Registered: ‎08-26-2014

How to check how much memory a program is using?

Jump to solution

Hello,

 

I am using the SDK to program a Zynq and checking the different optimization options.

 

Actually, I am getting impressive execution time improvement (85%) when changing the compiler optimization options from -O0 to -O3 plus adding -mcpu=cortex-a9. I  guess the compiler is using the VFPv3 or the NEON vectorization automatically.

 

But there must be an increase in memory usage, am I right? How can be measured the memory used by the program?

 

Thanks.

 

Cerilet

0 Kudos
Reply
1 Solution

Accepted Solutions
cerilet
Explorer
Explorer
18,812 Views
Registered: ‎08-26-2014

Ok, finally!

 

I have found the way to introduce the linker options when called from GCC here:

 

Note---if the linker is being invoked indirectly, via a compiler driver (e.g. gcc) then all the linker command line options should be prefixed by -Wl, (or whatever is appropriate for the particular compiler driver) like this:

 

gcc -Wl,--start-group foo.o bar.o -Wl,--end-group

This is important, because otherwise the compiler driver program may silently drop the linker options, resulting in a bad link.

 

So you have to right click on the project folder in the Project Explorer and then select C/C++ Build Settings -> ARM gcc linker -> Miscellaneous and add in the Linker Flags -Wl,-M=output.map to be able to generate the map file.

 

Now the only (uh) thing left is to understand the file.

 

Many thanks Austin for your help!

 

View solution in original post

0 Kudos
Reply
6 Replies
austin
Scholar
Scholar
12,049 Views
Registered: ‎02-27-2008

c,

 

In the past, a technique I used was to create a loop to write some pattern into the data storage area, so that I could the direct another program I wrote to report out how much of that space still had the initial value in it.  I know that reports should be telling you the size (and location) of all variables, but sometimes it is nice to verify what the tools report so you get comfortable with the tool reports.

 

The linker has a 'GNU Objects Dump' that lists all variables, locations, etc.

 

I used 0xAAAAh, or 0x5555h as my pattern (unlikely for huge sections to have this value and be unused).

 

You may also use the Xilinx debugger to do the above XMD (ug1043).

 

 

 

Austin Lesea
Principal Engineer
Xilinx San Jose
cerilet
Explorer
Explorer
11,970 Views
Registered: ‎08-26-2014

Thanks for your reply Austin.

 

So there is not an automated way on SDK to quickly check it?

 

That will take time to implement...

0 Kudos
Reply
austin
Scholar
Scholar
11,968 Views
Registered: ‎02-27-2008

gcc reports memory usage,

 

The GNU compiler/linker does report the memory used.

 

 

Austin Lesea
Principal Engineer
Xilinx San Jose
0 Kudos
Reply
cerilet
Explorer
Explorer
11,953 Views
Registered: ‎08-26-2014

The only output I see in the compiler is this. But is not it just how much memory the program ocuppy? I need to know how much memory the program uses during runtime depending on the optimization option.

 

'Invoking: ARM Print Size'
arm-xilinx-eabi-size simple_tests.elf  |tee "simple_tests.elf.size"
   text       data        bss        dec        hex    filename
  59720       2376    301996236    302058332    12010b5c    simple_tests.elf
'Finished building: simple_tests.elf.size'

By the way, what these values mean?

 

Thanks again for your help.

0 Kudos
Reply
austin
Scholar
Scholar
11,950 Views
Registered: ‎02-27-2008

the option:

 

"--print-map
This command tells the linker to create a map file."

 

is used with gcc.  Look up linker scripting with gnu gcc.

 

 

Austin Lesea
Principal Engineer
Xilinx San Jose
cerilet
Explorer
Explorer
18,813 Views
Registered: ‎08-26-2014

Ok, finally!

 

I have found the way to introduce the linker options when called from GCC here:

 

Note---if the linker is being invoked indirectly, via a compiler driver (e.g. gcc) then all the linker command line options should be prefixed by -Wl, (or whatever is appropriate for the particular compiler driver) like this:

 

gcc -Wl,--start-group foo.o bar.o -Wl,--end-group

This is important, because otherwise the compiler driver program may silently drop the linker options, resulting in a bad link.

 

So you have to right click on the project folder in the Project Explorer and then select C/C++ Build Settings -> ARM gcc linker -> Miscellaneous and add in the Linker Flags -Wl,-M=output.map to be able to generate the map file.

 

Now the only (uh) thing left is to understand the file.

 

Many thanks Austin for your help!

 

View solution in original post

0 Kudos
Reply