Finding+the+CPU+usage

//by Richard Russell, October 2011//

The code listed below reports, once per second, the current total CPU usage: code format="bb4w" *FLOAT 64 DIM IdleTime{l%,h%}, KernelTime{l%,h%}, UserTime{l%,h%} idletime = 0 kerneltime = 0 usertime = 0 REPEAT WAIT 100 SYS "GetSystemTimes", IdleTime{}, KernelTime{}, UserTime{} oldidletime = idletime oldkerneltime = kerneltime oldusertime = usertime idletime = IdleTime.h% * 2^32 + (IdleTime.l% >>> 1)*2 kerneltime = KernelTime.h% * 2^32 + (KernelTime.l% >>> 1)*2 usertime = UserTime.h% * 2^32 + (UserTime.l% >>> 1)*2 idledelta = idletime-oldidletime kerneldelta = kerneltime-oldkerneltime userdelta = usertime-oldusertime cpuusage = (userdelta+kerneldelta-idledelta)/(userdelta+kerneldelta) PRINT "CPU usage = ";INT(100*cpuusage+0.5) "%" UNTIL FALSE code