[+] AuHwInfo::GetThreadCPUUtilization(AuOptional<bool> optIncludeKernel)

This commit is contained in:
Reece Wilson 2023-11-29 04:10:40 +00:00
parent 2d58f8fdef
commit ed823a9819
2 changed files with 16 additions and 3 deletions

View File

@ -6,7 +6,8 @@
Author: Reece
Note: This API does not query system-wide CPU utilization
This belongs alongside AuProcess just about as much as our memory stat APIs do. I think it's fine to keep hardware perf query apis under AuHwInfo.
These APIs belong to the AuProcess subsystem just about as much as our memory-usage stat APIs do.
(I think it's fine to keep hardware perf query apis under AuHwInfo, even if they are process rel)
***/
#pragma once
@ -28,4 +29,5 @@ namespace Aurora::HWInfo
bool bCountKernelUsage = false); // False = Ignore kernel work under our callstack
AUKN_SYM double GetProcessCPUUtilization();
AUKN_SYM double GetThreadCPUUtilization(AuOptional<bool> optIncludeKernel = { true });
}

View File

@ -10,6 +10,13 @@
namespace Aurora::HWInfo
{
static thread_local CpuLoadSamplerImpl tlsThreadLocalUsageSamplers[2] {
CpuLoadSamplerImpl(AuSToMS<AuUInt32>(1), true, false),
CpuLoadSamplerImpl(AuSToMS<AuUInt32>(1), true, true)
};
static CpuLoadSamplerImpl gProcessUsageSampler(AuSToMS<AuUInt32>(1), false, true);
CpuLoadSamplerImpl::CpuLoadSamplerImpl(AuUInt32 uMinSamplePeriodMS,
bool bThreadMode,
bool bCountKernelUsage) :
@ -112,8 +119,12 @@ namespace Aurora::HWInfo
AUKN_SYM double GetProcessCPUUtilization()
{
static CpuLoadSamplerImpl gSampler(AuSToMS<AuUInt32>(1), false, false);
return gSampler.GetLoad();
return gProcessUsageSampler.GetLoad();
}
AUKN_SYM double GetThreadCPUUtilization(AuOptional<bool> optIncludeKernel)
{
return tlsThreadLocalUsageSamplers[optIncludeKernel.value_or(true)].GetLoad();
}
AUKN_SYM ICpuLoadSampler *CpuLoadSamplerNew(AuUInt32 uMinSamplePeriodMS,