diff --git a/src/cpu_win32.cpp b/src/cpu_win32.cpp new file mode 100644 index 00000000..e6be55f4 --- /dev/null +++ b/src/cpu_win32.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include "cpu.h" +#include +#define SystemProcessorPerformanceInformation 0x8 +#define SystemBasicInformation 0x0 +FILETIME last_userTime, last_kernelTime, last_idleTime; + +uint64_t FileTimeToInt64( const FILETIME& ft ) { + ULARGE_INTEGER uli = { 0 }; + uli.LowPart = ft.dwLowDateTime; + uli.HighPart = ft.dwHighDateTime; + return uli.QuadPart; +} + +bool CPUStats::UpdateCPUData() +{ + #define NUMBER_OF_PROCESSORS (8) + #define PROCESSOR_BUFFER_SIZE (NUMBER_OF_PROCESSORS * 8) + static ULONG64 ProcessorIdleTimeBuffer [ PROCESSOR_BUFFER_SIZE ]; + + FILETIME IdleTime, KernelTime, UserTime; + static unsigned long long PrevTotal = 0; + static unsigned long long PrevIdle = 0; + static unsigned long long PrevUser = 0; + unsigned long long ThisTotal; + unsigned long long ThisIdle, ThisKernel, ThisUser; + unsigned long long TotalSinceLast, IdleSinceLast, UserSinceLast; + + + // GET THE KERNEL / USER / IDLE times. + // And oh, BTW, kernel time includes idle time + GetSystemTimes( & IdleTime, & KernelTime, & UserTime); + + ThisIdle = FileTimeToInt64(IdleTime); + ThisKernel = FileTimeToInt64 (KernelTime); + ThisUser = FileTimeToInt64 (UserTime); + + ThisTotal = ThisKernel + ThisUser; + TotalSinceLast = ThisTotal - PrevTotal; + IdleSinceLast = ThisIdle - PrevIdle; + UserSinceLast = ThisUser - PrevUser; + double Headroom; + Headroom = (double)IdleSinceLast / (double)TotalSinceLast ; + double Load; + Load = 1.0 - Headroom; + Headroom *= 100.0; // to make it percent + Load *= 100.0; // percent + + PrevTotal = ThisTotal; + PrevIdle = ThisIdle; + PrevUser = ThisUser; + + // print results to output window of VS when run in Debug + m_cpuDataTotal.percent = Load; + return true; +} +CPUStats::CPUStats() +{ +} +CPUStats::~CPUStats() +{ +} +CPUStats cpuStats; \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index 3cb1d4e4..3d283107 100644 --- a/src/meson.build +++ b/src/meson.build @@ -39,6 +39,7 @@ opengl_files = [] if ['windows', 'mingw'].contains(host_machine.system()) vklayer_files += files( 'file_utils_win32.cpp', + 'cpu_win32.cpp', 'win/main.cpp', 'win/kiero.cpp', 'win/d3d12_hook.cpp', diff --git a/src/overlay.cpp b/src/overlay.cpp index f1633b52..b3a15aa5 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -12,19 +12,20 @@ #include "string_utils.h" struct benchmark_stats benchmark; +struct fps_limit fps_limit_stats {}; void update_hw_info(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID) { -#ifdef __gnu_linux__ if (params.enabled[OVERLAY_PARAM_ENABLED_cpu_stats] || logger->is_active()) { cpuStats.UpdateCPUData(); +#ifdef __gnu_linux__ if (params.enabled[OVERLAY_PARAM_ENABLED_core_load]) cpuStats.UpdateCoreMhz(); if (params.enabled[OVERLAY_PARAM_ENABLED_cpu_temp] || logger->is_active()) cpuStats.UpdateCpuTemp(); +#endif } - if (params.enabled[OVERLAY_PARAM_ENABLED_gpu_stats] || logger->is_active()) { if (vendorID == 0x1002) getAmdGpuInfo(); @@ -35,21 +36,24 @@ void update_hw_info(struct swapchain_stats& sw_stats, struct overlay_params& par // get ram usage/max +#ifdef __gnu_linux__ if (params.enabled[OVERLAY_PARAM_ENABLED_ram] || logger->is_active()) update_meminfo(); if (params.enabled[OVERLAY_PARAM_ENABLED_io_read] || params.enabled[OVERLAY_PARAM_ENABLED_io_write]) getIoStats(&sw_stats.io); +#endif currentLogData.gpu_load = gpu_info.load; currentLogData.gpu_temp = gpu_info.temp; currentLogData.gpu_core_clock = gpu_info.CoreClock; currentLogData.gpu_mem_clock = gpu_info.MemClock; currentLogData.gpu_vram_used = gpu_info.memoryUsed; +#ifdef __gnu_linux__ currentLogData.ram_used = memused; +#endif currentLogData.cpu_load = cpuStats.GetCPUDataTotal().percent; currentLogData.cpu_temp = cpuStats.GetCPUDataTotal().temp; -#endif logger->notify_data_valid(); }