From ca4288b513a20b86e11030e0819ba3630c143efc Mon Sep 17 00:00:00 2001 From: kuramochia Date: Wed, 7 Aug 2024 10:02:11 +0900 Subject: [PATCH 1/4] Change counter --- Sources/Windows/CpuUsageHelper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Windows/CpuUsageHelper.cpp b/Sources/Windows/CpuUsageHelper.cpp index 8b53765..ba78f23 100644 --- a/Sources/Windows/CpuUsageHelper.cpp +++ b/Sources/Windows/CpuUsageHelper.cpp @@ -15,7 +15,7 @@ CpuUsageHelper::CpuUsageHelper() { PdhOpenQuery(nullptr, NULL, &mCpuQuery); - PdhAddEnglishCounter(mCpuQuery, L"\\Processor(_Total)\\% Processor Time", NULL, &mCpuTotal); + PdhAddEnglishCounter(mCpuQuery, L"\\Processor Information(_Total)\\% Processor Utility", NULL, &mCpuTotal); PdhCollectQueryData(mCpuQuery); GetCurrentCPUValue(); } @@ -27,4 +27,4 @@ int CpuUsageHelper::GetCurrentCPUValue() PdhCollectQueryData(mCpuQuery); PdhGetFormattedCounterValue(mCpuTotal, PDH_FMT_LONG, NULL, &counterVal); return (int)counterVal.longValue; -} \ No newline at end of file +} From 16b56adc33ecd89bc131c5c4bb1c394d906fa211 Mon Sep 17 00:00:00 2001 From: kuramochia Date: Sat, 10 Aug 2024 08:09:48 +0900 Subject: [PATCH 2/4] set limit 100% --- Sources/Windows/CpuUsageHelper.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/Windows/CpuUsageHelper.cpp b/Sources/Windows/CpuUsageHelper.cpp index ba78f23..2703ae7 100644 --- a/Sources/Windows/CpuUsageHelper.cpp +++ b/Sources/Windows/CpuUsageHelper.cpp @@ -11,6 +11,7 @@ //============================================================================== #include "CpuUsageHelper.h" +#include CpuUsageHelper::CpuUsageHelper() { @@ -26,5 +27,6 @@ int CpuUsageHelper::GetCurrentCPUValue() PdhCollectQueryData(mCpuQuery); PdhGetFormattedCounterValue(mCpuTotal, PDH_FMT_LONG, NULL, &counterVal); - return (int)counterVal.longValue; + int result = std::min((int)counterVal.longValue, 100); + return result; } From 82c70b45f27737da83d339416762c8fbd5656bb8 Mon Sep 17 00:00:00 2001 From: kuramochia Date: Sat, 10 Aug 2024 08:17:23 +0900 Subject: [PATCH 3/4] min function to define. --- Sources/Windows/CpuUsageHelper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Windows/CpuUsageHelper.cpp b/Sources/Windows/CpuUsageHelper.cpp index 2703ae7..37da269 100644 --- a/Sources/Windows/CpuUsageHelper.cpp +++ b/Sources/Windows/CpuUsageHelper.cpp @@ -11,7 +11,7 @@ //============================================================================== #include "CpuUsageHelper.h" -#include +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) CpuUsageHelper::CpuUsageHelper() { @@ -27,6 +27,6 @@ int CpuUsageHelper::GetCurrentCPUValue() PdhCollectQueryData(mCpuQuery); PdhGetFormattedCounterValue(mCpuTotal, PDH_FMT_LONG, NULL, &counterVal); - int result = std::min((int)counterVal.longValue, 100); + int result = (int)(MIN(counterVal.longValue, (LONG)100)); return result; } From 1fe40688349683b792ce3dd6224450812cd58d80 Mon Sep 17 00:00:00 2001 From: kuramochia Date: Mon, 19 Aug 2024 20:41:53 +0900 Subject: [PATCH 4/4] remove unused variables --- Sources/Windows/CpuUsageHelper.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sources/Windows/CpuUsageHelper.cpp b/Sources/Windows/CpuUsageHelper.cpp index 37da269..bf365d8 100644 --- a/Sources/Windows/CpuUsageHelper.cpp +++ b/Sources/Windows/CpuUsageHelper.cpp @@ -27,6 +27,5 @@ int CpuUsageHelper::GetCurrentCPUValue() PdhCollectQueryData(mCpuQuery); PdhGetFormattedCounterValue(mCpuTotal, PDH_FMT_LONG, NULL, &counterVal); - int result = (int)(MIN(counterVal.longValue, (LONG)100)); - return result; + return (int)(MIN(counterVal.longValue, 100L)); }