View CPU usage in ucos

Source: Internet
Author: User

First set: # define OS _TASK_STAT_EN 1
A statistical task is created in OSInit ();.

#if OS_TASK_STAT_EN > 0void  OS_TaskStat (void *p_arg){    INT32U     run;    INT32U     max;    INT8S      usage;#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */    OS_CPU_SR  cpu_sr = 0;#endif      p_arg = p_arg;                               /* Prevent compiler warning for not using 'parg'      */    while (OSStatRdy == OS_FALSE) {        OSTimeDly(2 * OS_TICKS_PER_SEC / 10);    /* Wait until statistic task is ready                 */    }    max = OSIdleCtrMax / 100L;    for (;;) {        OS_ENTER_CRITICAL();        OSIdleCtrRun = OSIdleCtr;                /* Obtain the of the idle counter for the past second */        run          = OSIdleCtr;        OSIdleCtr    = 0L;                       /* Reset the idle counter for the next second         */        OS_EXIT_CRITICAL();        if (max > 0L) {            usage = (INT8S)(100L - run / max);            if (usage >= 0) {                    /* Make sure we don't have a negative percentage      */                OSCPUUsage = usage;            } else {                OSCPUUsage = 0;            }        } else {            OSCPUUsage = 0;            max        = OSIdleCtrMax / 100L;        }        OSTaskStatHook();                        /* Invoke user definable hook                         */#if (OS_TASK_STAT_STK_CHK_EN > 0) && (OS_TASK_CREATE_EXT_EN > 0)        OS_TaskStatStkChk();                     /* Check the stacks for each task                     */#endif        OSTimeDly(OS_TICKS_PER_SEC / 10);        /* Accumulate OSIdleCtr for the next 1/10 second      */    }}#endif

View CPU usage in ucos

Now you can output the relevant information in your task:

printf("\r\n\r\n Micrium uC/OS-II  \r\n");    printf(" ST STM32 (Cortex-M3)\r\n\r\n");    printf(" uC/OS-II: V%ld.%ld%ld\r\n",OSVersion()/100,(OSVersion() % 100) /   10,(OSVersion() % 10));    printf(" TickRate: %ld  \r\n",OS_TICKS_PER_SEC);    printf(" CPU Usage: %ld%    \r\n",OSCPUUsage);    printf(" CPU Speed: %ld MHz  \r\n",BSP_CPU_ClkFreq() / 1000000L);    printf(" #Ticks: %ld  \r\n",OSTime);    printf(" #CtxSw: %ld  \r\n",OSCtxSwCtr);

In sequence: version number, CPU usage, clock speed, task switching times, and so on!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.