Example to demonstrate usage of mbed_stats_stack_get_each API
Fork of heap_stats_example by
Revision 5:dcc8640ad89c, committed 2018-08-31
- Comitter:
- deepikabhavnani
- Date:
- Fri Aug 31 16:52:13 2018 +0000
- Parent:
- 4:539750137652
- Commit message:
- Fix build warning and free allocated memory
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Aug 30 16:51:05 2018 +0000 +++ b/main.cpp Fri Aug 31 16:52:13 2018 +0000 @@ -8,9 +8,12 @@ int cnt = osThreadGetCount(); mbed_stats_stack_t *stats = (mbed_stats_stack_t*) malloc(cnt * sizeof(mbed_stats_stack_t)); - 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); + if (stats) { + cnt = mbed_stats_stack_get_each(stats, cnt); + for (int i = 0; i < cnt; i++) { + printf("Thread: 0x%lx, Stack size: %u, Max stack: %u\r\n", + stats[i].thread_id, stats[i].reserved_size, stats[i].max_size); + } + free(stats); } }