diff --git a/Include/Aurora/HWInfo/CoreLoadSampler.hpp b/Include/Aurora/HWInfo/CoreLoadSampler.hpp index 74e79277..441c3f82 100644 --- a/Include/Aurora/HWInfo/CoreLoadSampler.hpp +++ b/Include/Aurora/HWInfo/CoreLoadSampler.hpp @@ -23,11 +23,15 @@ namespace Aurora::HWInfo virtual double GetTotalLoadCached() = 0; virtual double *GetCoreLoadsCached(AuUInt32 *pOut) = 0; + + virtual void SetNoAggressiveFiltering(bool bNoFiltering) = 0; + virtual bool GetNoAggressiveFiltering() = 0; }; - AUKN_SHARED_API(CoreLoadSampler, ICoreLoadSampler, - AuUInt32 uMinSamplePeriodMS = AuSToMS(1), - bool bCountKernelUsage = true); + AUKN_SHARED_SOO2_NCM(CoreLoadSampler, ICoreLoadSampler, 128, + ((AuUInt32, uMinSamplePeriodMS), (bool, bCountKernelUsage)), + AuUInt32 uMinSamplePeriodMS = AuSToMS(1), + bool bCountKernelUsage = true); AUKN_SYM ICoreLoadSampler *GetDefaultCoreLoadSampler(); } \ No newline at end of file diff --git a/Include/Aurora/HWInfo/ProcessLoadSampler.hpp b/Include/Aurora/HWInfo/ProcessLoadSampler.hpp index b8e4c15b..ff37e6b1 100644 --- a/Include/Aurora/HWInfo/ProcessLoadSampler.hpp +++ b/Include/Aurora/HWInfo/ProcessLoadSampler.hpp @@ -20,9 +20,12 @@ namespace Aurora::HWInfo * @return a percentage (0 - 100; as a decimal) of the local process or thread CPU usage between ::GetLoad() calls, with respect to a uMinSamplePeriod averaging period. */ virtual double GetLoad() = 0; + + virtual void SetNoAggressiveFiltering(bool bNoFiltering) = 0; + virtual bool GetNoAggressiveFiltering() = 0; }; - AUKN_SHARED_SOO2_NCM(ProcessLoadSampler, IProcessLoadSampler, 64, + AUKN_SHARED_SOO2_NCM(ProcessLoadSampler, IProcessLoadSampler, 128, ((AuUInt32, uMinSamplePeriodMS), (bool, bThreadMode), (bool, bCountKernelUsage)), AuUInt32 uMinSamplePeriodMS = AuSToMS(1), // May be zero bool bThreadMode = false, // False = Sample Process Usage | True = Sample Thread Usage diff --git a/Source/HWInfo/AuCoreLoadSampler.cpp b/Source/HWInfo/AuCoreLoadSampler.cpp index c9fb2dbf..1083dac2 100644 --- a/Source/HWInfo/AuCoreLoadSampler.cpp +++ b/Source/HWInfo/AuCoreLoadSampler.cpp @@ -116,12 +116,25 @@ namespace Aurora::HWInfo { dUsage[i] = dDeltaCore[i] / dDeltaSteady; - if (uMinSamplePeriod) + if (this->bNoAggressiveFiltering) + { + // nop + } + else if (uMinSamplePeriod) { if (dUsage[i] > AuNumericLimits::epsilon() && this->dPrevLoad[i] > AuNumericLimits::epsilon()) { - dUsage[i] = AuMin(dUsage[i], dUsage[i] + this->dPrevLoad[i] / 2.0); + if (dDeltaSteady >= AuMSToNS(1000)) + { + // slow tick rage: high pass filter + dUsage[i] = AuMin(dUsage[i], (dUsage[i] * 0.75) + (this->dPrevLoad[i] * 0.25)); + } + else + { + // fast tick rate: increase in load no faster than the average + dUsage[i] = AuMin(dUsage[i], (dUsage[i] + this->dPrevLoad[i]) / 2.0); + } } else { @@ -214,10 +227,20 @@ namespace Aurora::HWInfo return this->state.dCurrentLoad; } + void CoreLoadSamplerImpl::SetNoAggressiveFiltering(bool bNoFiltering) + { + this->state.bNoAggressiveFiltering = bNoFiltering; + } + + bool CoreLoadSamplerImpl::GetNoAggressiveFiltering() + { + return this->state.bNoAggressiveFiltering; + } + AUKN_SYM ICoreLoadSampler *CoreLoadSamplerNew(AuUInt32 uMinSamplePeriodMS, bool bCountKernelUsage) { - return _new CoreLoadSamplerImpl(uMinSamplePeriodMS, bCountKernelUsage); + return _new CoreLoadSamplerImpl(uMinSamplePeriodMS, bCountKernelUsage); } AUKN_SYM void CoreLoadSamplerRelease(ICoreLoadSampler *pSampler) @@ -229,4 +252,6 @@ namespace Aurora::HWInfo { return &gDefaultCoreUsageSampler; } + + AUROXTL_INTERFACE_SOO_SRC_EX(AURORA_SYMBOL_EXPORT, CoreLoadSampler, CoreLoadSamplerImpl, (AuUInt32, uMinSamplePeriod), (bool, bCountKernelUsage)) } \ No newline at end of file diff --git a/Source/HWInfo/AuCoreLoadSampler.hpp b/Source/HWInfo/AuCoreLoadSampler.hpp index 0412e581..96d9a410 100644 --- a/Source/HWInfo/AuCoreLoadSampler.hpp +++ b/Source/HWInfo/AuCoreLoadSampler.hpp @@ -22,6 +22,7 @@ namespace Aurora::HWInfo double dCurrentLoadAll {}; AuUInt64 uCount {}; bool bSet {}; + bool bNoAggressiveFiltering {}; }; struct CoreLoadSamplerImpl : ICoreLoadSampler @@ -36,6 +37,8 @@ namespace Aurora::HWInfo double GetTotalLoadCached() override; double GetCoreLoadCached(AuUInt8 uCore) override; double *GetCoreLoadsCached(AuUInt32 *pOut) override; + void SetNoAggressiveFiltering(bool bNoFiltering) override; + bool GetNoAggressiveFiltering() override; AuUInt32 uMinSamplePeriod {}; bool bCountKernelUsage {}; diff --git a/Source/HWInfo/AuCpuLoadSampler.cpp b/Source/HWInfo/AuCpuLoadSampler.cpp index dcd262bf..64f9fadd 100644 --- a/Source/HWInfo/AuCpuLoadSampler.cpp +++ b/Source/HWInfo/AuCpuLoadSampler.cpp @@ -84,12 +84,24 @@ namespace Aurora::HWInfo dUsage = dDeltaProcess / dDeltaSteady2; this->uPrevTimes[1] = now[1]; this->uPrevTimes[0] = now[0]; - if (uMinSamplePeriod) + + if (this->bNoAggressiveFiltering) + { + // nop + } + else if (uMinSamplePeriod) { if (dUsage > AuNumericLimits::epsilon() && this->dPrevLoad > AuNumericLimits::epsilon()) { - dUsage = AuMin(dUsage, dUsage + this->dPrevLoad / 2.0); + if (dDeltaSteady >= AuMSToNS(1000)) + { + dUsage = AuMin(dUsage, (dUsage * 0.75) + (this->dPrevLoad * 0.25)); + } + else + { + dUsage = AuMin(dUsage, (dUsage + this->dPrevLoad) / 2.0); + } } else { @@ -164,6 +176,16 @@ namespace Aurora::HWInfo } } + void ProcessLoadSamplerImpl::SetNoAggressiveFiltering(bool bNoFiltering) + { + this->processState.bNoAggressiveFiltering = bNoFiltering; + } + + bool ProcessLoadSamplerImpl::GetNoAggressiveFiltering() + { + return this->processState.bNoAggressiveFiltering; + } + AUKN_SYM double GetProcessCPUUtilization() { return gProcessUsageSampler.GetLoad(); diff --git a/Source/HWInfo/AuCpuLoadSampler.hpp b/Source/HWInfo/AuCpuLoadSampler.hpp index 0cbc370a..1ab7e10c 100644 --- a/Source/HWInfo/AuCpuLoadSampler.hpp +++ b/Source/HWInfo/AuCpuLoadSampler.hpp @@ -16,6 +16,7 @@ namespace Aurora::HWInfo AuUInt64 uPrevTimes[2] {}; double dPrevLoad {}; bool bSet {}; + bool bNoAggressiveFiltering {}; }; struct ProcessLoadSamplerImpl : IProcessLoadSampler @@ -27,6 +28,8 @@ namespace Aurora::HWInfo ~ProcessLoadSamplerImpl(); double GetLoad() override; + void SetNoAggressiveFiltering(bool bNoFiltering) override; + bool GetNoAggressiveFiltering() override; AuUInt32 uMinSamplePeriod {}; bool bThreadMode {};