1 year, 3 months ago.

Unable to get heap stats working


I am using the Online Compiler. I have a mbed_app.json file under my project root. It reads:

    "macros": ["MBED_HEAP_STATS_ENABLED=1"]

As far as I can tell, this definition makes it into build. But it does not get listed when I use "Verbose" option in Compile Output, why is this? I copied all the lines out of verbose output and searched for ENABLED ... no hits.

When I try to use the head stats like

#include "mbed_stats.h"
 mbed_stats_heap_t heap_stats;
 printf("Current heap: %lu\r\n", heap_stats.current_size);
 printf("Max heap size: %lu\r\n", heap_stats.max_size);

I always get zero values, as if the stats would not be enabled, why? Even if I malloc() memory, always zero.

Current heap: 0
Max heap size: 0

For full code, see

I would be very grateful if you could help me to get my stats going!

Comment on this question

2 Answers

2 months, 1 week ago.

I struggled with this tonight as I continue learning about mbed's sorcery. The major bit of arcane lore is you can't just use a #define. The build system wants a .json file to enable a library feature... I made an example that hopefully helps.

3 months ago.

Facing same probs ...

To post an answer, please log in.