Re: performance registry interface
From: The Other Roger (blooline_at_online.nospam)
Date: 02/23/05
- Next message: Chuck Chopp: "NetWkstaUserGetInfo() & error code 1312"
- Previous message: Al Koch: "Re: [HS] Re: How use ShellExecute with a "RAM file"?"
- In reply to: The Other Roger: "Re: performance registry interface"
- Next in thread: Rhett Gong [MSFT]: "RE: performance registry interface"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 23 Feb 2005 18:05:05 -0500
Shame on me for believing the documentation! In my Platform SDK documentation,
February 2003 release, there is a pretty clear statement that object 2 is a
"System" object, object 4 is a "Memory" object, and object 6 is a "% Processor
Time" object. I expected my program results to be consistent with the docs so I
couldn't figure out why object 6 didn't utilize enough memory to contain
instances and counters. It turns out that object 6 doesn't monitor anything and
"%Processor Time" is found elsewhere, e.g. object 230 in W2K has an "Idle"
instance which is probably the difference between 100 and total CPU time.
Roger
The Other Roger wrote:
>
> I posted this question a couple of weeks ago as an "ordinary citizen" and it did
> not elicit a response. I am reposting it using my MSDN Universal alias that is
> supposed to guarantee me an answer.
>
> One additional fact. The mail was written based on results under Windows 2000.
> I got slightly different, but no more usable results in Windows XP/SP2.
>
> Roger Levy wrote:
> >
> > I followed MSDN Platform SDK documentation to write code to retrieve %CPU
> > utilization from the registry. The registry key
> > HKLM\Software\Microsoft\Windows NT\CurrentVersion\Perflib\009 documents that
> > numeric keys are associated with performance objects as follows:
> > 2 System
> > 4 Memory
> > 6 % Processor Time
> > (and many others)
> > Other documentation explains how to use these keys to retrieve various
> > performance structures and counters. My interest was only in retrieving the
> > performance object for key 6. However I found that I could do retrievals
> > for keys 2 and 4 but I failed to retrieve all data for higher numbered keys.
> > In particular for keys greater than 4 (I tried up to key 32) I could only
> > retrieve the PERF_DATA_BLOCK but not the objects that follow it in the
> > retrieval buffer that ultimately lead to counters.
> >
> > I have a short program that partially illustrates this problem. The program
> > attempts to retrieve performance blocks associated with the keys I listed.
> > It takes a brute force approach in determining the minimum size of the
> > retrieval buffer by starting with a small buffer and incrementing its size
> > until RegQueryValExW no longer returns error 234. Here's the results:
> >
> > provided 992 bytes for key 2 type 3 used 992 bytes
> > provided 1560 bytes for key 4 type 3 used 1560 bytes
> > provided 4448 bytes for key 6 type 3 used 112 bytes
> >
> > The first line means that in trying to retrieve the performance object for
> > "System" a buffer of 992 bytes was needed (error 234 if the size was
> > smaller) and that RegQueryValExW reported that it populated 992 bytes (the
> > 2nd 992). But in trying to retrieve the performance object for "% Processor
> > Time" a buffer of 4448 bytes was needed (error 234 if size was smaller) but
> > RegQueryValExW reported that it only populated 112 bytes. 112 bytes is the
> > size of a PERF_DATA_BLOCK hence other blocks such as PERF_OBJECT_TYPE and
> > PERF_OBJECT_DEFINITION were not returned meaning the counter of interest was
> > not returned either.
> >
> > The program I used follows. I know that a lot more is needed to ultimately
> > get the data of interest but I'm stumped as to why most of the objects that
> > are claimed to be available through this interface can't be retrieved. Also
> > I know about PDH but would like to understand this problem before trying a
> > different approach.
> >
> > #include <windows.h>
> > main()
> > {
> > DWORD lpType, lpcbData;
> > LONG item, n, success;
> > wchar_t pItem[8];
> > u_char lpData[8192];
> >
> > for(item=2; item<=6; item+=2) {
> > swprintf(pItem, L"%d", item);
> > n = 100;
> > for( ;; ) {
> > lpcbData = n;
> > success = RegQueryValueExW(HKEY_PERFORMANCE_DATA,
> > pItem, NULL, &lpType, lpData, &lpcbData);
> > if(success == 234) {
> > n += 1;
> > } else if(success != ERROR_SUCCESS) {
> > printf("item %d failed with error code
> > %d\n", item, success);
> > break;
> > } else {
> > printf("provided %d bytes for key %S type %d
> > used %d bytes\n",
> > n, pItem, lpType, lpcbData);
> > break;
> > }
> > }
> > }
> > RegCloseKey(HKEY_PERFORMANCE_DATA);
> > }
- Next message: Chuck Chopp: "NetWkstaUserGetInfo() & error code 1312"
- Previous message: Al Koch: "Re: [HS] Re: How use ShellExecute with a "RAM file"?"
- In reply to: The Other Roger: "Re: performance registry interface"
- Next in thread: Rhett Gong [MSFT]: "RE: performance registry interface"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|