1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| PROCEDURE GLOBAL CPU
// Déclaration de CPU
FILETIME is structure
dwLowDateTime is unsigned int
dwHighDateTime is unsigned int
FIN
TIMEF is structure
last_idleTime is FILETIME
last_kernelTime is FILETIME
last_userTime is FILETIME
END
gFT is TIMEF
// Pocédures globales
FUNCTION GetSystemTimes(idleTime is FILETIME, kernelTime is FILETIME, userTime is FILETIME)
bRet is boolean = API(KERNEL32, "GetSystemTimes", &idleTime, &kernelTime, &userTime)
RESULT bRet
FUNCTION CPU_GetUsages()
idleTime, kernelTime, userTime are FILETIME
usr, ker, idl, sys are 8-byte int
cpu is int = 0
LARGE_INTEGER1 is 8-byte int = 0
LARGE_INTEGER2 is 8-byte int = 0
Transfer(&LARGE_INTEGER1, &gFT.last_kernelTime, 8)
IF LARGE_INTEGER1 THEN
GetSystemTimes(idleTime, kernelTime, userTime)
Transfer(&LARGE_INTEGER1, &userTime, 8); Transfer(&LARGE_INTEGER2, &gFT.last_userTime, 8); usr = LARGE_INTEGER1 - LARGE_INTEGER2
Transfer(&LARGE_INTEGER1, &kernelTime, 8); Transfer(&LARGE_INTEGER2, &gFT.last_kernelTime, 8); ker = LARGE_INTEGER1 - LARGE_INTEGER2
Transfer(&LARGE_INTEGER1, &idleTime, 8); Transfer(&LARGE_INTEGER2, &gFT.last_idleTime, 8); idl = LARGE_INTEGER1 - LARGE_INTEGER2
sys = ker + usr
IF (sys) cpu = (sys - idl) * 100 / sys
END
GetSystemTimes(gFT.last_idleTime, gFT.last_kernelTime, gFT.last_userTime)
RESULT cpu
|
Partager