[pywin32-checkins] /hgroot/pywin32/pywin32: Feature req #3529527 (AddEnglishCounter)
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2012-06-04 22:59:57
|
changeset 153ff53992c6 in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=153ff53992c6 summary: Feature req #3529527 (AddEnglishCounter) diffstat: win32/src/win32pdhmodule.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 46 insertions(+), 1 deletions(-) diffs (85 lines): diff -r 58aabb12a580 -r 153ff53992c6 win32/src/win32pdhmodule.cpp --- a/win32/src/win32pdhmodule.cpp Mon Jun 04 18:43:08 2012 -0400 +++ b/win32/src/win32pdhmodule.cpp Mon Jun 04 18:58:32 2012 -0400 @@ -157,7 +157,7 @@ LPDWORD pcchBuffer ); -#define CHECK_PDH_PTR(ptr) if((ptr)==NULL) { PyErr_SetString(PyExc_RuntimeError, "The pdh.dll entry point functions could not be loaded."); return NULL;} +#define CHECK_PDH_PTR(ptr) if((ptr)==NULL) { PyErr_Format(PyExc_RuntimeError, "The pdh.dll entry point function %s could not be loaded.", #ptr); return NULL;} // The function pointers FuncPdhEnumObjects pPdhEnumObjects = NULL; @@ -166,6 +166,7 @@ FuncPdhCloseQuery pPdhCloseQuery = NULL; FuncPdhRemoveCounter pPdhRemoveCounter = NULL; FuncPdhAddCounter pPdhAddCounter = NULL; +FuncPdhAddCounter pPdhAddEnglishCounter = NULL; FuncPdhMakeCounterPath pPdhMakeCounterPath = NULL; FuncPdhGetCounterInfo pPdhGetCounterInfo = NULL; FuncPdhGetFormattedCounterValue pPdhGetFormattedCounterValue = NULL; @@ -222,6 +223,7 @@ pPdhRemoveCounter = (FuncPdhRemoveCounter)GetProcAddress(handle, "PdhRemoveCounter"); pPdhOpenQuery = (FuncPdhOpenQuery)GetProcAddress(handle, "PdhOpenQuery" A_OR_W); pPdhAddCounter = (FuncPdhAddCounter)GetProcAddress(handle, "PdhAddCounter" A_OR_W); + pPdhAddEnglishCounter = (FuncPdhAddCounter)GetProcAddress(handle, "PdhAddEnglishCounter" A_OR_W); pPdhMakeCounterPath = (FuncPdhMakeCounterPath)GetProcAddress(handle, "PdhMakeCounterPath" A_OR_W); pPdhGetCounterInfo = (FuncPdhGetCounterInfo)GetProcAddress(handle, "PdhGetCounterInfo" A_OR_W); pPdhGetFormattedCounterValue = (FuncPdhGetFormattedCounterValue)GetProcAddress(handle, "PdhGetFormattedCounterValue"); @@ -453,6 +455,48 @@ return PyWinLong_FromHANDLE(hCounter); } +// @pymethod int|win32pdh|AddEnglishCounter|Adds a counter to a query by its English name +// @comm Available on Vista and later +// @rdesc Returns a handle to the counter +static PyObject *PyAddEnglishCounter(PyObject *self, PyObject *args) +{ + HQUERY hQuery; + PyObject *obhQuery; + PyObject *obPath; + PyObject *obuserData = Py_None; // Might make more sense to use actual PyObject for userData + DWORD_PTR userData = 0; + CHECK_PDH_PTR(pPdhAddEnglishCounter); + PDH_STATUS pdhStatus; + if (!PyArg_ParseTuple(args, "OO|O:AddEnglishCounter", + &obhQuery, // @pyparm int|hQuery||Handle to an open query. + &obPath, // @pyparm string|path||Full counter path with standard English names. + &obuserData)) // @pyparm int|userData|0|User data associated with the counter. + return NULL; + if (!PyWinObject_AsHANDLE(obhQuery, &hQuery)) + return NULL; + if (obuserData != Py_None) + if (!PyWinLong_AsDWORD_PTR(obuserData, &userData)) + return NULL; + TCHAR *szPath; + if (!PyWinObject_AsTCHAR(obPath, &szPath, FALSE)) + return NULL; + HCOUNTER hCounter; + + Py_BEGIN_ALLOW_THREADS + pdhStatus = (*pPdhAddEnglishCounter) ( + hQuery, + szPath, + userData, + &hCounter); + + Py_END_ALLOW_THREADS; + PyWinObject_FreeTCHAR(szPath); + if (pdhStatus != ERROR_SUCCESS) + return PyWin_SetAPIError("AddEnglishCounter", pdhStatus); + // @comm See also <om win32pdh.RemoveCounter> + return PyWinLong_FromHANDLE(hCounter); +} + // @pymethod |win32pdh|RemoveCounter|Removes a previously opened counter static PyObject *PyRemoveCounter(PyObject *self, PyObject *args) { @@ -1185,6 +1229,7 @@ // @module win32pdh|A module, encapsulating the Windows Performance Data Helpers API static struct PyMethodDef win32pdh_functions[] = { {"AddCounter", PyAddCounter, 1}, // @pymeth AddCounter|Adds a new counter + {"AddEnglishCounter", PyAddEnglishCounter, 1}, // @pymeth AddEnglishCounter|Adds a counter to a query by its English name {"RemoveCounter", PyRemoveCounter, 1}, // @pymeth RemoveCounter|Removes an open counter. {"EnumObjectItems", PyEnumObjectItems, 1}, // @pymeth EnumObjectItems|Enumerates an object's items {"EnumObjects", PyEnumObjects, 1}, // @pymeth EnumObjects|Enumerates objects |