[python-win32] Problem with win32pdh.GetCounterInfo
Thomas HERVE
therve at neocles.com
Wed Feb 25 06:23:31 EST 2004
I try to get some monitoring information on Windows Station. My
installation is Windows Server 2003, in french.
I use python 2.3 and win32all-163.
Here is my script :
>>> import win32pdh
>>> path = win32pdh.MakeCounterPath((None,"Processeur", "_Total", None,
-1, "% Temps processeur"))
>>> base = win32pdh.OpenQuery()
>>> counter = win32pdh.AddCounter(base, path)
>>> win32pdh.GetCounterInfo(counter, 0)
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
error: (-2147481646, 'GetCounterInfo for size', 'No error message is
available')
But if i do :
>>> win32pdh.CollectQueryData(base)
>>> win32pdh.CollectQueryData(base)
>>> win32pdh.GetFormattedCounterValue(hc,win32pdh.PDH_FMT_LONG)
(558957824, 6)
So my counter is "well formed".
Ok I reply to myself after get a further look in win32pdhmodule.cpp. I see
that function (*pPdhMakeCounterPath) (&cpe, NULL, &bufSize, flags);
don't work with an bufSize set to zero, in order to return size needed, as
it's specified in msdn documentation.
Furthermore, thinking at it made me realize that "-2147481646" corresponds to 0x800007D2, pdh error PDH_MORE_DATA : "There is more data to return than would fit in the
supplied buffer. Allocate a larger buffer and call the function again." So
the pretended behaviour of PdhGetCounterInfo seems to be wrong...
I think the work that has been done to MakeCounterPath should be done in
GetCounterInfo, ie hard-coding the size of the buffer.
I hope I'm clear enough to be understood.
--
Thomas Herve
More information about the Python-win32
mailing list