Did you know any other way to do this with the current port?
This is on my list to look into. I will bump it up in priority and let you know what I discover.
Are you comfortable with using GDB, the GNU Debugger? I have an introduction on how to use GDB with GCC4MBED here. Any solution that I come up with to dump the heap statistics will probably be through the debugger.
If you are using the version of GCC installed by GCC4MBED's install scripts then you can use the following command in GDB to dump the amount of memory currently dedicated to the heap:
printf "heap size=%d\n",**(int**)(_sbrk+28) - ((((int)&Image$$RW_IRAM1$$ZI$$Limit)+7)&~7)
Sorry that it is so ugly. It turns out that there are no symbols for the _sbrk() implementation used by the current GCC4MBED so I have to reach into the _sbrk() machine code to pull out the pointers I want from its literal pool. If you installed a different version of GCC yourself and added it to your PATH then the above trick will not work since the code output will be slightly different.
There can be free chunks within this heap but printed values of heap size will tell you the maximum amount of heap that was required or if it is growing over multiple samples. I don't believe that the heap implementation in newlib-nano will ever decrease this value (the standard newlib implementation would.) So even if you free up everything, you will still see the maximum heap size ever required printed by the above command. However, the heap will be tracking free space with this heap and new allocations will be satisfied from it first before it grows the heap any more.
If you don't mind growing the size of your program, you could also switch back to using the standard newlib library instead. This would allow malloc_stats() to work. You could edit build/gcc4mbed.mk to change this line:
SYS_LIBS = -lstdc++_s -lsupc++_s -lm -lgcc -lc_s -lgcc -lc_s -lnosys
to
SYS_LIBS = -lstdc++ -lsupc++ -lm -lgcc -lc -lgcc -lc -lnosys
I hope that helps,
Adam
Do you get a prompt for a Authentication Realm password at this time?
No, I did not get it.