wince 计算CPU的使用率 GetIdleTime

 OEMIdle(  DWORD dwIdleParam )

 This function is called by the kernel to place the CPU in the idle state when there are no threads ready to run.

 The number of milliseconds that the system has been idle. If GetIdleTime returns MAXDWORD, this functionality is  

 not supported by your platform.

 

 

GetIdleTime(void)

 This function returns the amount of time, in milliseconds, that the system has been idle.

 

在OEMIdle()函数中OEM根据(int) (dwRescheduleTime – CurMSec) 计算值判断是否让CPU进入idle状态,因此我们可以利用此函数来计算cpu的loading. 根据MSDN ,可以写个应用程序,每100ms去计算一次idle的时间,10次评价后,在UI上更新,以下是应用程序的一个线程!

 

 

 static void CallCountCpuIdleThread(CCountCpuDlg *pCCountCpuDlg)
{
 DWORD dwStartTick;
 DWORD dwIdleStart;
 DWORD dwStopTick;
 DWORD dwIdleEnd;
 int   nPresentIdle;
 int   nCpuUage[10]={0};
 int   nCount=0;
 int   ave=0;
 DWORD sum=0;
 int i;

 while(1)
 {
  dwStartTick=GetTickCount();
  dwIdleStart=GetIdleTime();
  Sleep(100);
  dwStopTick=GetTickCount();
  dwIdleEnd=GetIdleTime();

  nPresentIdle=(100*(dwIdleEnd-dwIdleStart))/((dwStopTick-dwStartTick));
 
  if(nCount<10)
  {
   nCpuUage[nCount]=nPresentIdle;
   nCount++;
   if(nCount==10)
   {
    for(i=0;i<10;i++)
     sum+=nCpuUage[i];
    ave=sum/10;
    // g_nCpuIdle only read in the main thread
    g_nCpuIdle=ave;
    nCount=0;
    sum=0;
    //RETAILMSG(1,(TEXT("CPU laoding is %d /r/n"),ave));
    }  
  }
 }
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值