CPUUsage(Windows): add new method using Windows Performance Library

This commit is contained in:
李通洲
2025-07-01 20:53:46 +08:00
parent d5b56be4ff
commit 4abb183735
5 changed files with 139 additions and 0 deletions
+9
View File
@@ -27,6 +27,11 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options)
if (*percent == *percent)
{
sumValue += *percent;
#if FF_ENABLE_CPUUSAGE_PERFLIB
// Windows may return values greater than 100%, cap them to 100%
if (*percent > 100) *percent = 100;
#endif
if (*percent > maxValue)
{
maxValue = *percent;
@@ -42,6 +47,10 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options)
++index;
}
double avgValue = sumValue / (double) valueCount;
#if FF_ENABLE_CPUUSAGE_PERFLIB
// See above comment
if (avgValue > 100) avgValue = 100;
#endif
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;