[*] Ignore kernel CPU usage by default
[*] Normalize cpu load over queries
This commit is contained in:
parent
087bac4085
commit
77253a7654
@ -22,9 +22,10 @@ namespace Aurora::HWInfo
|
||||
};
|
||||
|
||||
AUKN_SHARED_SOO2_NCM(CpuLoadSampler, ICpuLoadSampler, 64,
|
||||
((AuUInt32, bTriggered), (bool, bThreadMode)),
|
||||
((AuUInt32, uMinSamplePeriodMS), (bool, bThreadMode), (bool, bCountKernelUsage)),
|
||||
AuUInt32 uMinSamplePeriodMS = AuSToMS<AuUInt32>(1), // May be zero
|
||||
bool bThreadMode = false); // False = Sample Process Usage | True = Sample Thread Usage
|
||||
bool bThreadMode = false, // False = Sample Process Usage | True = Sample Thread Usage
|
||||
bool bCountKernelUsage = false); // False = Ignore kernel work under our callstack
|
||||
|
||||
AUKN_SYM double GetProcessCPUUtilization();
|
||||
}
|
@ -11,9 +11,11 @@
|
||||
namespace Aurora::HWInfo
|
||||
{
|
||||
CpuLoadSamplerImpl::CpuLoadSamplerImpl(AuUInt32 uMinSamplePeriodMS,
|
||||
bool bThreadMode) :
|
||||
bool bThreadMode,
|
||||
bool bCountKernelUsage) :
|
||||
uMinSamplePeriod(uMinSamplePeriodMS),
|
||||
bThreadMode(bThreadMode)
|
||||
bThreadMode(bThreadMode),
|
||||
bCountKernelUsage(bCountKernelUsage)
|
||||
{
|
||||
|
||||
}
|
||||
@ -28,19 +30,21 @@ namespace Aurora::HWInfo
|
||||
{
|
||||
if (!this->bThreadMode)
|
||||
{
|
||||
return this->processState.GetLoad(this->uMinSamplePeriod, false);
|
||||
return this->processState.GetLoad(this->uMinSamplePeriod, false, this->bCountKernelUsage);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this->threadState->GetLoad(this->uMinSamplePeriod, true);
|
||||
return this->threadState->GetLoad(this->uMinSamplePeriod, true, this->bCountKernelUsage);
|
||||
}
|
||||
}
|
||||
|
||||
double CpuLoadSamplerState::GetLoad(AuUInt32 uMinSamplePeriod, bool bThread)
|
||||
double CpuLoadSamplerState::GetLoad(AuUInt32 uMinSamplePeriod, bool bThread, bool bCountKernelUsage)
|
||||
{
|
||||
AuUInt64 now[2] = {
|
||||
AuTime::SteadyClockNS(),
|
||||
bThread ? AuTime::ThreadClockNS() : AuTime::ProcessClockNS()
|
||||
bThread ?
|
||||
(bCountKernelUsage ? AuTime::ThreadClockNS() : AuTime::ThreadUserClockNS()) :
|
||||
(bCountKernelUsage ? AuTime::ProcessClockNS() : AuTime::ProcessUserClockNS())
|
||||
};
|
||||
|
||||
double dDeltaSteady = now[0] - this->uPrevTimes[0];
|
||||
@ -61,6 +65,10 @@ namespace Aurora::HWInfo
|
||||
dUsage = dDeltaProcess / dDeltaSteady;
|
||||
this->uPrevTimes[1] = now[1];
|
||||
this->uPrevTimes[0] = now[0];
|
||||
#if 1
|
||||
if (uMinSamplePeriod &&
|
||||
this->dPrevLoad) dUsage = AuMin(dUsage, dUsage + this->dPrevLoad / 2.0);
|
||||
#endif
|
||||
this->dPrevLoad = dUsage;
|
||||
}
|
||||
else
|
||||
@ -104,14 +112,15 @@ namespace Aurora::HWInfo
|
||||
|
||||
AUKN_SYM double GetProcessCPUUtilization()
|
||||
{
|
||||
static CpuLoadSamplerImpl gSampler(AuSToMS<AuUInt32>(1), false);
|
||||
static CpuLoadSamplerImpl gSampler(AuSToMS<AuUInt32>(1), false, false);
|
||||
return gSampler.GetLoad();
|
||||
}
|
||||
|
||||
AUKN_SYM ICpuLoadSampler *CpuLoadSamplerNew(AuUInt32 uMinSamplePeriodMS,
|
||||
bool bThreadMode)
|
||||
bool bThreadMode,
|
||||
bool bCountKernelUsage)
|
||||
{
|
||||
return _new CpuLoadSamplerImpl(uMinSamplePeriodMS, bThreadMode);
|
||||
return _new CpuLoadSamplerImpl(uMinSamplePeriodMS, bThreadMode, bCountKernelUsage);
|
||||
}
|
||||
|
||||
AUKN_SYM void CpuLoadSamplerRelease(ICpuLoadSampler *pEvent)
|
||||
@ -119,5 +128,5 @@ namespace Aurora::HWInfo
|
||||
AuSafeDelete<CpuLoadSamplerImpl *>(pEvent);
|
||||
}
|
||||
|
||||
AUROXTL_INTERFACE_SOO_SRC_EX(AURORA_SYMBOL_EXPORT, CpuLoadSampler, CpuLoadSamplerImpl, (AuUInt32, uMinSamplePeriod), (bool, bThreadMode))
|
||||
AUROXTL_INTERFACE_SOO_SRC_EX(AURORA_SYMBOL_EXPORT, CpuLoadSampler, CpuLoadSamplerImpl, (AuUInt32, uMinSamplePeriod), (bool, bThreadMode), (bool, bCountKernelUsage))
|
||||
}
|
@ -11,7 +11,7 @@ namespace Aurora::HWInfo
|
||||
{
|
||||
struct CpuLoadSamplerState
|
||||
{
|
||||
double GetLoad(AuUInt32 uMinSamplePeriod, bool bThread);
|
||||
double GetLoad(AuUInt32 uMinSamplePeriod, bool bThread, bool bCountKernelUsage);
|
||||
|
||||
AuUInt64 uPrevTimes[2] {};
|
||||
double dPrevLoad {};
|
||||
@ -20,7 +20,8 @@ namespace Aurora::HWInfo
|
||||
struct CpuLoadSamplerImpl : ICpuLoadSampler
|
||||
{
|
||||
CpuLoadSamplerImpl(AuUInt32 uMinSamplePeriodMS,
|
||||
bool bThreadMode);
|
||||
bool bThreadMode,
|
||||
bool bCountKernelUsage);
|
||||
|
||||
~CpuLoadSamplerImpl();
|
||||
|
||||
@ -28,6 +29,7 @@ namespace Aurora::HWInfo
|
||||
|
||||
AuUInt32 uMinSamplePeriod {};
|
||||
bool bThreadMode {};
|
||||
bool bCountKernelUsage {};
|
||||
CpuLoadSamplerState processState;
|
||||
AuTLSVariable<CpuLoadSamplerState> threadState;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user