I am using Win32 x64 Environment
Please go link below too
I have found an answer from this link Collecting CPU Usage of a Process
Under first answer for Windows criteria,you able to see code snippet as below:
double getCurrentValue(){
FILETIME ftime, fsys, fuser;
ULARGE_INTEGER now, sys, user;
double percent;
GetSystemTimeAsFileTime(&ftime);
memcpy(&now, &ftime, sizeof(FILETIME));
GetProcessTimes(self, &ftime, &ftime, &fsys, &fuser);
memcpy(&sys, &fsys, sizeof(FILETIME));
memcpy(&user, &fuser, sizeof(FILETIME));
percent = (sys.QuadPart - lastSysCPU.QuadPart) +
(user.QuadPart - lastUserCPU.QuadPart);
percent /= (now.QuadPart - lastCPU.QuadPart);
percent /= numProcessors;
lastCPU = now;
lastUserCPU = user;
lastSysCPU = sys;
return percent * 100;
}
//--------------------------- FOCUS -----------------------------//
percent = (sys.QuadPart - lastSysCPU.QuadPart) +(user.QuadPart - lastUserCPU.QuadPart); // ---(1)
percent /= (now.QuadPart - lastCPU.QuadPart); // ---(2)
percent /= numProcessors; // --- (3)
As in line (1) assigning ULONGLONG(unsigned long long) to double give compiler warning C4244: conversion from 'ULONGLONG' to 'double', possible loss of data
- Therefore @Line #(1),(2) & (3) how can we have a guarantee about the value of
double precent
data?
(Since Ulonglong 64 bit integral data convert to 64bit floating point data)
- Sometimes this
precent
value gets value above 100.00 for time stamps as CPU Usage