Example to demonstrate usage of mbed_stats_stack_get_each API

Fork of heap_stats_example by mbed_example

Committer:
deepikabhavnani
Date:
Thu Aug 30 16:47:16 2018 +0000
Revision:
3:c084f1df237e
Parent:
2:cbb9a9884f45
Child:
4:539750137652
Update the heap example

Who changed what in which revision?

UserRevisionLine numberNew contents of line
deepikabhavnani 0:a5479359bf28 1 #include "mbed.h"
deepikabhavnani 2:cbb9a9884f45 2 #include "mbed_stats.h"
deepikabhavnani 0:a5479359bf28 3
deepikabhavnani 2:cbb9a9884f45 4 int main(void)
deepikabhavnani 2:cbb9a9884f45 5 {
deepikabhavnani 2:cbb9a9884f45 6 mbed_stats_heap_t heap_stats;
deepikabhavnani 2:cbb9a9884f45 7
deepikabhavnani 2:cbb9a9884f45 8 printf("Starting heap stats example\r\n");
deepikabhavnani 3:c084f1df237e 9 mbed_stats_heap_get(&heap_stats);
deepikabhavnani 3:c084f1df237e 10 printf("Start; Current heap: %lu\n", heap_stats.current_size);
deepikabhavnani 3:c084f1df237e 11 printf("Start; Max heap size: %lu\n", heap_stats.max_size);
deepikabhavnani 0:a5479359bf28 12
deepikabhavnani 3:c084f1df237e 13 printf("\nAllocating 1000 bytes\n");
deepikabhavnani 2:cbb9a9884f45 14 void *allocation = malloc(1000);
deepikabhavnani 2:cbb9a9884f45 15
deepikabhavnani 2:cbb9a9884f45 16 mbed_stats_heap_get(&heap_stats);
deepikabhavnani 3:c084f1df237e 17 printf("Post-Alloc; Current heap: %lu\n", heap_stats.current_size);
deepikabhavnani 3:c084f1df237e 18 printf("Post-Alloc; Max heap size: %lu\n", heap_stats.max_size);
deepikabhavnani 2:cbb9a9884f45 19
deepikabhavnani 2:cbb9a9884f45 20 free(allocation);
deepikabhavnani 3:c084f1df237e 21 printf("\nFreed 1000 bytes\n");
deepikabhavnani 2:cbb9a9884f45 22
deepikabhavnani 2:cbb9a9884f45 23 mbed_stats_heap_get(&heap_stats);
deepikabhavnani 3:c084f1df237e 24 printf("Post-Free; Current heap: %lu\n", heap_stats.current_size);
deepikabhavnani 3:c084f1df237e 25 printf("Post-Free; Max heap size: %lu\n", heap_stats.max_size);
deepikabhavnani 3:c084f1df237e 26
deepikabhavnani 0:a5479359bf28 27 }