mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 10:22:12 +02:00
CpuUsage: fix calucation on Windows
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
#include "fastfetch.h"
|
||||
#include "cpuUsage.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
#include <Windows.h>
|
||||
#include <processthreadsapi.h>
|
||||
|
||||
static inline uint64_t fileTimeToUint64(const FILETIME* ft) {
|
||||
return (((uint64_t)ft->dwHighDateTime) << 32) | ((uint64_t)ft->dwLowDateTime);
|
||||
@@ -11,10 +10,12 @@ static inline uint64_t fileTimeToUint64(const FILETIME* ft) {
|
||||
const char* ffGetCpuUsageInfo(uint64_t* inUseAll, uint64_t* totalAll)
|
||||
{
|
||||
FILETIME idleTime, kernelTime, userTime;
|
||||
if(GetSystemTimes(&idleTime, &kernelTime, &userTime) == 0)
|
||||
if(!GetSystemTimes(&idleTime, &kernelTime, &userTime))
|
||||
return "GetSystemTimes() failed";
|
||||
|
||||
*inUseAll = fileTimeToUint64(&userTime) + fileTimeToUint64(&kernelTime);
|
||||
*totalAll = *inUseAll + fileTimeToUint64(&idleTime);
|
||||
// https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getsystemtimes
|
||||
// `kernelTime` also includes the amount of time the system has been idle.
|
||||
*totalAll = fileTimeToUint64(&userTime) + fileTimeToUint64(&kernelTime);
|
||||
*inUseAll = *totalAll - fileTimeToUint64(&idleTime);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user