ucos中对CPU使用率查看

首先设置:#define OS_TASK_STAT_EN           1 
                   在OSInit();中就建立了统计任务
  

[cpp]  view plain copy
  1. #if OS_TASK_STAT_EN > 0  
  2. void  OS_TaskStat (void *p_arg)  
  3. {  
  4.     INT32U     run;  
  5.     INT32U     max;  
  6.     INT8S      usage;  
  7. #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */  
  8.     OS_CPU_SR  cpu_sr = 0;  
  9. #endif  
  10.   
  11.    
  12.   
  13.    
  14.   
  15.   
  16.     p_arg = p_arg;                               /* Prevent compiler warning for not using 'parg'      */  
  17.     while (OSStatRdy == OS_FALSE) {  
  18.         OSTimeDly(2 * OS_TICKS_PER_SEC / 10);    /* Wait until statistic task is ready                 */  
  19.     }  
  20.     max = OSIdleCtrMax / 100L;  
  21.     for (;;) {  
  22.         OS_ENTER_CRITICAL();  
  23.         OSIdleCtrRun = OSIdleCtr;                /* Obtain the of the idle counter for the past second */  
  24.         run          = OSIdleCtr;  
  25.         OSIdleCtr    = 0L;                       /* Reset the idle counter for the next second         */  
  26.         OS_EXIT_CRITICAL();  
  27.         if (max > 0L) {  
  28.             usage = (INT8S)(100L - run / max);  
  29.             if (usage >= 0) {                    /* Make sure we don't have a negative percentage      */  
  30.                 OSCPUUsage = usage;  
  31.             } else {  
  32.                 OSCPUUsage = 0;  
  33.             }  
  34.         } else {  
  35.             OSCPUUsage = 0;  
  36.             max        = OSIdleCtrMax / 100L;  
  37.         }  
  38.         OSTaskStatHook();                        /* Invoke user definable hook                         */  
  39. #if (OS_TASK_STAT_STK_CHK_EN > 0) && (OS_TASK_CREATE_EXT_EN > 0)  
  40.         OS_TaskStatStkChk();                     /* Check the stacks for each task                     */  
  41. #endif  
  42.         OSTimeDly(OS_TICKS_PER_SEC / 10);        /* Accumulate OSIdleCtr for the next 1/10 second      */  
  43.     }  
  44. }  
  45. #endif  


ucos中对CPU使用率查看

下面你就可以在自己的任务中输出相关信息了:

[cpp]  view plain copy
  1. printf("\r\n\r\n Micrium uC/OS-II  \r\n");  
  2.     printf(" ST STM32 (Cortex-M3)\r\n\r\n");  
  3.   
  4.   
  5.     printf(" uC/OS-II: V%ld.%ld%ld\r\n",OSVersion()/100,(OSVersion() % 100) /   10,(OSVersion() % 10));  
  6.     printf(" TickRate: %ld  \r\n",OS_TICKS_PER_SEC);  
  7.     printf(" CPU Usage: %ld%    \r\n",OSCPUUsage);  
  8.     printf(" CPU Speed: %ld MHz  \r\n",BSP_CPU_ClkFreq() / 1000000L);  
  9.     printf(" #Ticks: %ld  \r\n",OSTime);  
  10.     printf(" #CtxSw: %ld  \r\n",OSCtxSwCtr);  



 依次为:版本号,CPU使用率,主频,任务切换次数等!


http://blog.csdn.net/l545045612/article/details/7823046


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值