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