Example to demonstrate usage of mbed_stats_stack_get_each API
Fork of heap_stats_example by
Diff: main.cpp
- Revision:
- 4:539750137652
- Parent:
- 3:c084f1df237e
- Child:
- 5:dcc8640ad89c
diff -r c084f1df237e -r 539750137652 main.cpp --- a/main.cpp Thu Aug 30 16:47:16 2018 +0000 +++ b/main.cpp Thu Aug 30 16:51:05 2018 +0000 @@ -3,25 +3,14 @@ int main(void) { - mbed_stats_heap_t heap_stats; + printf("Starting stack stats example\r\n"); - printf("Starting heap stats example\r\n"); - mbed_stats_heap_get(&heap_stats); - printf("Start; Current heap: %lu\n", heap_stats.current_size); - printf("Start; Max heap size: %lu\n", heap_stats.max_size); - - printf("\nAllocating 1000 bytes\n"); - void *allocation = malloc(1000); + int cnt = osThreadGetCount(); + mbed_stats_stack_t *stats = (mbed_stats_stack_t*) malloc(cnt * sizeof(mbed_stats_stack_t)); - mbed_stats_heap_get(&heap_stats); - printf("Post-Alloc; Current heap: %lu\n", heap_stats.current_size); - printf("Post-Alloc; Max heap size: %lu\n", heap_stats.max_size); - - free(allocation); - printf("\nFreed 1000 bytes\n"); - - mbed_stats_heap_get(&heap_stats); - printf("Post-Free; Current heap: %lu\n", heap_stats.current_size); - printf("Post-Free; Max heap size: %lu\n", heap_stats.max_size); - + cnt = mbed_stats_stack_get_each(stats, cnt); + for (int i = 0; i < cnt; i++) { + printf("Thread: 0x%X, Stack size: %u, Max stack: %u\r\n", + stats[i].thread_id, stats[i].reserved_size, stats[i].max_size); + } }