|
| 1 | +## Mbed statistics |
| 2 | + |
| 3 | +Mbed OS provides a set of functions that you can use to capture the memory and thread statistics at runtime. `mbed_stats.h` declares these functions. To enable all Mbed OS statistics, you must build code with the `MBED_ALL_STATS_ENABLED` macro. |
| 4 | + |
| 5 | +### Memory statistics |
| 6 | + |
| 7 | +You can use memory statistics functions to capture heap usage, cumulative stack usage or stack usage per thread at runtime. To enable memory usage monitoring, you must build Mbed OS with the following macros: |
| 8 | + |
| 9 | +- `MBED_HEAP_STATS_ENABLED`. |
| 10 | +- `MBED_STACK_STATS_ENABLED`. |
| 11 | + |
| 12 | +### Thread statistics |
| 13 | + |
| 14 | +You can use the thread statistics function `mbed_stats_thread_get_each` to capture the thread ID, state, priority, name and stack information for all active threads at runtime. To enable thread monitoring, you must build Mbed OS with the `MBED_THREAD_STATS_ENABLED` macro. |
| 15 | + |
| 16 | +### System information |
| 17 | + |
| 18 | +You can use the `mbed_stats_sys_get` function to get the CPU ID and compiler information. You must build Mbed OS with the `MBED_SYS_STATS_ENABLED` macro to enable fetching of system information. |
| 19 | + |
| 20 | +### CPU statistics |
| 21 | + |
| 22 | +You can use the `mbed_stats_cpu_get` function to get the uptime, idle time and sleep time information. Timing information available is cumulative since the system is on. You must build Mbed OS with the `MBED_CPU_STATS_ENABLED` macro to enable fetching of CPU information. Please note CPU statistics depend on the availability of the low power timer in the hardware. |
| 23 | + |
| 24 | +### Mbed statistics functions reference |
| 25 | + |
| 26 | +[](http://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/mbed__stats_8h_source.html) |
| 27 | + |
| 28 | +### Memory statistics example |
| 29 | + |
| 30 | +[](https://os.mbed.com/teams/mbed_example/code/mbed-os-example-platform-utils/file/92b97ba04fd3/main.cpp) |
| 31 | + |
| 32 | +### Thread statistics example |
| 33 | + |
| 34 | +[](https://os.mbed.com/teams/mbed_example/code/thread_statistics/file/8cfc3eff0d78/main.cpp/) |
| 35 | + |
| 36 | +### System information example |
| 37 | + |
| 38 | +[](https://os.mbed.com/teams/mbed_example/code/system_information/file/8189a62cbb4e/main.cpp/) |
| 39 | + |
| 40 | +### CPU statistics example |
| 41 | + |
| 42 | +[](https://os.mbed.com/teams/mbed_example/code/cpu_stats/file/de30f5166672/main.cpp/) |
| 43 | + |
| 44 | +### CPU usage example |
| 45 | + |
| 46 | +[](https://os.mbed.com/teams/mbed_example/code/cpu_usage_calculation/file/358f7cf7196d/main.cpp/) |
0 commit comments