Example to demonstrate usage of mbed_stats_stack_get_each API

Fork of heap_stats_example by mbed_example

Revision:
2:cbb9a9884f45
Parent:
0:a5479359bf28
Child:
3:c084f1df237e
--- a/main.cpp	Fri May 25 19:55:07 2018 +0000
+++ b/main.cpp	Thu Aug 30 16:42:01 2018 +0000
@@ -1,13 +1,22 @@
-#include <stdlib.h>
 #include "mbed.h"
-#include "mbed_mem_trace.h"
+#include "mbed_stats.h"
 
+int main(void)
+{
+    mbed_stats_heap_t heap_stats;
+
+    printf("Starting heap stats example\r\n");
 
-int main() {
-    mbed_mem_trace_set_callback(mbed_mem_trace_default_callback);
-    while (true) {
-        void *p = malloc(50);
-        wait(0.5);
-        free(p);
-    }
+    void *allocation = malloc(1000);
+    printf("Freeing 1000 bytes\r\n");
+
+    mbed_stats_heap_get(&heap_stats);
+    printf("Current heap: %lu\r\n", heap_stats.current_size);
+    printf("Max heap size: %lu\r\n", heap_stats.max_size);
+
+    free(allocation);
+
+    mbed_stats_heap_get(&heap_stats);
+    printf("Current heap after: %lu\r\n", heap_stats.current_size);
+    printf("Max heap size after: %lu\r\n", heap_stats.max_size);
 }