From 89347b8d9d785421bdf02db86974104403f7ec19 Mon Sep 17 00:00:00 2001 From: Zhen Tang Date: Sun, 7 Jul 2013 13:54:52 +0800 Subject: [PATCH] processor information monitor completed. --- WindowsMonitor/Monitor/Common.cpp | 4 +- WindowsMonitor/Monitor/MonitorApi.h | 27 ++++ .../Monitor/ProcessorInformation.cpp | 130 ++++++++++++++++-- WindowsMonitor/Monitor/ProcessorInformation.h | 13 ++ WindowsMonitor/Native/MonitorApi.h | 27 ++++ WindowsMonitor/Test/MonitorApi.h | 27 ++++ WindowsMonitor/Test/Test.cpp | 17 +-- 7 files changed, 215 insertions(+), 30 deletions(-) diff --git a/WindowsMonitor/Monitor/Common.cpp b/WindowsMonitor/Monitor/Common.cpp index 1c007a21..baa93c63 100644 --- a/WindowsMonitor/Monitor/Common.cpp +++ b/WindowsMonitor/Monitor/Common.cpp @@ -22,7 +22,7 @@ double Common::GetCounterValue(const wchar_t * fullCounterPath) return -1; } PDH_FMT_COUNTERVALUE counterValue; - status=PdhGetFormattedCounterValue(counter,PDH_FMT_DOUBLE,NULL,&counterValue); + status=PdhGetFormattedCounterValue(counter,PDH_FMT_DOUBLE|PDH_FMT_NOSCALE|PDH_FMT_NOCAP100,NULL,&counterValue); if(status!=ERROR_SUCCESS) { return -1; @@ -64,7 +64,7 @@ double Common::GetCounterValueWithIdle(const wchar_t * fullCounterPath,int idleT return -1; } PDH_FMT_COUNTERVALUE counterValue; - status=PdhGetFormattedCounterValue(counter,PDH_FMT_DOUBLE,NULL,&counterValue); + status=PdhGetFormattedCounterValue(counter,PDH_FMT_DOUBLE|PDH_FMT_NOSCALE|PDH_FMT_NOCAP100,NULL,&counterValue); if(status!=ERROR_SUCCESS) { return -1; diff --git a/WindowsMonitor/Monitor/MonitorApi.h b/WindowsMonitor/Monitor/MonitorApi.h index b09c906f..40ae84da 100644 --- a/WindowsMonitor/Monitor/MonitorApi.h +++ b/WindowsMonitor/Monitor/MonitorApi.h @@ -37,6 +37,33 @@ class MONITOR_API ProcessorInformation public: static list GetInstances(); static list GetCounterList(); + static double GetPerformanceLimitFlags(wchar_t * instanceName); + static double GetPerformanceLimitPercent(wchar_t * instanceName); + static double GetPrivilegedUtilityPercent(wchar_t * instanceName, int idleTime); + static double GetProcessorUtilityPercent(wchar_t * instanceName, int idleTime); + static double GetProcessorPerformancePercent(wchar_t * instanceName, int idleTime); + static double GetIdleBreakEventsPerSecond(wchar_t * instanceName, int idleTime); + static double GetAverageIdleTime(wchar_t * instanceName, int idleTime); + static double GetClockInterruptsPerSecond(wchar_t * instanceName, int idleTime); + static double GetProcessorStateFlags(wchar_t * instanceName); + static double GetPercentageOfMaximumFrequency(wchar_t * instanceName); + static double GetProcessorFrequency(wchar_t * instanceName); + static double GetParkingStatus(wchar_t * instanceName); + static double GetPriorityTimePercent(wchar_t * instanceName, int idleTime); + static double GetC3TransitionsPerSecond(wchar_t * instanceName, int idleTime); + static double GetC2TransitionsPerSecond(wchar_t * instanceName, int idleTime); + static double GetC1TransitionsPerSecond(wchar_t * instanceName, int idleTime); + static double GetC3TimePercent(wchar_t * instanceName, int idleTime); + static double GetC2TimePercent(wchar_t * instanceName, int idleTime); + static double GetC1TimePercent(wchar_t * instanceName, int idleTime); + static double GetIdleTimePercent(wchar_t * instanceName, int idleTime); + static double GetDpcRate(wchar_t * instanceName); + static double GetDpcsQueuedPerSecond(wchar_t * instanceName, int idleTime); + static double GetInterruptTimePercent(wchar_t * instanceName, int idleTime); + static double GetDpcTimePercent(wchar_t * instanceName, int idleTime); + static double GetInterruptsPerSecond(wchar_t * instanceName, int idleTime); + static double GetPrivilegedTimePercent(wchar_t * instanceName, int idleTime); + static double GetUserTimePercent(wchar_t * instanceName, int idleTime); static double GetProcessorTimePercent(wchar_t * instanceName, int idleTime); }; diff --git a/WindowsMonitor/Monitor/ProcessorInformation.cpp b/WindowsMonitor/Monitor/ProcessorInformation.cpp index e8b975b1..1cea6031 100644 --- a/WindowsMonitor/Monitor/ProcessorInformation.cpp +++ b/WindowsMonitor/Monitor/ProcessorInformation.cpp @@ -14,43 +14,147 @@ list ProcessorInformation::GetCounterList() } // Performance Limit Flags - +double ProcessorInformation::GetPerformanceLimitFlags(wchar_t * instanceName) +{ + wstring fullCounterPath(L""); + fullCounterPath+=L"\\Processor Information("; + fullCounterPath+=instanceName; + fullCounterPath+=L")\\Performance Limit Flags"; + double ret=Common::GetCounterValue(fullCounterPath.c_str()); + return ret; +} // % Performance Limit - +double ProcessorInformation::GetPerformanceLimitPercent(wchar_t * instanceName) +{ + wstring fullCounterPath(L""); + fullCounterPath+=L"\\Processor Information("; + fullCounterPath+=instanceName; + fullCounterPath+=L")\\% Performance Limit"; + double ret=Common::GetCounterValue(fullCounterPath.c_str()); + return ret; +} // % Privileged Utility - +double ProcessorInformation::GetPrivilegedUtilityPercent(wchar_t * instanceName, int idleTime) +{ + wstring fullCounterPath(L""); + fullCounterPath+=L"\\Processor Information("; + fullCounterPath+=instanceName; + fullCounterPath+=L")\\% Privileged Utility"; + double ret=Common::GetCounterValueWithIdle(fullCounterPath.c_str(),idleTime); + return ret; +} // % Processor Utility - +double ProcessorInformation::GetProcessorUtilityPercent(wchar_t * instanceName, int idleTime) +{ + wstring fullCounterPath(L""); + fullCounterPath+=L"\\Processor Information("; + fullCounterPath+=instanceName; + fullCounterPath+=L")\\% Processor Utility"; + double ret=Common::GetCounterValueWithIdle(fullCounterPath.c_str(),idleTime); + return ret; +} // % Processor Performance - +double ProcessorInformation::GetProcessorPerformancePercent(wchar_t * instanceName, int idleTime) +{ + wstring fullCounterPath(L""); + fullCounterPath+=L"\\Processor Information("; + fullCounterPath+=instanceName; + fullCounterPath+=L")\\% Processor Performance"; + double ret=Common::GetCounterValueWithIdle(fullCounterPath.c_str(),idleTime); + return ret; +} // Idle Break Events/sec - +double ProcessorInformation::GetIdleBreakEventsPerSecond(wchar_t * instanceName, int idleTime) +{ + wstring fullCounterPath(L""); + fullCounterPath+=L"\\Processor Information("; + fullCounterPath+=instanceName; + fullCounterPath+=L")\\Idle Break Events/sec"; + double ret=Common::GetCounterValueWithIdle(fullCounterPath.c_str(),idleTime); + return ret; +} // Average Idle Time - +double ProcessorInformation::GetAverageIdleTime(wchar_t * instanceName, int idleTime) +{ + wstring fullCounterPath(L""); + fullCounterPath+=L"\\Processor Information("; + fullCounterPath+=instanceName; + fullCounterPath+=L")\\Average Idle Time"; + double ret=Common::GetCounterValueWithIdle(fullCounterPath.c_str(),idleTime); + return ret; +} // Clock Interrupts/sec - +double ProcessorInformation::GetClockInterruptsPerSecond(wchar_t * instanceName, int idleTime) +{ + wstring fullCounterPath(L""); + fullCounterPath+=L"\\Processor Information("; + fullCounterPath+=instanceName; + fullCounterPath+=L")\\Clock Interrupts/sec"; + double ret=Common::GetCounterValueWithIdle(fullCounterPath.c_str(),idleTime); + return ret; +} // Processor State Flags - +double ProcessorInformation::GetProcessorStateFlags(wchar_t * instanceName) +{ + wstring fullCounterPath(L""); + fullCounterPath+=L"\\Processor Information("; + fullCounterPath+=instanceName; + fullCounterPath+=L")\\Processor State Flags"; + double ret=Common::GetCounterValue(fullCounterPath.c_str()); + return ret; +} // % of Maximum Frequency - +double ProcessorInformation::GetPercentageOfMaximumFrequency(wchar_t * instanceName) +{ + wstring fullCounterPath(L""); + fullCounterPath+=L"\\Processor Information("; + fullCounterPath+=instanceName; + fullCounterPath+=L")\\% of Maximum Frequency"; + double ret=Common::GetCounterValue(fullCounterPath.c_str()); + return ret; +} // Processor Frequency - +double ProcessorInformation::GetProcessorFrequency(wchar_t * instanceName) +{ + wstring fullCounterPath(L""); + fullCounterPath+=L"\\Processor Information("; + fullCounterPath+=instanceName; + fullCounterPath+=L")\\Processor Frequency"; + double ret=Common::GetCounterValue(fullCounterPath.c_str()); + return ret; +} // Parking Status - +double ProcessorInformation::GetParkingStatus(wchar_t * instanceName) +{ + wstring fullCounterPath(L""); + fullCounterPath+=L"\\Processor Information("; + fullCounterPath+=instanceName; + fullCounterPath+=L")\\Parking Status"; + double ret=Common::GetCounterValue(fullCounterPath.c_str()); + return ret; +} // % Priority Time - +double ProcessorInformation::GetPriorityTimePercent(wchar_t * instanceName, int idleTime) +{ + wstring fullCounterPath(L""); + fullCounterPath+=L"\\Processor Information("; + fullCounterPath+=instanceName; + fullCounterPath+=L")\\% Priority Time"; + double ret=Common::GetCounterValueWithIdle(fullCounterPath.c_str(),idleTime); + return ret; +} // C3 Transitions/sec double ProcessorInformation::GetC3TransitionsPerSecond(wchar_t * instanceName, int idleTime) diff --git a/WindowsMonitor/Monitor/ProcessorInformation.h b/WindowsMonitor/Monitor/ProcessorInformation.h index b362854b..10ae2218 100644 --- a/WindowsMonitor/Monitor/ProcessorInformation.h +++ b/WindowsMonitor/Monitor/ProcessorInformation.h @@ -9,6 +9,19 @@ class MONITOR_API ProcessorInformation public: static list GetInstances(); static list GetCounterList(); + static double GetPerformanceLimitFlags(wchar_t * instanceName); + static double GetPerformanceLimitPercent(wchar_t * instanceName); + static double GetPrivilegedUtilityPercent(wchar_t * instanceName, int idleTime); + static double GetProcessorUtilityPercent(wchar_t * instanceName, int idleTime); + static double GetProcessorPerformancePercent(wchar_t * instanceName, int idleTime); + static double GetIdleBreakEventsPerSecond(wchar_t * instanceName, int idleTime); + static double GetAverageIdleTime(wchar_t * instanceName, int idleTime); + static double GetClockInterruptsPerSecond(wchar_t * instanceName, int idleTime); + static double GetProcessorStateFlags(wchar_t * instanceName); + static double GetPercentageOfMaximumFrequency(wchar_t * instanceName); + static double GetProcessorFrequency(wchar_t * instanceName); + static double GetParkingStatus(wchar_t * instanceName); + static double GetPriorityTimePercent(wchar_t * instanceName, int idleTime); static double GetC3TransitionsPerSecond(wchar_t * instanceName, int idleTime); static double GetC2TransitionsPerSecond(wchar_t * instanceName, int idleTime); static double GetC1TransitionsPerSecond(wchar_t * instanceName, int idleTime); diff --git a/WindowsMonitor/Native/MonitorApi.h b/WindowsMonitor/Native/MonitorApi.h index b09c906f..40ae84da 100644 --- a/WindowsMonitor/Native/MonitorApi.h +++ b/WindowsMonitor/Native/MonitorApi.h @@ -37,6 +37,33 @@ class MONITOR_API ProcessorInformation public: static list GetInstances(); static list GetCounterList(); + static double GetPerformanceLimitFlags(wchar_t * instanceName); + static double GetPerformanceLimitPercent(wchar_t * instanceName); + static double GetPrivilegedUtilityPercent(wchar_t * instanceName, int idleTime); + static double GetProcessorUtilityPercent(wchar_t * instanceName, int idleTime); + static double GetProcessorPerformancePercent(wchar_t * instanceName, int idleTime); + static double GetIdleBreakEventsPerSecond(wchar_t * instanceName, int idleTime); + static double GetAverageIdleTime(wchar_t * instanceName, int idleTime); + static double GetClockInterruptsPerSecond(wchar_t * instanceName, int idleTime); + static double GetProcessorStateFlags(wchar_t * instanceName); + static double GetPercentageOfMaximumFrequency(wchar_t * instanceName); + static double GetProcessorFrequency(wchar_t * instanceName); + static double GetParkingStatus(wchar_t * instanceName); + static double GetPriorityTimePercent(wchar_t * instanceName, int idleTime); + static double GetC3TransitionsPerSecond(wchar_t * instanceName, int idleTime); + static double GetC2TransitionsPerSecond(wchar_t * instanceName, int idleTime); + static double GetC1TransitionsPerSecond(wchar_t * instanceName, int idleTime); + static double GetC3TimePercent(wchar_t * instanceName, int idleTime); + static double GetC2TimePercent(wchar_t * instanceName, int idleTime); + static double GetC1TimePercent(wchar_t * instanceName, int idleTime); + static double GetIdleTimePercent(wchar_t * instanceName, int idleTime); + static double GetDpcRate(wchar_t * instanceName); + static double GetDpcsQueuedPerSecond(wchar_t * instanceName, int idleTime); + static double GetInterruptTimePercent(wchar_t * instanceName, int idleTime); + static double GetDpcTimePercent(wchar_t * instanceName, int idleTime); + static double GetInterruptsPerSecond(wchar_t * instanceName, int idleTime); + static double GetPrivilegedTimePercent(wchar_t * instanceName, int idleTime); + static double GetUserTimePercent(wchar_t * instanceName, int idleTime); static double GetProcessorTimePercent(wchar_t * instanceName, int idleTime); }; diff --git a/WindowsMonitor/Test/MonitorApi.h b/WindowsMonitor/Test/MonitorApi.h index b09c906f..40ae84da 100644 --- a/WindowsMonitor/Test/MonitorApi.h +++ b/WindowsMonitor/Test/MonitorApi.h @@ -37,6 +37,33 @@ class MONITOR_API ProcessorInformation public: static list GetInstances(); static list GetCounterList(); + static double GetPerformanceLimitFlags(wchar_t * instanceName); + static double GetPerformanceLimitPercent(wchar_t * instanceName); + static double GetPrivilegedUtilityPercent(wchar_t * instanceName, int idleTime); + static double GetProcessorUtilityPercent(wchar_t * instanceName, int idleTime); + static double GetProcessorPerformancePercent(wchar_t * instanceName, int idleTime); + static double GetIdleBreakEventsPerSecond(wchar_t * instanceName, int idleTime); + static double GetAverageIdleTime(wchar_t * instanceName, int idleTime); + static double GetClockInterruptsPerSecond(wchar_t * instanceName, int idleTime); + static double GetProcessorStateFlags(wchar_t * instanceName); + static double GetPercentageOfMaximumFrequency(wchar_t * instanceName); + static double GetProcessorFrequency(wchar_t * instanceName); + static double GetParkingStatus(wchar_t * instanceName); + static double GetPriorityTimePercent(wchar_t * instanceName, int idleTime); + static double GetC3TransitionsPerSecond(wchar_t * instanceName, int idleTime); + static double GetC2TransitionsPerSecond(wchar_t * instanceName, int idleTime); + static double GetC1TransitionsPerSecond(wchar_t * instanceName, int idleTime); + static double GetC3TimePercent(wchar_t * instanceName, int idleTime); + static double GetC2TimePercent(wchar_t * instanceName, int idleTime); + static double GetC1TimePercent(wchar_t * instanceName, int idleTime); + static double GetIdleTimePercent(wchar_t * instanceName, int idleTime); + static double GetDpcRate(wchar_t * instanceName); + static double GetDpcsQueuedPerSecond(wchar_t * instanceName, int idleTime); + static double GetInterruptTimePercent(wchar_t * instanceName, int idleTime); + static double GetDpcTimePercent(wchar_t * instanceName, int idleTime); + static double GetInterruptsPerSecond(wchar_t * instanceName, int idleTime); + static double GetPrivilegedTimePercent(wchar_t * instanceName, int idleTime); + static double GetUserTimePercent(wchar_t * instanceName, int idleTime); static double GetProcessorTimePercent(wchar_t * instanceName, int idleTime); }; diff --git a/WindowsMonitor/Test/Test.cpp b/WindowsMonitor/Test/Test.cpp index 499fc9d4..d41f8f72 100644 --- a/WindowsMonitor/Test/Test.cpp +++ b/WindowsMonitor/Test/Test.cpp @@ -1,23 +1,10 @@ #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) -{ - list counterList=Process::GetCounterList(); - list instances=Process::GetInstances(); - list::iterator iter; - std::wcout.imbue(std::locale("chs")); - //for(iter=counterList.begin();iter!=counterList.end();iter++) - //{ - // wcout<<(*iter).c_str()<