diff --git a/WindowsMonitor/Monitor/Common.cpp b/WindowsMonitor/Monitor/Common.cpp index 6da05507..eca1eec2 100644 --- a/WindowsMonitor/Monitor/Common.cpp +++ b/WindowsMonitor/Monitor/Common.cpp @@ -110,4 +110,40 @@ list GetInstanceName(const wchar_t * objectName) free(instanceListBuffer); } return ret; +} + +list GetCounterList(const wchar_t * objectName) +{ + list ret; + wchar_t * counterListBuffer = NULL; + wchar_t * instanceListBuffer = NULL; + DWORD dwCounterListSize = 0; + + DWORD dwInstanceListSize = 0; + BOOL pass =FALSE; + PDH_STATUS status = PdhEnumObjectItems(NULL,NULL,objectName,counterListBuffer,&dwCounterListSize,instanceListBuffer,&dwInstanceListSize,PERF_DETAIL_WIZARD, 0); + + if(status == PDH_MORE_DATA) + { + counterListBuffer=(wchar_t *)malloc((dwCounterListSize*sizeof(wchar_t))); + instanceListBuffer=(wchar_t *)malloc((dwInstanceListSize*sizeof(wchar_t))); + status= PdhEnumObjectItems(NULL,NULL,objectName,counterListBuffer,&dwCounterListSize,instanceListBuffer,&dwInstanceListSize,PERF_DETAIL_WIZARD,0); + if(status == ERROR_SUCCESS) + { + wchar_t * counterList = counterListBuffer; + for(; *counterList != 0; counterList += lstrlen(counterList) + 1) + { + ret.push_back(wstring(counterList)); + } + } + } + if(counterListBuffer != NULL) + { + free(counterListBuffer); + } + if(instanceListBuffer != NULL) + { + free(instanceListBuffer); + } + return ret; } \ No newline at end of file diff --git a/WindowsMonitor/Monitor/Common.h b/WindowsMonitor/Monitor/Common.h index a846cc4a..89bbb8ba 100644 --- a/WindowsMonitor/Monitor/Common.h +++ b/WindowsMonitor/Monitor/Common.h @@ -2,4 +2,5 @@ double GetCounterValue(const wchar_t * fullCounterPath); double GetCounterValueWithSleep(const wchar_t * fullCounterPath,int sleepTime); -list GetInstanceName(const wchar_t * objectName); \ No newline at end of file +list GetInstanceName(const wchar_t * objectName); +list GetCounterList(const wchar_t * objectName); \ No newline at end of file diff --git a/WindowsMonitor/Monitor/MonitorApi.h b/WindowsMonitor/Monitor/MonitorApi.h index cfd8ba78..ab155f60 100644 --- a/WindowsMonitor/Monitor/MonitorApi.h +++ b/WindowsMonitor/Monitor/MonitorApi.h @@ -10,5 +10,7 @@ #include using namespace std; +// Processor Information MONITOR_API list GetProcessorInformationInstances(); +MONITOR_API list GetProcessorInformationCounterList(); MONITOR_API double GetProcessorTimePercent(wchar_t * instanceName, int sleepTime); \ No newline at end of file diff --git a/WindowsMonitor/Monitor/ProcessorInformation.cpp b/WindowsMonitor/Monitor/ProcessorInformation.cpp index 98dd246b..d2a43ad2 100644 --- a/WindowsMonitor/Monitor/ProcessorInformation.cpp +++ b/WindowsMonitor/Monitor/ProcessorInformation.cpp @@ -7,6 +7,11 @@ MONITOR_API list GetProcessorInformationInstances() return GetInstanceName(L"Processor Information"); } +MONITOR_API list GetProcessorInformationCounterList() +{ + return GetCounterList(L"Processor Information"); +} + MONITOR_API double GetProcessorTimePercent(wchar_t * instanceName, int sleepTime) { wstring fullCounterPath(L""); diff --git a/WindowsMonitor/Monitor/ProcessorInformation.h b/WindowsMonitor/Monitor/ProcessorInformation.h index fa6a96e2..72c7c926 100644 --- a/WindowsMonitor/Monitor/ProcessorInformation.h +++ b/WindowsMonitor/Monitor/ProcessorInformation.h @@ -5,4 +5,5 @@ using namespace std; MONITOR_API list GetProcessorInformationInstances(); +MONITOR_API list GetProcessorInformationCounterList(); MONITOR_API double GetProcessorTimePercent(wchar_t * instanceName, int sleepTime); \ No newline at end of file diff --git a/WindowsMonitor/Native/MonitorApi.h b/WindowsMonitor/Native/MonitorApi.h index cfd8ba78..ab155f60 100644 --- a/WindowsMonitor/Native/MonitorApi.h +++ b/WindowsMonitor/Native/MonitorApi.h @@ -10,5 +10,7 @@ #include using namespace std; +// Processor Information MONITOR_API list GetProcessorInformationInstances(); +MONITOR_API list GetProcessorInformationCounterList(); MONITOR_API double GetProcessorTimePercent(wchar_t * instanceName, int sleepTime); \ No newline at end of file diff --git a/WindowsMonitor/Test/MonitorApi.h b/WindowsMonitor/Test/MonitorApi.h index cfd8ba78..ab155f60 100644 --- a/WindowsMonitor/Test/MonitorApi.h +++ b/WindowsMonitor/Test/MonitorApi.h @@ -10,5 +10,7 @@ #include using namespace std; +// Processor Information MONITOR_API list GetProcessorInformationInstances(); +MONITOR_API list GetProcessorInformationCounterList(); MONITOR_API double GetProcessorTimePercent(wchar_t * instanceName, int sleepTime); \ No newline at end of file diff --git a/WindowsMonitor/Test/Test.cpp b/WindowsMonitor/Test/Test.cpp index 93ca2acd..b63956ec 100644 --- a/WindowsMonitor/Test/Test.cpp +++ b/WindowsMonitor/Test/Test.cpp @@ -3,10 +3,15 @@ int _tmain(int argc, _TCHAR* argv[]) { list instances=GetProcessorInformationInstances(); + list counterList=GetProcessorInformationCounterList(); list::iterator iter; for(iter=instances.begin();iter!=instances.end();iter++) { - wprintf(L"%s\n",*iter); + wprintf(L"%ls\n",(*iter).c_str()); + } + for(iter=counterList.begin();iter!=counterList.end();iter++) + { + wprintf(L"%ls\n",(*iter).c_str()); } while(1)