CPU Usage Calculation

Hi All,

I am developing a tool for monitoring CPU Usage ( Total Processor Usage
%, Kernel Mode Processor usage %, User Mode Processor Usage %). We can see
these parameters in windows Task
Manager, or Process Explorer (sysinternals.com). But I am not sure how there
calculations are being done in those tools.

I tried 2 methods for getting the system performance variables:

  1. Directly calling NtQuerySystemInformation NTDLL.dll, based on the
    following documentation

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/ntquerysysteminformation.asp

  1. Calling Registry fucntions using HKEY_PERFORMANCE_DATA Key.

I know that we can get these variables through PDH (Performace Data Helper)
DLL ,
But I didnt tried that.

So, the question is that, how to calculate based on the data that we get
from the system
variables from the above said methods, I am getting KernelTime, UserTime as
ULARGE_INTERGER
(__int64), how to convert them into a % Kernel Mode Processor Usage, and %
UserMode Processor usage.

I tried the following calculation to calcualte the Kernel Mode Usage:

Kernel Mode Time at Time1 (T1) - KMTime1
Kernel Mode Time at Time2 (T2) - KMTime2

Here Time T1 and T2 are in 1/100 Nano Seconds.

So the Kernel Mode Processor usage % = (((KMTime2 - KMTime1)) / (T2- T1)) *
100.00

But I am not getting the exact (atleast) approximate value, when verified
with Windows Task Manager.

Am I missing some thing ?

Regards,

Bhanu Gogineni.

Hi All,

I am developing a tool for monitoring CPU Usage ( Total Processor Usage
%, Kernel Mode Processor usage %, User Mode Processor Usage %). We can see
these parameters in windows Task
Manager, or Process Explorer (sysinternals.com). But I am not sure how there
calculations are being done in those tools.

I tried 2 methods for getting the system performance variables:

  1. Directly calling NtQuerySystemInformation NTDLL.dll, based on the
    following documentation

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/ntquerysysteminformation.asp

  1. Calling Registry fucntions using HKEY_PERFORMANCE_DATA Key.

I know that we can get these variables through PDH (Performace Data Helper)
DLL ,
But I didnt tried that.

So, the question is that, how to calculate based on the data that we get
from the system
variables from the above said methods, I am getting KernelTime, UserTime as
ULARGE_INTERGER
(__int64), how to convert them into a % Kernel Mode Processor Usage, and %
UserMode Processor usage.

I tried the following calculation to calcualte the Kernel Mode Usage:

Kernel Mode Time at Time1 (T1) - KMTime1
Kernel Mode Time at Time2 (T2) - KMTime2

Here Time T1 and T2 are in 1/100 Nano Seconds.

So the Kernel Mode Processor usage % = (((KMTime2 - KMTime1)) / (T2- T1)) *
100.00

But I am not getting the exact (atleast approximate) value, when verified
with Windows Task Manager.

Am I missing some thing ?

Regards,

Bhanu Gogineni.

> I tried 2 methods for getting the system performance variables:

  1. Directly calling NtQuerySystemInformation NTDLL.dll, based on the
    following documentation

http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/sysinfo/base/ntquerysysteminformation.asp

  1. Calling Registry fucntions using HKEY_PERFORMANCE_DATA Key.

This will invoke Method 1 in turn via some add-on DLL which implements
HKEY_PERFORMANCE_DATA.

WMI can also help.

variables from the above said methods, I am getting KernelTime, UserTime as
ULARGE_INTERGER
(__int64), how to convert them into a % Kernel Mode Processor Usage, and %
UserMode Processor usage.

Each TIME seconds do the following:

QueryUserTime(UserTime);
QueryKernelTime(KernelTime);
UserPercent = ( UserTime - MyVarOldUserTime ) / ( TIME * 1000000 );
KernelPercent = ( KernelTime - MyVarOldKernelTime ) / ( TIME * 1000000 );
MyVarOldUserTime = UserTime;
MyVarOldKernelTime = KernelTime;

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

Maxim,

Thanks for responding. I did the same steps to calculate the CPU
usage,

KernelPercent = ( KernelTime - MyVarOldKernelTime ) / ( TIME * 1000000
);

but TIME(In Seconds) * 1000000 ?. I am getting large numbers when I tried
this.
I believe it is supposed to be Time(In Seconds) * 100000000000.

I have one more problem with the “HKEY_PERFORMANCE_DATA” registry approach,
I am getting Kernel32.DLL Exceptions. I pasted the debug messages that I
got, which I tried to
debug my program using Visual Sudio 6.0. I have to resolve these kernel32
exceptions, But I have
no Idea why I am getting them. I am getting the exceptions when executing
this code.

while((dwRetValue = RegQueryValueEx( HKEY_PERFORMANCE_DATA,
“Global”,
NULL,
NULL,
(LPBYTE) pPerfData,
&dwBufferSize )) == ERROR_MORE_DATA )
{
// Get a buffer that is big enough.
dwErrorCode = GetLastError();
LocalFree (pPerfData);
dwBufferSize += BYTEINCREMENT;
pPerfData = (PPERF_DATA_BLOCK) LocalAlloc (LMEM_FIXED,
dwBufferSize);
}

At some point I am getting the error codes 2 and 997, at that time I am
getting the Kernel32 Exceptions. According to the MSDN help, error code 2
and 997 corresponds to the following
information:

2 - The system cannot find the file specified. ERROR_FILE_NOT_FOUND
997 - Overlapped I/O operation is in progress. ERROR_IO_PENDING

Debug Messages:

Loaded ‘C:\WINNT\system32\netfxperf.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\mscoree.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\Microsoft.NET\Framework\v1.0.3705\PerfCounter.dll’, no
matching symbolic information found.
Loaded ‘C:\WINNT\Microsoft.NET\Framework\v1.0.3705\mscorwks.dll’, no
matching symbolic information found.
Loaded ‘C:\WINNT\Microsoft.NET\Framework\v1.0.3705\msvcr70.dll’, no matching
symbolic information found.
Loaded ‘C:\WINNT\Microsoft.NET\Framework\v1.0.3705\fusion.dll’, no matching
symbolic information found.
Loaded ‘C:\WINNT\Microsoft.NET\Framework\v1.0.3705\mscorlib.dll’, no
matching symbolic information found.
Loaded
‘C:\WINNT\assembly\NativeImages1_v1.0.3705\mscorlib\1.0.3300.0__b77a5c561934e089_7ee40345\mscorlib.dll’,
no matching symbolic information found.
Loaded
‘C:\WINNT\assembly\GAC\System\1.0.3300.0__b77a5c561934e089\System.dll’, no
matching symbolic information found.
Loaded
‘C:\WINNT\assembly\NativeImages1_v1.0.3705\System\1.0.3300.0__b77a5c561934e089_e0d6f832\System.dll’,
no matching symbolic information found.
Loaded
‘C:\WINNT\assembly\GAC\System.Xml\1.0.3300.0__b77a5c561934e089\System.XML.dll’,
no matching symbolic information found.
Loaded
‘C:\WINNT\assembly\NativeImages1_v1.0.3705\System.Xml\1.0.3300.0__b77a5c561934e089_6e762083\System.Xml.dll’,
no matching symbolic information found.
Loaded ‘C:\WINNT\Microsoft.NET\Framework\v1.0.3705\CORPerfMonExt.dll’, no
matching symbolic information found.
Loaded ‘C:\WINNT\system32\psapi.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\CCM\FrameworkPerf.dll’, no matching symbolic
information found.
Loaded ‘C:\WINNT\system32\CCM\ccmperf.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\msvcp60.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\ccmcore.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\wtsapi32.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\utildll.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\TAPI32.DLL’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\SETUPAPI.DLL’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\USERENV.DLL’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\NETAPI32.DLL’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\secur32.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\ntdsapi.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\dnsapi.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\WLDAP32.DLL’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\netrap.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\samlib.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\winsta.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\regapi.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\mprapi.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\activeds.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\adsldpc.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\rtutils.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\query.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\faxperf.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\iasperf.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\msvcp50.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\SNMPAPI.DLL’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\LOADPERF.DLL’, no matching symbolic information
found.
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0xE06D7363: Microsoft
C++ Exception.
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0xE06D7363: Microsoft
C++ Exception.
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0xE06D7363: Microsoft
C++ Exception.
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0xE06D7363: Microsoft
C++ Exception.
Loaded ‘C:\WINNT\system32\perfdisk.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\perfnet.dll’, no matching symbolic information
found.
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
Loaded ‘C:\WINNT\system32\perfos.dll’, no matching symbolic information
found.
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
Loaded ‘C:\WINNT\system32\perfproc.dll’, no matching symbolic information
found.
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
First-chance exception in WinDAS.exe (KERNEL32.DLL): 0x000006B5: (no name).
Loaded ‘C:\WINNT\system32\rasctrs.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\RASMAN.DLL’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\rsvpperf.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\tapiperf.dll’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\PERFCTRS.DLL’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\IPHLPAPI.DLL’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\icmp.dll’, no matching symbolic information found.
Loaded ‘C:\WINNT\system32\RASAPI32.DLL’, no matching symbolic information
found.
Loaded ‘C:\WINNT\system32\DHCPCSVC.DLL’, no matching symbolic information
found.

Regards,

Bhanu Gogineni.

From: “Maxim S. Shatskih”
>Reply-To: “Windows System Software Devs Interest List”
>
>To: “Windows System Software Devs Interest List”
>Subject: Re: [ntdev] CPU Usage Calculation
>Date: Wed, 15 Dec 2004 20:12:15 +0300
>
> > I tried 2 methods for getting the system performance variables:
> >
> > 1. Directly calling NtQuerySystemInformation NTDLL.dll, based on the
> > following documentation
> >
> > http://msdn.microsoft.com/library/default.asp?url=/library/en-
>us/sysinfo/base/ntquerysysteminformation.asp
> >
> > 2. Calling Registry fucntions using HKEY_PERFORMANCE_DATA Key.
>
>This will invoke Method 1 in turn via some add-on DLL which implements
>HKEY_PERFORMANCE_DATA.
>
>WMI can also help.
>
> > variables from the above said methods, I am getting KernelTime, UserTime
>as
> > ULARGE_INTERGER
> > (__int64), how to convert them into a % Kernel Mode Processor Usage, and
>%
> > UserMode Processor usage.
>
>Each TIME seconds do the following:
>
> QueryUserTime(UserTime);
> QueryKernelTime(KernelTime);
> UserPercent = ( UserTime - MyVarOldUserTime ) / ( TIME * 1000000 );
> KernelPercent = ( KernelTime - MyVarOldKernelTime ) / ( TIME * 1000000
>);
> MyVarOldUserTime = UserTime;
> MyVarOldKernelTime = KernelTime;
>
>Maxim Shatskih, Windows DDK MVP
>StorageCraft Corporation
>xxxxx@storagecraft.com
>http://www.storagecraft.com
>
>
>—
>Questions? First check the Kernel Driver FAQ at
>http://www.osronline.com/article.cfm?id=256
>
>You are currently subscribed to ntdev as: xxxxx@hotmail.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com

> but TIME(In Seconds) * 1000000 ?. I am getting large numbers when I tried

this.
I believe it is supposed to be Time(In Seconds) * 100000000000.

Unit is 100ns - so, 10,000,000 units per second. To have percents and not just
the proportion, the number below the “/” operator must be 100 times smaller -
so, 100,000.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

Bhanu, you’ve gotten help with the calculations. I can help with the “how
these calculations are being done in those tools” part of your question.

These performance counters were originally developed for Perfmon (now called
“Performance.”) In Perfmon, click the + button, click any counter in the
list, and then click the Explain button. There are detailed descriptions of
the counters, including information about data collection.

Hope this helps,
June

June Blender (MSFT)
DDK Tool Docs
xxxxx@microsoft.com

“Bhanu Gogineni” wrote in message
news:xxxxx@ntdev…
> Hi All,
>
> I am developing a tool for monitoring CPU Usage ( Total Processor Usage
> %, Kernel Mode Processor usage %, User Mode Processor Usage %). We can see
> these parameters in windows Task
> Manager, or Process Explorer (sysinternals.com). But I am not sure how
> there calculations are being done in those tools.
>
> I tried 2 methods for getting the system performance variables:
>
> 1. Directly calling NtQuerySystemInformation NTDLL.dll, based on the
> following documentation
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/ntquerysysteminformation.asp
>
> 2. Calling Registry fucntions using HKEY_PERFORMANCE_DATA Key.
>
> I know that we can get these variables through PDH (Performace Data
> Helper) DLL ,
> But I didnt tried that.
>
> So, the question is that, how to calculate based on the data that we get
> from the system
> variables from the above said methods, I am getting KernelTime, UserTime
> as ULARGE_INTERGER
> (__int64), how to convert them into a % Kernel Mode Processor Usage, and %
> UserMode Processor usage.
>
> I tried the following calculation to calcualte the Kernel Mode Usage:
>
> Kernel Mode Time at Time1 (T1) - KMTime1
> Kernel Mode Time at Time2 (T2) - KMTime2
>
> Here Time T1 and T2 are in 1/100 Nano Seconds.
>
> So the Kernel Mode Processor usage % = (((KMTime2 - KMTime1)) / (T2- T1))
> * 100.00
>
> But I am not getting the exact (atleast approximate) value, when verified
> with Windows Task Manager.
>
> Am I missing some thing ?
>
> Regards,
>
> Bhanu Gogineni.
>
>
>

Hi June,

Thanks for your valuable reply. I understood how these calculations
are being done
in the windows Task Manager, by reading the (Open Source) source code of
“task manger” in
ReactOS. For some reason the calculation based on time parameter is not
correct, ProcessorTime1
(counter1) at T1 and ProcessorTime2(counter2) at T2.

according to Maxim

fIdleThreadProcessorUsage = (float)((ProcessorTime2 - ProcessorTime1) /
((T2-T1) * 100000));

I believe the above statement is wrong, if T1 and T2 are in seconds then
multiplying my 100000
making the fIdleThreadProcessorUsage a large number

fProcessorUsage = (float)(100% - fIdleThreadProcessorUsage);

so making this statement a large negative number.

And one more question not resolved yet is, I am getting excpetions in
Kernel32.dll when I tried
to access the Performance Variables through the registry
(HKEY_PERFORMANCE_DATA ). Is it
because in some machines, those perfomance DLLs might be missing ?, In some
machines I could be able to read some performance variables and failed to
read some other variables.

To make more sense let me explain what I am developing, I am trying to
develop a tool that Monitor the performance variables of the resources,
Memory(Kernel Mode, UserMode, Paged, Nonpaged), Disk usage( Used space,
Available Space), Network (TCP Packets sent and Received, and for UDP), CPU
(Kernel Mode CPU Usage, User Mode CPU Usage), …etc.

Thank You June, for showing your interest in helping me.

Regards,

Bhanu Gogineni.

From: “June Blender (MSFT)”
>Reply-To: “Windows System Software Devs Interest List”
>
>To: “Windows System Software Devs Interest List”
>Subject: Re:[ntdev] CPU Usage Calculation
>Date: Fri, 17 Dec 2004 08:35:09 -0800
>
>Bhanu, you’ve gotten help with the calculations. I can help with the “how
>these calculations are being done in those tools” part of your question.
>
>These performance counters were originally developed for Perfmon (now
>called
>“Performance.”) In Perfmon, click the + button, click any counter in the
>list, and then click the Explain button. There are detailed descriptions of
>the counters, including information about data collection.
>
>Hope this helps,
>June
>
>June Blender (MSFT)
>DDK Tool Docs
>xxxxx@microsoft.com
>
>“Bhanu Gogineni” wrote in message
>news:xxxxx@ntdev…
> > Hi All,
> >
> > I am developing a tool for monitoring CPU Usage ( Total Processor
>Usage
> > %, Kernel Mode Processor usage %, User Mode Processor Usage %). We can
>see
> > these parameters in windows Task
> > Manager, or Process Explorer (sysinternals.com). But I am not sure how
> > there calculations are being done in those tools.
> >
> > I tried 2 methods for getting the system performance variables:
> >
> > 1. Directly calling NtQuerySystemInformation NTDLL.dll, based on the
> > following documentation
> >
> >
>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/ntquerysysteminformation.asp
> >
> > 2. Calling Registry fucntions using HKEY_PERFORMANCE_DATA Key.
> >
> > I know that we can get these variables through PDH (Performace Data
> > Helper) DLL ,
> > But I didnt tried that.
> >
> > So, the question is that, how to calculate based on the data that we get
> > from the system
> > variables from the above said methods, I am getting KernelTime, UserTime
> > as ULARGE_INTERGER
> > (__int64), how to convert them into a % Kernel Mode Processor Usage, and
>%
> > UserMode Processor usage.
> >
> > I tried the following calculation to calcualte the Kernel Mode Usage:
> >
> > Kernel Mode Time at Time1 (T1) - KMTime1
> > Kernel Mode Time at Time2 (T2) - KMTime2
> >
> > Here Time T1 and T2 are in 1/100 Nano Seconds.
> >
> > So the Kernel Mode Processor usage % = (((KMTime2 - KMTime1)) / (T2-
>T1))
> > * 100.00
> >
> > But I am not getting the exact (atleast approximate) value, when
>verified
> > with Windows Task Manager.
> >
> > Am I missing some thing ?
> >
> > Regards,
> >
> > Bhanu Gogineni.
> >
> >
> >
>
>
>
>—
>Questions? First check the Kernel Driver FAQ at
>http://www.osronline.com/article.cfm?id=256
>
>You are currently subscribed to ntdev as: xxxxx@hotmail.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com

Thanks, Bhanu. I’ve referred your questions to the writers and devs who now
handle these issues. I’ll get back to you (offline) when I hear from them.

Again, please use the feedback links and encourage others to use them.


June Blender (MSFT)
DDK Tool Docs
xxxxx@microsoft.com

“Bhanu Gogineni” wrote in message
news:xxxxx@ntdev…
> Hi June,
>
> Thanks for your valuable reply. I understood how these calculations
> are being done
> in the windows Task Manager, by reading the (Open Source) source code of
> “task manger” in
> ReactOS. For some reason the calculation based on time parameter is not
> correct, ProcessorTime1
> (counter1) at T1 and ProcessorTime2(counter2) at T2.
>
> according to Maxim
>
> fIdleThreadProcessorUsage = (float)((ProcessorTime2 - ProcessorTime1) /
> ((T2-T1) * 100000));
>
> I believe the above statement is wrong, if T1 and T2 are in seconds
> then multiplying my 100000
> making the fIdleThreadProcessorUsage a large number
>
> fProcessorUsage = (float)(100% - fIdleThreadProcessorUsage);
>
> so making this statement a large negative number.
>
> And one more question not resolved yet is, I am getting excpetions in
> Kernel32.dll when I tried
> to access the Performance Variables through the registry
> (HKEY_PERFORMANCE_DATA ). Is it
> because in some machines, those perfomance DLLs might be missing ?, In
> some machines I could be able to read some performance variables and
> failed to read some other variables.
>
> To make more sense let me explain what I am developing, I am trying
> to develop a tool that Monitor the performance variables of the resources,
> Memory(Kernel Mode, UserMode, Paged, Nonpaged), Disk usage( Used space,
> Available Space), Network (TCP Packets sent and Received, and for UDP),
> CPU (Kernel Mode CPU Usage, User Mode CPU Usage), …etc.
>
> Thank You June, for showing your interest in helping me.
>
> Regards,
>
> Bhanu Gogineni.
>
>
>>From: “June Blender (MSFT)”
>>Reply-To: “Windows System Software Devs Interest List”
>>
>>To: “Windows System Software Devs Interest List”
>>Subject: Re:[ntdev] CPU Usage Calculation
>>Date: Fri, 17 Dec 2004 08:35:09 -0800
>>
>>Bhanu, you’ve gotten help with the calculations. I can help with the “how
>>these calculations are being done in those tools” part of your question.
>>
>>These performance counters were originally developed for Perfmon (now
>>called
>>“Performance.”) In Perfmon, click the + button, click any counter in the
>>list, and then click the Explain button. There are detailed descriptions
>>of
>>the counters, including information about data collection.
>>
>>Hope this helps,
>>June
>>
>>June Blender (MSFT)
>>DDK Tool Docs
>>xxxxx@microsoft.com
>>
>>“Bhanu Gogineni” wrote in message
>>news:xxxxx@ntdev…
>> > Hi All,
>> >
>> > I am developing a tool for monitoring CPU Usage ( Total Processor
>>Usage
>> > %, Kernel Mode Processor usage %, User Mode Processor Usage %). We can
>>see
>> > these parameters in windows Task
>> > Manager, or Process Explorer (sysinternals.com). But I am not sure how
>> > there calculations are being done in those tools.
>> >
>> > I tried 2 methods for getting the system performance variables:
>> >
>> > 1. Directly calling NtQuerySystemInformation NTDLL.dll, based on the
>> > following documentation
>> >
>> >
>>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/ntquerysysteminformation.asp
>> >
>> > 2. Calling Registry fucntions using HKEY_PERFORMANCE_DATA Key.
>> >
>> > I know that we can get these variables through PDH (Performace Data
>> > Helper) DLL ,
>> > But I didnt tried that.
>> >
>> > So, the question is that, how to calculate based on the data that we
>> > get
>> > from the system
>> > variables from the above said methods, I am getting KernelTime,
>> > UserTime
>> > as ULARGE_INTERGER
>> > (__int64), how to convert them into a % Kernel Mode Processor Usage,
>> > and
>>%
>> > UserMode Processor usage.
>> >
>> > I tried the following calculation to calcualte the Kernel Mode Usage:
>> >
>> > Kernel Mode Time at Time1 (T1) - KMTime1
>> > Kernel Mode Time at Time2 (T2) - KMTime2
>> >
>> > Here Time T1 and T2 are in 1/100 Nano Seconds.
>> >
>> > So the Kernel Mode Processor usage % = (((KMTime2 - KMTime1)) / (T2-
>>T1))
>> > * 100.00
>> >
>> > But I am not getting the exact (atleast approximate) value, when
>>verified
>> > with Windows Task Manager.
>> >
>> > Am I missing some thing ?
>> >
>> > Regards,
>> >
>> > Bhanu Gogineni.
>> >
>> >
>> >
>>
>>
>>
>>—
>>Questions? First check the Kernel Driver FAQ at
>>http://www.osronline.com/article.cfm?id=256
>>
>>You are currently subscribed to ntdev as: xxxxx@hotmail.com
>>To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>

Bhanu, to resolve the exceptions, you should be using the PDH.interface. For
info, see the following SDK topic:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/perfmon/base/using_the_pdh_interface.asp

Hope this helps.


June Blender (MSFT)
DDK Tool Docs
xxxxx@microsoft.com

“Bhanu Gogineni” wrote in message
news:xxxxx@ntdev…
> Hi June,
>
> Thanks for your valuable reply. I understood how these calculations
> are being done
> in the windows Task Manager, by reading the (Open Source) source code of
> “task manger” in
> ReactOS. For some reason the calculation based on time parameter is not
> correct, ProcessorTime1
> (counter1) at T1 and ProcessorTime2(counter2) at T2.
>
> according to Maxim
>
> fIdleThreadProcessorUsage = (float)((ProcessorTime2 - ProcessorTime1) /
> ((T2-T1) * 100000));
>
> I believe the above statement is wrong, if T1 and T2 are in seconds
> then multiplying my 100000
> making the fIdleThreadProcessorUsage a large number
>
> fProcessorUsage = (float)(100% - fIdleThreadProcessorUsage);
>
> so making this statement a large negative number.
>
> And one more question not resolved yet is, I am getting excpetions in
> Kernel32.dll when I tried
> to access the Performance Variables through the registry
> (HKEY_PERFORMANCE_DATA ). Is it
> because in some machines, those perfomance DLLs might be missing ?, In
> some machines I could be able to read some performance variables and
> failed to read some other variables.
>
> To make more sense let me explain what I am developing, I am trying
> to develop a tool that Monitor the performance variables of the resources,
> Memory(Kernel Mode, UserMode, Paged, Nonpaged), Disk usage( Used space,
> Available Space), Network (TCP Packets sent and Received, and for UDP),
> CPU (Kernel Mode CPU Usage, User Mode CPU Usage), …etc.
>
> Thank You June, for showing your interest in helping me.
>
> Regards,
>
> Bhanu Gogineni.
>
>
>>From: “June Blender (MSFT)”
>>Reply-To: “Windows System Software Devs Interest List”
>>
>>To: “Windows System Software Devs Interest List”
>>Subject: Re:[ntdev] CPU Usage Calculation
>>Date: Fri, 17 Dec 2004 08:35:09 -0800
>>
>>Bhanu, you’ve gotten help with the calculations. I can help with the “how
>>these calculations are being done in those tools” part of your question.
>>
>>These performance counters were originally developed for Perfmon (now
>>called
>>“Performance.”) In Perfmon, click the + button, click any counter in the
>>list, and then click the Explain button. There are detailed descriptions
>>of
>>the counters, including information about data collection.
>>
>>Hope this helps,
>>June
>>
>>June Blender (MSFT)
>>DDK Tool Docs
>>xxxxx@microsoft.com
>>
>>“Bhanu Gogineni” wrote in message
>>news:xxxxx@ntdev…
>> > Hi All,
>> >
>> > I am developing a tool for monitoring CPU Usage ( Total Processor
>>Usage
>> > %, Kernel Mode Processor usage %, User Mode Processor Usage %). We can
>>see
>> > these parameters in windows Task
>> > Manager, or Process Explorer (sysinternals.com). But I am not sure how
>> > there calculations are being done in those tools.
>> >
>> > I tried 2 methods for getting the system performance variables:
>> >
>> > 1. Directly calling NtQuerySystemInformation NTDLL.dll, based on the
>> > following documentation
>> >
>> >
>>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/ntquerysysteminformation.asp
>> >
>> > 2. Calling Registry fucntions using HKEY_PERFORMANCE_DATA Key.
>> >
>> > I know that we can get these variables through PDH (Performace Data
>> > Helper) DLL ,
>> > But I didnt tried that.
>> >
>> > So, the question is that, how to calculate based on the data that we
>> > get
>> > from the system
>> > variables from the above said methods, I am getting KernelTime,
>> > UserTime
>> > as ULARGE_INTERGER
>> > (__int64), how to convert them into a % Kernel Mode Processor Usage,
>> > and
>>%
>> > UserMode Processor usage.
>> >
>> > I tried the following calculation to calcualte the Kernel Mode Usage:
>> >
>> > Kernel Mode Time at Time1 (T1) - KMTime1
>> > Kernel Mode Time at Time2 (T2) - KMTime2
>> >
>> > Here Time T1 and T2 are in 1/100 Nano Seconds.
>> >
>> > So the Kernel Mode Processor usage % = (((KMTime2 - KMTime1)) / (T2-
>>T1))
>> > * 100.00
>> >
>> > But I am not getting the exact (atleast approximate) value, when
>>verified
>> > with Windows Task Manager.
>> >
>> > Am I missing some thing ?
>> >
>> > Regards,
>> >
>> > Bhanu Gogineni.
>> >
>> >
>> >
>>
>>
>>
>>—
>>Questions? First check the Kernel Driver FAQ at
>>http://www.osronline.com/article.cfm?id=256
>>
>>You are currently subscribed to ntdev as: xxxxx@hotmail.com
>>To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>