When using the above I got occasional negative values. Found it was due to the idle time value rolling over (only the PCU percentage was checked not the Process Percentage). Also sometimes it would have no time elapse between measurements (Some OS caching the function call?) which resulted in incorrect 0% CPU time for the measured Process.
Here is the error checking:
Func _ProcessCPUExample()
Static Local $aEnd, $aStart = _GetProcessUsage($g_hAutoItProcess)
sleep(2000) ; make sure some time elapses between measurements.
$aEnd = _GetProcessUsage($g_hAutoItProcess)
;Make sure time value did not roll over
while $aEnd[0] <= $aStart[0] or $aEnd[1] <= $aStart[1] or $aEnd[2] <= $aStart[2]
ConsoleWrite('ReTrying'&@CRLF)
$aStart = _GetProcessUsage($g_hAutoItProcess)
sleep(2000)
$aEnd = _GetProcessUsage($g_hAutoItProcess)
WEnd
;Get both total and process cpu usage
Local $aCPU = _CalcUsage($aStart, $aEnd)
ConsoleWrite('Total CPU Usage = ' & $aCPU[0] & '%' & @TAB & @TAB & 'AutoIt CPU Usage = ' & $aCPU[1] & '%' & @LF)
;copy last cpu times to start.
$aStart = $aEnd
EndFunc ;==>_GetProcessCPU