classes added.

This commit is contained in:
Zhen Tang 2013-07-06 23:53:50 +08:00
parent 5ed7e5dc6a
commit 43c32b7af1
15 changed files with 154 additions and 35 deletions

View File

@ -1,6 +1,7 @@
#include "stdafx.h"
#include "Common.h"
double GetCounterValue(const wchar_t * fullCounterPath)
double Common::GetCounterValue(const wchar_t * fullCounterPath)
{
HQUERY hquery;
PDH_STATUS status;
@ -34,7 +35,7 @@ double GetCounterValue(const wchar_t * fullCounterPath)
return counterValue.doubleValue;
}
double GetCounterValueWithSleep(const wchar_t * fullCounterPath,int idleTime)
double Common::GetCounterValueWithSleep(const wchar_t * fullCounterPath,int idleTime)
{
HQUERY hquery;
PDH_STATUS status;
@ -76,7 +77,7 @@ double GetCounterValueWithSleep(const wchar_t * fullCounterPath,int idleTime)
return counterValue.doubleValue;
}
list<wstring> GetInstanceName(const wchar_t * objectName)
list<wstring> Common::GetInstanceName(const wchar_t * objectName)
{
list<wstring> ret;
wchar_t * counterListBuffer = NULL;
@ -112,7 +113,7 @@ list<wstring> GetInstanceName(const wchar_t * objectName)
return ret;
}
list<wstring> GetCounterList(const wchar_t * objectName)
list<wstring> Common::GetCounterList(const wchar_t * objectName)
{
list<wstring> ret;
wchar_t * counterListBuffer = NULL;

View File

@ -1,6 +1,10 @@
#pragma once
double GetCounterValue(const wchar_t * fullCounterPath);
double GetCounterValueWithSleep(const wchar_t * fullCounterPath,int sleepTime);
list<wstring> GetInstanceName(const wchar_t * objectName);
list<wstring> GetCounterList(const wchar_t * objectName);
class Common
{
public:
static double GetCounterValue(const wchar_t * fullCounterPath);
static double GetCounterValueWithSleep(const wchar_t * fullCounterPath,int idleTime);
static list<wstring> GetInstanceName(const wchar_t * objectName);
static list<wstring> GetCounterList(const wchar_t * objectName);
};

View File

@ -414,6 +414,7 @@
<ClInclude Include="Common.h" />
<ClInclude Include="Monitor.h" />
<ClInclude Include="MonitorApi.h" />
<ClInclude Include="Processor.h" />
<ClInclude Include="ProcessorInformation.h" />
<ClInclude Include="stdafx.h" />
</ItemGroup>
@ -457,6 +458,7 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release-x86|x64'">
</PrecompiledHeader>
</ClCompile>
<ClCompile Include="Processor.cpp" />
<ClCompile Include="ProcessorInformation.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>

View File

@ -30,6 +30,9 @@
<ClInclude Include="MonitorApi.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="Processor.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
@ -44,5 +47,8 @@
<ClCompile Include="ProcessorInformation.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="Processor.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -10,7 +10,17 @@
#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);
class MONITOR_API Processor
{
public:
static list<wstring> GetInstances();
static list<wstring> GetCounterList();
};
class MONITOR_API ProcessorInformation
{
public:
static list<wstring> GetInstances();
static list<wstring> GetCounterList();
static double GetProcessorTimePercent(wchar_t * instanceName, int idleTime);
};

View File

@ -0,0 +1,31 @@
#include "stdafx.h"
#include "Monitor.h"
#include "Common.h"
#include "Processor.h"
list<wstring> Processor::GetInstances()
{
return Common::GetInstanceName(L"Processor");
}
list<wstring> Processor::GetCounterList()
{
return Common::GetCounterList(L"Processor");
}
// % Processor Time
// % User Time
// % Privileged Time
// Interrupts/sec
// % DPC Time
// % Interrupt Time
// DPCs Queued/sec
// DPC Rate
// % Idle Time
// % C1 Time
// % C2 Time
// % C3 Time
// C1 Transitions/sec
// C2 Transitions/sec
// C3 Transitions/sec

View File

@ -0,0 +1,12 @@
#pragma once
#include "Monitor.h"
#include <list>
#include <string>
using namespace std;
class MONITOR_API Processor
{
public:
static list<wstring> GetInstances();
static list<wstring> GetCounterList();
};

View File

@ -1,23 +1,52 @@
#include "stdafx.h"
#include "Monitor.h"
#include "Common.h"
#include "ProcessorInformation.h"
MONITOR_API list<wstring> GetProcessorInformationInstances()
list<wstring> ProcessorInformation::GetInstances()
{
return GetInstanceName(L"Processor Information");
return Common::GetInstanceName(L"Processor Information");
}
MONITOR_API list<wstring> GetProcessorInformationCounterList()
list<wstring> ProcessorInformation::GetCounterList()
{
return GetCounterList(L"Processor Information");
return Common::GetCounterList(L"Processor Information");
}
MONITOR_API double GetProcessorTimePercent(wchar_t * instanceName, int sleepTime)
// Performance Limit Flags
// % Performance Limit
// % Privileged Utility
// % Processor Utility
// % Processor Performance
// Idle Break Events/sec
// Average Idle Time
// Clock Interrupts/sec
// Processor State Flags
// % of Maximum Frequency
// Processor Frequency
// Parking Status
// % Priority Time
// C3 Transitions/sec
// C2 Transitions/sec
// C1 Transitions/sec
// % C3 Time
// % C2 Time
// % C1 Time
// % Idle Time
// DPC Rate
// DPCs Queued/sec
// % Interrupt Time
// % DPC Time
// Interrupts/sec
// % Privileged Time
// % User Time
double ProcessorInformation::GetProcessorTimePercent(wchar_t * instanceName, int idleTime)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Processor Information(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\% Processor Time";
double ret=GetCounterValueWithSleep(fullCounterPath.c_str(),sleepTime);
double ret=Common::GetCounterValueWithSleep(fullCounterPath.c_str(),idleTime);
return ret;
}

View File

@ -4,6 +4,10 @@
#include <string>
using namespace std;
MONITOR_API list<wstring> GetProcessorInformationInstances();
MONITOR_API list<wstring> GetProcessorInformationCounterList();
MONITOR_API double GetProcessorTimePercent(wchar_t * instanceName, int sleepTime);
class MONITOR_API ProcessorInformation
{
public:
static list<wstring> GetInstances();
static list<wstring> GetCounterList();
static double GetProcessorTimePercent(wchar_t * instanceName, int idleTime);
};

View File

@ -10,7 +10,17 @@
#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);
class MONITOR_API Processor
{
public:
static list<wstring> GetInstances();
static list<wstring> GetCounterList();
};
class MONITOR_API ProcessorInformation
{
public:
static list<wstring> GetInstances();
static list<wstring> GetCounterList();
static double GetProcessorTimePercent(wchar_t * instanceName, int idleTime);
};

View File

@ -4,5 +4,5 @@
JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_probe_windows_WindowsCpuProbe_getCpuUsage
(JNIEnv * environment, jobject object)
{
return GetProcessorTimePercent(L"_Total",1500);
return ProcessorInformation::GetProcessorTimePercent(L"_Total",1500);
}

View File

@ -1,6 +1,6 @@
#pragma once
#pragma comment(lib,"../x64/Release/Monitor.lib")
#pragma comment(lib,"../x64/Debug/Monitor.lib")
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

View File

@ -10,7 +10,17 @@
#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);
class MONITOR_API Processor
{
public:
static list<wstring> GetInstances();
static list<wstring> GetCounterList();
};
class MONITOR_API ProcessorInformation
{
public:
static list<wstring> GetInstances();
static list<wstring> GetCounterList();
static double GetProcessorTimePercent(wchar_t * instanceName, int idleTime);
};

View File

@ -2,8 +2,8 @@
int _tmain(int argc, _TCHAR* argv[])
{
list<wstring> instances=GetProcessorInformationInstances();
list<wstring> counterList=GetProcessorInformationCounterList();
list<wstring> instances=Processor::GetInstances();
list<wstring> counterList=Processor::GetCounterList();
list<wstring>::iterator iter;
for(iter=instances.begin();iter!=instances.end();iter++)
{
@ -16,7 +16,7 @@ int _tmain(int argc, _TCHAR* argv[])
while(1)
{
printf("%lf\n",GetProcessorTimePercent(L"_Total",1500));
printf("%lf\n",ProcessorInformation::GetProcessorTimePercent(L"_Total",1500));
}
return 0;
}

View File

@ -1,6 +1,6 @@
#pragma once
#pragma comment(lib,"../x64/Release/Monitor.lib")
#pragma comment(lib,"../x64/Debug/Monitor.lib")
#include <tchar.h>
#include <iostream>