Example to demonstrate usage of mbed_stats_stack_get_each API

Fork of heap_stats_example by mbed_example

Committer:
deepikabhavnani
Date:
Fri Aug 31 16:52:13 2018 +0000
Revision:
5:dcc8640ad89c
Parent:
4:539750137652
Fix build warning and free allocated memory

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 4:539750137652 6 printf("Starting stack stats example\r\n");
deepikabhavnani 2:cbb9a9884f45 7
deepikabhavnani 4:539750137652 8 int cnt = osThreadGetCount();
deepikabhavnani 4:539750137652 9 mbed_stats_stack_t *stats = (mbed_stats_stack_t*) malloc(cnt * sizeof(mbed_stats_stack_t));
deepikabhavnani 2:cbb9a9884f45 10
deepikabhavnani 5:dcc8640ad89c 11 if (stats) {
deepikabhavnani 5:dcc8640ad89c 12 cnt = mbed_stats_stack_get_each(stats, cnt);
deepikabhavnani 5:dcc8640ad89c 13 for (int i = 0; i < cnt; i++) {
deepikabhavnani 5:dcc8640ad89c 14 printf("Thread: 0x%lx, Stack size: %u, Max stack: %u\r\n",
deepikabhavnani 5:dcc8640ad89c 15 stats[i].thread_id, stats[i].reserved_size, stats[i].max_size);
deepikabhavnani 5:dcc8640ad89c 16 }
deepikabhavnani 5:dcc8640ad89c 17 free(stats);
deepikabhavnani 4:539750137652 18 }
deepikabhavnani 0:a5479359bf28 19 }