From 43c32b7af116342471a7ad704cd0994ed15a1cd5 Mon Sep 17 00:00:00 2001 From: Zhen Tang Date: Sat, 6 Jul 2013 23:53:50 +0800 Subject: [PATCH] classes added. --- WindowsMonitor/Monitor/Common.cpp | 9 ++-- WindowsMonitor/Monitor/Common.h | 12 ++++-- WindowsMonitor/Monitor/Monitor.vcxproj | 2 + .../Monitor/Monitor.vcxproj.filters | 6 +++ WindowsMonitor/Monitor/MonitorApi.h | 18 ++++++-- WindowsMonitor/Monitor/Processor.cpp | 31 ++++++++++++++ WindowsMonitor/Monitor/Processor.h | 12 ++++++ .../Monitor/ProcessorInformation.cpp | 41 ++++++++++++++++--- WindowsMonitor/Monitor/ProcessorInformation.h | 10 +++-- WindowsMonitor/Native/MonitorApi.h | 18 ++++++-- WindowsMonitor/Native/Native.cpp | 2 +- WindowsMonitor/Native/stdafx.h | 2 +- WindowsMonitor/Test/MonitorApi.h | 18 ++++++-- WindowsMonitor/Test/Test.cpp | 6 +-- WindowsMonitor/Test/stdafx.h | 2 +- 15 files changed, 154 insertions(+), 35 deletions(-) create mode 100644 WindowsMonitor/Monitor/Processor.cpp create mode 100644 WindowsMonitor/Monitor/Processor.h diff --git a/WindowsMonitor/Monitor/Common.cpp b/WindowsMonitor/Monitor/Common.cpp index eca1eec2..a2bfc70b 100644 --- a/WindowsMonitor/Monitor/Common.cpp +++ b/WindowsMonitor/Monitor/Common.cpp @@ -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 GetInstanceName(const wchar_t * objectName) +list Common::GetInstanceName(const wchar_t * objectName) { list ret; wchar_t * counterListBuffer = NULL; @@ -112,7 +113,7 @@ list GetInstanceName(const wchar_t * objectName) return ret; } -list GetCounterList(const wchar_t * objectName) +list Common::GetCounterList(const wchar_t * objectName) { list ret; wchar_t * counterListBuffer = NULL; diff --git a/WindowsMonitor/Monitor/Common.h b/WindowsMonitor/Monitor/Common.h index 89bbb8ba..7298c9c2 100644 --- a/WindowsMonitor/Monitor/Common.h +++ b/WindowsMonitor/Monitor/Common.h @@ -1,6 +1,10 @@ #pragma once -double GetCounterValue(const wchar_t * fullCounterPath); -double GetCounterValueWithSleep(const wchar_t * fullCounterPath,int sleepTime); -list GetInstanceName(const wchar_t * objectName); -list GetCounterList(const wchar_t * objectName); \ No newline at end of file +class Common +{ +public: + static double GetCounterValue(const wchar_t * fullCounterPath); + static double GetCounterValueWithSleep(const wchar_t * fullCounterPath,int idleTime); + static list GetInstanceName(const wchar_t * objectName); + static list GetCounterList(const wchar_t * objectName); +}; \ No newline at end of file diff --git a/WindowsMonitor/Monitor/Monitor.vcxproj b/WindowsMonitor/Monitor/Monitor.vcxproj index 9acb2daf..b84fc476 100644 --- a/WindowsMonitor/Monitor/Monitor.vcxproj +++ b/WindowsMonitor/Monitor/Monitor.vcxproj @@ -414,6 +414,7 @@ + @@ -457,6 +458,7 @@ + Create diff --git a/WindowsMonitor/Monitor/Monitor.vcxproj.filters b/WindowsMonitor/Monitor/Monitor.vcxproj.filters index f4f54f54..b1a0eea8 100644 --- a/WindowsMonitor/Monitor/Monitor.vcxproj.filters +++ b/WindowsMonitor/Monitor/Monitor.vcxproj.filters @@ -30,6 +30,9 @@ 头文件 + + 头文件 + @@ -44,5 +47,8 @@ 源文件 + + 源文件 + \ No newline at end of file diff --git a/WindowsMonitor/Monitor/MonitorApi.h b/WindowsMonitor/Monitor/MonitorApi.h index ab155f60..d8ceb7f6 100644 --- a/WindowsMonitor/Monitor/MonitorApi.h +++ b/WindowsMonitor/Monitor/MonitorApi.h @@ -10,7 +10,17 @@ #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 +class MONITOR_API Processor +{ +public: + static list GetInstances(); + static list GetCounterList(); +}; + +class MONITOR_API ProcessorInformation +{ +public: + static list GetInstances(); + static list GetCounterList(); + static double GetProcessorTimePercent(wchar_t * instanceName, int idleTime); +}; \ No newline at end of file diff --git a/WindowsMonitor/Monitor/Processor.cpp b/WindowsMonitor/Monitor/Processor.cpp new file mode 100644 index 00000000..52f14367 --- /dev/null +++ b/WindowsMonitor/Monitor/Processor.cpp @@ -0,0 +1,31 @@ +#include "stdafx.h" +#include "Monitor.h" +#include "Common.h" +#include "Processor.h" + +list Processor::GetInstances() +{ + return Common::GetInstanceName(L"Processor"); +} + +list 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 \ No newline at end of file diff --git a/WindowsMonitor/Monitor/Processor.h b/WindowsMonitor/Monitor/Processor.h new file mode 100644 index 00000000..77c1671c --- /dev/null +++ b/WindowsMonitor/Monitor/Processor.h @@ -0,0 +1,12 @@ +#pragma once +#include "Monitor.h" +#include +#include +using namespace std; + +class MONITOR_API Processor +{ +public: + static list GetInstances(); + static list GetCounterList(); +}; diff --git a/WindowsMonitor/Monitor/ProcessorInformation.cpp b/WindowsMonitor/Monitor/ProcessorInformation.cpp index d2a43ad2..f7bccd29 100644 --- a/WindowsMonitor/Monitor/ProcessorInformation.cpp +++ b/WindowsMonitor/Monitor/ProcessorInformation.cpp @@ -1,23 +1,52 @@ #include "stdafx.h" #include "Monitor.h" #include "Common.h" +#include "ProcessorInformation.h" -MONITOR_API list GetProcessorInformationInstances() +list ProcessorInformation::GetInstances() { - return GetInstanceName(L"Processor Information"); + return Common::GetInstanceName(L"Processor Information"); } -MONITOR_API list GetProcessorInformationCounterList() +list 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; } \ No newline at end of file diff --git a/WindowsMonitor/Monitor/ProcessorInformation.h b/WindowsMonitor/Monitor/ProcessorInformation.h index 72c7c926..36a451d4 100644 --- a/WindowsMonitor/Monitor/ProcessorInformation.h +++ b/WindowsMonitor/Monitor/ProcessorInformation.h @@ -4,6 +4,10 @@ #include 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 +class MONITOR_API ProcessorInformation +{ +public: + static list GetInstances(); + static list GetCounterList(); + static double GetProcessorTimePercent(wchar_t * instanceName, int idleTime); +}; \ No newline at end of file diff --git a/WindowsMonitor/Native/MonitorApi.h b/WindowsMonitor/Native/MonitorApi.h index ab155f60..d8ceb7f6 100644 --- a/WindowsMonitor/Native/MonitorApi.h +++ b/WindowsMonitor/Native/MonitorApi.h @@ -10,7 +10,17 @@ #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 +class MONITOR_API Processor +{ +public: + static list GetInstances(); + static list GetCounterList(); +}; + +class MONITOR_API ProcessorInformation +{ +public: + static list GetInstances(); + static list GetCounterList(); + static double GetProcessorTimePercent(wchar_t * instanceName, int idleTime); +}; \ No newline at end of file diff --git a/WindowsMonitor/Native/Native.cpp b/WindowsMonitor/Native/Native.cpp index 37c468d5..9696ed5b 100644 --- a/WindowsMonitor/Native/Native.cpp +++ b/WindowsMonitor/Native/Native.cpp @@ -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); } \ No newline at end of file diff --git a/WindowsMonitor/Native/stdafx.h b/WindowsMonitor/Native/stdafx.h index 58aea125..19eff7b3 100644 --- a/WindowsMonitor/Native/stdafx.h +++ b/WindowsMonitor/Native/stdafx.h @@ -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 diff --git a/WindowsMonitor/Test/MonitorApi.h b/WindowsMonitor/Test/MonitorApi.h index ab155f60..d8ceb7f6 100644 --- a/WindowsMonitor/Test/MonitorApi.h +++ b/WindowsMonitor/Test/MonitorApi.h @@ -10,7 +10,17 @@ #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 +class MONITOR_API Processor +{ +public: + static list GetInstances(); + static list GetCounterList(); +}; + +class MONITOR_API ProcessorInformation +{ +public: + static list GetInstances(); + static list GetCounterList(); + static double GetProcessorTimePercent(wchar_t * instanceName, int idleTime); +}; \ No newline at end of file diff --git a/WindowsMonitor/Test/Test.cpp b/WindowsMonitor/Test/Test.cpp index b63956ec..c724842d 100644 --- a/WindowsMonitor/Test/Test.cpp +++ b/WindowsMonitor/Test/Test.cpp @@ -2,8 +2,8 @@ int _tmain(int argc, _TCHAR* argv[]) { - list instances=GetProcessorInformationInstances(); - list counterList=GetProcessorInformationCounterList(); + list instances=Processor::GetInstances(); + list counterList=Processor::GetCounterList(); list::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; } diff --git a/WindowsMonitor/Test/stdafx.h b/WindowsMonitor/Test/stdafx.h index 67cc4553..aa7cd1f4 100644 --- a/WindowsMonitor/Test/stdafx.h +++ b/WindowsMonitor/Test/stdafx.h @@ -1,6 +1,6 @@ #pragma once -#pragma comment(lib,"../x64/Release/Monitor.lib") +#pragma comment(lib,"../x64/Debug/Monitor.lib") #include #include