cpu performance
-
hello, i need to know how to determine the total cpu usage expressed in percent. Is there any function which can provide this value ? Please help me it's urgent. Thanks in advance!
See my response here.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
hello, i need to know how to determine the total cpu usage expressed in percent. Is there any function which can provide this value ? Please help me it's urgent. Thanks in advance!
On Win9x, i think the HKEY_DYN_DATA registry key provides some performance data, but im not sure if the CPU's included.. On NT/XP/2000, use performance counters:
HQUERY hQuery;
HCOUNTER hCounter;if(ERROR_SUCCESS == PdhOpenQuery(0, 0, &hQuery))
{
if(ERROR_SUCCESS == PdhAddCounter (hQuery,TEXT("\\Processor(0)\\% Processor Time"),0,&hCounter))
{
int i = 0;
while(i < 5)
{
++i;
if(ERROR_SUCCESS == PdhCollectQueryData(hQuery))
{
PDH_FMT_COUNTERVALUE val;
if(ERROR_SUCCESS == PdhGetFormattedCounterValue(hCounter,PDH_FMT_LONG|PDH_FMT_NOSCALE,0, &val))
{
printf("\nCPU is at %d %%",val.longValue);
}
}
Sleep(500); //wait for some time(not absolutely needed though, but better to wait some time atleast!)
}
PdhRemoveCounter(hCounter);
}
PdhCloseQuery(hQuery);
}Bikram Singh
-
hello, i need to know how to determine the total cpu usage expressed in percent. Is there any function which can provide this value ? Please help me it's urgent. Thanks in advance!
HQUERY hQuery;
HCOUNTER hCounter;if(ERROR_SUCCESS == PdhOpenQuery(0, 0, &hQuery))
{
if(ERROR_SUCCESS == PdhAddCounter (hQuery,TEXT("\\Processor(0)\\% Processor Time"),0,&hCounter))
{
int i = 0;
while(i < 5)
{
++i;
if(ERROR_SUCCESS == PdhCollectQueryData(hQuery))
{
PDH_FMT_COUNTERVALUE val;
if(ERROR_SUCCESS == PdhGetFormattedCounterValue(hCounter,PDH_FMT_LONG|PDH_FMT_NOSCALE,0, &val))
{
printf("\nCPU is at %d %%",val.longValue);
}
}
Sleep(500); //wait for some time(not absolutely needed though, but better to wait some time atleast!)
}
PdhRemoveCounter(hCounter);
}
PdhCloseQuery(hQuery);
}Bikram Singh