2022-10-07 16:52:52 +08:00
|
|
|
#include "fastfetch.h"
|
|
|
|
|
#include "cpuUsage.h"
|
|
|
|
|
|
2022-11-15 17:30:16 +08:00
|
|
|
#include <processthreadsapi.h>
|
2022-10-07 16:52:52 +08:00
|
|
|
|
|
|
|
|
static inline uint64_t fileTimeToUint64(const FILETIME* ft) {
|
|
|
|
|
return (((uint64_t)ft->dwHighDateTime) << 32) | ((uint64_t)ft->dwLowDateTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* ffGetCpuUsageInfo(uint64_t* inUseAll, uint64_t* totalAll)
|
|
|
|
|
{
|
|
|
|
|
FILETIME idleTime, kernelTime, userTime;
|
2022-11-15 17:30:16 +08:00
|
|
|
if(!GetSystemTimes(&idleTime, &kernelTime, &userTime))
|
2022-10-07 16:52:52 +08:00
|
|
|
return "GetSystemTimes() failed";
|
|
|
|
|
|
2022-11-15 17:30:16 +08:00
|
|
|
// 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);
|
2022-10-07 16:52:52 +08:00
|
|
|
return NULL;
|
|
|
|
|
}
|