Код: Выделить всё
map ProcessMap;
map processUsageCPU;
map processUsageMEM;
void* getProcessUsage(){
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
int numProcessors = sysInfo.dwNumberOfProcessors;
while(1){
map usrTimesLast;
map systemTimesLast;
map checkTimes;
list procBuffer;
for(auto process : ProcessMap){
procBuffer.push_back(process.first);
//take its user time and system time and put it in the respective map
FILETIME uTime, sTime, fTime, cTime, tTime;
GetSystemTimeAsFileTime(&tTime);
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, process.first);
GetProcessTimes(hProcess,&cTime, &fTime, &sTime, &uTime);
usrTimesLast[process.first] = uTime;
systemTimesLast[process.first] = sTime;
checkTimes[process.first] = tTime;
CloseHandle(hProcess);
}
Sleep(REFRESH*0.5);
for(unsigned int process : procBuffer){
FILETIME NuTime, NsTime, NfTime, NcTime, NtTime;
FILETIME uTime = usrTimesLast[process];
FILETIME sTime = systemTimesLast[process];
FILETIME tTime = checkTimes[process];
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, process);
GetProcessTimes(hProcess, &NcTime,&NfTime,&NsTime,&NuTime);
GetSystemTimeAsFileTime(&NtTime);
ULARGE_INTEGER kerL,kerR,usrL,usrR,timeL, timeR;
memcpy(&timeL, &tTime, sizeof(FILETIME));
memcpy(&timeR, &NtTime, sizeof(FILETIME));
long long totTime = timeR.QuadPart - timeL.QuadPart;
memcpy(&kerL, &sTime, sizeof(FILETIME));
memcpy(&kerR, &NsTime, sizeof(FILETIME));
long long kernTime = kerR.QuadPart - kerL.QuadPart;
memcpy(&usrL, &uTime, sizeof(FILETIME));
memcpy(&usrR, &NuTime, sizeof(FILETIME));
long long userTime = usrR.QuadPart - usrL.QuadPart;
long long systemTime = kernTime + userTime;
processUsageCPU[process] = (totTime - systemTime) * 100 / numProcessors;
qDebug()
Изменение времени задержки не оказывает эффекта. Я попробовал другой вариант этой программы, найденной в Интернете, используя GetProcessTimes Подробнее здесь: https://stackoverflow.com/questions/795 ... fter-delay