PDA

View Full Version : Performance Monitor library question



jackdeth999
May 25th, 2009, 12:13 AM
I am trying to get the Performance Monitor library to return CPU usage, but I keep getting the error "CPUUSAGE PdhAddCounter failed c0000bb8" when I run the command:

obj, err = win.CreatePerformanceMonitor(1000, 33, 1, "Laptop", "_Total", 2, nil);
print (obj)
print (err)

Result of print statements:
CPUUSAGE PdhAddCounter failed c0000bb8
nil


"Laptop" is the hostname of the system I'm on. To arrive at the parameters in the win.CreatePerformanceMonitor command, I used the following code:

objects,e = win.PerformanceMonitorListObjects( "Laptop", "100" )
table.print(objects)

-Snipped result of "objects" table:
[33] = "Processor"

counters, instances = win.PerformanceMonitorListObjectItems("Laptop", "Processor", "100")
table.print(counters)
table.print(instances)

-Snipped result of "counters" table:
[1] = "% Processor Time"

-Snipped result of "instances" table:
[2] = "_Total"

Can you tell me what I'm doing wrong here? It seems this should create a counter I can poll with obj.Read() that would give me the total CPU usage.

Thanks,
Ken

Rob H
May 25th, 2009, 08:23 AM
I'm not sure what to tell you about this - I can get one stage further than you have, ie I get an object, but calling obj:Read() (note that the help is wrong here - you need to use a colon rather than a dot when calling it), returns an error.

In your case the error is


0xC0000BB8 (PDH_CSTATUS_NO_OBJECT) The specified object is not found on the system.

so it looks like one of your parameters is incorrect, but it looks okay to me.

In my case I get

0x800007D3 (PDH_CSTATUS_ITEM_NOT_VALIDATED) The data item has been added to the query but has not been validated nor accessed. No other status information on this data item is available.

We may need to wait for some advice from Ron on this one.

jackdeth999
May 25th, 2009, 05:24 PM
Rob, can you post the code you used to get the object successfully?

Also, where are you referencing the explanation text for the error codes?

thanks,
Ken

Rob H
May 25th, 2009, 06:32 PM
My code was the same as yours, except I had 77 instead of 33 since that's what win.PerformanceMonitorListObjects gave me as the index for the Processor object.

Error codes came from http://msdn.microsoft.com/en-us/library/aa373046(VS.85).aspx

jackdeth999
May 26th, 2009, 11:34 PM
I tried this on another machine, and on there I didn't even get the "Processor" instance... I just got a subset of PerfMon counters, even if I used "400" as the detail level.

Sounds like this code is still a bit buggy. Ron, any thoughts?

Rob H
May 27th, 2009, 04:56 AM
Did you call win.PerformanceMonitorListObjects to get the table of available performance objects on this other machine?

I suspect that the Girder code is a fairly thin wrapper around the underlying calls, just enough to convert the data into something suitable for Lua to access.

Rob H
June 15th, 2009, 11:07 AM
There's definitely something not right there. However, there is some good news.

The second form of win.CreatePerformanceMonitor does work okay.

The <token> there is the counter path - see http://msdn.microsoft.com/en-us/library/aa373193(VS.85).aspx for details of that.