can get counter list now.

This commit is contained in:
Zhen Tang 2013-07-06 23:25:54 +08:00
parent 0ec099bb47
commit 5ed7e5dc6a
8 changed files with 56 additions and 2 deletions

View File

@ -110,4 +110,40 @@ list<wstring> GetInstanceName(const wchar_t * objectName)
free(instanceListBuffer);
}
return ret;
}
list<wstring> GetCounterList(const wchar_t * objectName)
{
list<wstring> 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;
}

View File

@ -2,4 +2,5 @@
double GetCounterValue(const wchar_t * fullCounterPath);
double GetCounterValueWithSleep(const wchar_t * fullCounterPath,int sleepTime);
list<wstring> GetInstanceName(const wchar_t * objectName);
list<wstring> GetInstanceName(const wchar_t * objectName);
list<wstring> GetCounterList(const wchar_t * objectName);

View File

@ -10,5 +10,7 @@
#include <string>
using namespace std;
// Processor Information
MONITOR_API list<wstring> GetProcessorInformationInstances();
MONITOR_API list<wstring> GetProcessorInformationCounterList();
MONITOR_API double GetProcessorTimePercent(wchar_t * instanceName, int sleepTime);

View File

@ -7,6 +7,11 @@ MONITOR_API list<wstring> GetProcessorInformationInstances()
return GetInstanceName(L"Processor Information");
}
MONITOR_API list<wstring> GetProcessorInformationCounterList()
{
return GetCounterList(L"Processor Information");
}
MONITOR_API double GetProcessorTimePercent(wchar_t * instanceName, int sleepTime)
{
wstring fullCounterPath(L"");

View File

@ -5,4 +5,5 @@
using namespace std;
MONITOR_API list<wstring> GetProcessorInformationInstances();
MONITOR_API list<wstring> GetProcessorInformationCounterList();
MONITOR_API double GetProcessorTimePercent(wchar_t * instanceName, int sleepTime);

View File

@ -10,5 +10,7 @@
#include <string>
using namespace std;
// Processor Information
MONITOR_API list<wstring> GetProcessorInformationInstances();
MONITOR_API list<wstring> GetProcessorInformationCounterList();
MONITOR_API double GetProcessorTimePercent(wchar_t * instanceName, int sleepTime);

View File

@ -10,5 +10,7 @@
#include <string>
using namespace std;
// Processor Information
MONITOR_API list<wstring> GetProcessorInformationInstances();
MONITOR_API list<wstring> GetProcessorInformationCounterList();
MONITOR_API double GetProcessorTimePercent(wchar_t * instanceName, int sleepTime);

View File

@ -3,10 +3,15 @@
int _tmain(int argc, _TCHAR* argv[])
{
list<wstring> instances=GetProcessorInformationInstances();
list<wstring> counterList=GetProcessorInformationCounterList();
list<wstring>::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)