can get counter list now.
This commit is contained in:
parent
0ec099bb47
commit
5ed7e5dc6a
|
@ -110,4 +110,40 @@ list<wstring> GetInstanceName(const wchar_t * objectName)
|
||||||
free(instanceListBuffer);
|
free(instanceListBuffer);
|
||||||
}
|
}
|
||||||
return ret;
|
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;
|
||||||
}
|
}
|
|
@ -2,4 +2,5 @@
|
||||||
|
|
||||||
double GetCounterValue(const wchar_t * fullCounterPath);
|
double GetCounterValue(const wchar_t * fullCounterPath);
|
||||||
double GetCounterValueWithSleep(const wchar_t * fullCounterPath,int sleepTime);
|
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);
|
|
@ -10,5 +10,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
// Processor Information
|
||||||
MONITOR_API list<wstring> GetProcessorInformationInstances();
|
MONITOR_API list<wstring> GetProcessorInformationInstances();
|
||||||
|
MONITOR_API list<wstring> GetProcessorInformationCounterList();
|
||||||
MONITOR_API double GetProcessorTimePercent(wchar_t * instanceName, int sleepTime);
|
MONITOR_API double GetProcessorTimePercent(wchar_t * instanceName, int sleepTime);
|
|
@ -7,6 +7,11 @@ MONITOR_API list<wstring> GetProcessorInformationInstances()
|
||||||
return GetInstanceName(L"Processor Information");
|
return GetInstanceName(L"Processor Information");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MONITOR_API list<wstring> GetProcessorInformationCounterList()
|
||||||
|
{
|
||||||
|
return GetCounterList(L"Processor Information");
|
||||||
|
}
|
||||||
|
|
||||||
MONITOR_API double GetProcessorTimePercent(wchar_t * instanceName, int sleepTime)
|
MONITOR_API double GetProcessorTimePercent(wchar_t * instanceName, int sleepTime)
|
||||||
{
|
{
|
||||||
wstring fullCounterPath(L"");
|
wstring fullCounterPath(L"");
|
||||||
|
|
|
@ -5,4 +5,5 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
MONITOR_API list<wstring> GetProcessorInformationInstances();
|
MONITOR_API list<wstring> GetProcessorInformationInstances();
|
||||||
|
MONITOR_API list<wstring> GetProcessorInformationCounterList();
|
||||||
MONITOR_API double GetProcessorTimePercent(wchar_t * instanceName, int sleepTime);
|
MONITOR_API double GetProcessorTimePercent(wchar_t * instanceName, int sleepTime);
|
|
@ -10,5 +10,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
// Processor Information
|
||||||
MONITOR_API list<wstring> GetProcessorInformationInstances();
|
MONITOR_API list<wstring> GetProcessorInformationInstances();
|
||||||
|
MONITOR_API list<wstring> GetProcessorInformationCounterList();
|
||||||
MONITOR_API double GetProcessorTimePercent(wchar_t * instanceName, int sleepTime);
|
MONITOR_API double GetProcessorTimePercent(wchar_t * instanceName, int sleepTime);
|
|
@ -10,5 +10,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
// Processor Information
|
||||||
MONITOR_API list<wstring> GetProcessorInformationInstances();
|
MONITOR_API list<wstring> GetProcessorInformationInstances();
|
||||||
|
MONITOR_API list<wstring> GetProcessorInformationCounterList();
|
||||||
MONITOR_API double GetProcessorTimePercent(wchar_t * instanceName, int sleepTime);
|
MONITOR_API double GetProcessorTimePercent(wchar_t * instanceName, int sleepTime);
|
|
@ -3,10 +3,15 @@
|
||||||
int _tmain(int argc, _TCHAR* argv[])
|
int _tmain(int argc, _TCHAR* argv[])
|
||||||
{
|
{
|
||||||
list<wstring> instances=GetProcessorInformationInstances();
|
list<wstring> instances=GetProcessorInformationInstances();
|
||||||
|
list<wstring> counterList=GetProcessorInformationCounterList();
|
||||||
list<wstring>::iterator iter;
|
list<wstring>::iterator iter;
|
||||||
for(iter=instances.begin();iter!=instances.end();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)
|
while(1)
|
||||||
|
|
Loading…
Reference in New Issue