µC/OS-III contains an internal task that provides such run-time statistics as overall CPU utilization (0.00 to 100.00%), per-task CPU utilization (0.00 to 100.00%), and per-task stack usage. As of V3.03.00, CPU utilization is represented as a integer from 0 to 10,000 (0.00% to 100.00%). Prior to V3.03.00, CPU utilization was represented an integer ranging from 0 to 100.
The statistic task is optional in a µC/OS-III application and its presence is controlled by a compile-time configuration constant OS_CFG_STAT_TASK_EN
defined in os_cfg.h
. Specifically, the code is included in the build when OS_CFG_STAT_TASK_EN
is set to 1.
Also, the priority of this task and the location and size of the statistic task’s stack is configurable via OS_CFG_STAT_TASK_PRIO
declared in os_cfg_app.h
().
If the application uses the statistic task, it should call OSStatTaskCPUUsageInit()
from the first, and only application task created in the main()
function as shown in Listing 5-5. The startup code should create only one task before calling OSStart()
. The single task created is, of course, allowed to create other tasks, but only after calling OSStatTaskCPUUsageInit()
.