CPU usage calculated by wince getidletime

Source: Internet
Author: User

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.

In the oemidle () function, the OEM determines whether the CPU enters the idle state based on the value calculated by (INT) (dwrescheduletime-curmsec). Therefore, we can use this function to calculate the CPU loading. according to msdn, you can write an application to calculate the idle time every Ms. After 10 comments, update the UI. The following is a thread of the application!

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 ));
}
}
}
}

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/yjy889/archive/2009/11/29/4902234.aspx

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.