Win32 cpu usage

pull/337/head^2
FlightlessMango 4 years ago
parent ff5d85a4a5
commit cbd87585b4

@ -0,0 +1,65 @@
#include <windows.h>
#include <thread>
#include <string.h>
#include "cpu.h"
#include <iostream>
#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;

@ -39,6 +39,7 @@ opengl_files = []
if ['windows', 'mingw'].contains(host_machine.system()) if ['windows', 'mingw'].contains(host_machine.system())
vklayer_files += files( vklayer_files += files(
'file_utils_win32.cpp', 'file_utils_win32.cpp',
'cpu_win32.cpp',
'win/main.cpp', 'win/main.cpp',
'win/kiero.cpp', 'win/kiero.cpp',
'win/d3d12_hook.cpp', 'win/d3d12_hook.cpp',

@ -12,19 +12,20 @@
#include "string_utils.h" #include "string_utils.h"
struct benchmark_stats benchmark; 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) 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()) { if (params.enabled[OVERLAY_PARAM_ENABLED_cpu_stats] || logger->is_active()) {
cpuStats.UpdateCPUData(); cpuStats.UpdateCPUData();
#ifdef __gnu_linux__
if (params.enabled[OVERLAY_PARAM_ENABLED_core_load]) if (params.enabled[OVERLAY_PARAM_ENABLED_core_load])
cpuStats.UpdateCoreMhz(); cpuStats.UpdateCoreMhz();
if (params.enabled[OVERLAY_PARAM_ENABLED_cpu_temp] || logger->is_active()) if (params.enabled[OVERLAY_PARAM_ENABLED_cpu_temp] || logger->is_active())
cpuStats.UpdateCpuTemp(); cpuStats.UpdateCpuTemp();
#endif
} }
if (params.enabled[OVERLAY_PARAM_ENABLED_gpu_stats] || logger->is_active()) { if (params.enabled[OVERLAY_PARAM_ENABLED_gpu_stats] || logger->is_active()) {
if (vendorID == 0x1002) if (vendorID == 0x1002)
getAmdGpuInfo(); getAmdGpuInfo();
@ -35,21 +36,24 @@ void update_hw_info(struct swapchain_stats& sw_stats, struct overlay_params& par
// get ram usage/max // get ram usage/max
#ifdef __gnu_linux__
if (params.enabled[OVERLAY_PARAM_ENABLED_ram] || logger->is_active()) if (params.enabled[OVERLAY_PARAM_ENABLED_ram] || logger->is_active())
update_meminfo(); update_meminfo();
if (params.enabled[OVERLAY_PARAM_ENABLED_io_read] || params.enabled[OVERLAY_PARAM_ENABLED_io_write]) if (params.enabled[OVERLAY_PARAM_ENABLED_io_read] || params.enabled[OVERLAY_PARAM_ENABLED_io_write])
getIoStats(&sw_stats.io); getIoStats(&sw_stats.io);
#endif
currentLogData.gpu_load = gpu_info.load; currentLogData.gpu_load = gpu_info.load;
currentLogData.gpu_temp = gpu_info.temp; currentLogData.gpu_temp = gpu_info.temp;
currentLogData.gpu_core_clock = gpu_info.CoreClock; currentLogData.gpu_core_clock = gpu_info.CoreClock;
currentLogData.gpu_mem_clock = gpu_info.MemClock; currentLogData.gpu_mem_clock = gpu_info.MemClock;
currentLogData.gpu_vram_used = gpu_info.memoryUsed; currentLogData.gpu_vram_used = gpu_info.memoryUsed;
#ifdef __gnu_linux__
currentLogData.ram_used = memused; currentLogData.ram_used = memused;
#endif
currentLogData.cpu_load = cpuStats.GetCPUDataTotal().percent; currentLogData.cpu_load = cpuStats.GetCPUDataTotal().percent;
currentLogData.cpu_temp = cpuStats.GetCPUDataTotal().temp; currentLogData.cpu_temp = cpuStats.GetCPUDataTotal().temp;
#endif
logger->notify_data_valid(); logger->notify_data_valid();
} }

Loading…
Cancel
Save