#SingleInstance Force
proc = procexp64.exe ; Change to whatever process you want to check
SplashTextOn, 300, 100, Working, `nPlease wait....
Process, Exist, %proc%
pid := ErrorLevel, load := [], n := 0
Loop {
If (load[Mod(++n, 4) + 1] := getProcessTimes(pid)) = -2 {
SplashTextOff
MsgBox, 48, Error, Process was not found. Aborting.`n`n%proc%
ExitApp
If (n = 4)
SplashTextOff
If !Mod(n, 4)
ToolTip, % Format("{:0.2f}%", (load.1 + load.2 + load.3 + load.4) / 4)
Sleep, 350
Return
getProcessTimes(PID) {
; RHCP https://autohotkey.com/board/topic/113942-solved-get-cpu-usage-in/
; Return values
; -1 on first run
; -2 if process doesn't exist or you don't have access to it
; Process cpu usage as percent of total CPU
; https://www.autohotkey.com/boards/viewtopic.php?f=76&t=73498
static aPIDs := [], hasSetDebug
; If called too frequently, will get mostly 0%, so it's better to just return the previous usage
if aPIDs.HasKey(PID) && A_TickCount - aPIDs[PID, "tickPrior"] < 250
return aPIDs[PID, "usagePrior"]
; Open a handle with PROCESS_QUERY_LIMITED_INFORMATION access
if !hProc := DllCall("OpenProcess", "UInt", 0x1000, "Int", 0, "Ptr", pid, "Ptr")
return -2, aPIDs.HasKey(PID) ? aPIDs.Remove(PID, "") : "" ; Process doesn't exist anymore or don't have access to it.
DllCall("GetProcessTimes", "Ptr", hProc, "Int64*", lpCreationTime, "Int64*", lpExitTime, "Int64*", lpKernelTimeProcess, "Int64*", lpUserTimeProcess)
DllCall("CloseHandle", "Ptr", hProc)
DllCall("GetSystemTimes", "Int64*", lpIdleTimeSystem, "Int64*", lpKernelTimeSystem, "Int64*", lpUserTimeSystem)
if aPIDs.HasKey(PID) ; check if previously run
; find the total system run time delta between the two calls
systemKernelDelta := lpKernelTimeSystem - aPIDs[PID, "lpKernelTimeSystem"] ;lpKernelTimeSystemOld
systemUserDelta := lpUserTimeSystem - aPIDs[PID, "lpUserTimeSystem"] ; lpUserTimeSystemOld
; get the total process run time delta between the two calls
procKernalDelta := lpKernelTimeProcess - aPIDs[PID, "lpKernelTimeProcess"] ; lpKernelTimeProcessOld
procUserDelta := lpUserTimeProcess - aPIDs[PID, "lpUserTimeProcess"] ;lpUserTimeProcessOld
; sum the kernal + user time
totalSystem := systemKernelDelta + systemUserDelta
totalProcess := procKernalDelta + procUserDelta
; The result is simply the process delta run time as a percent of system delta run time
result := 100 * totalProcess / totalSystem
else result := -1
aPIDs[PID, "lpKernelTimeSystem"] := lpKernelTimeSystem
aPIDs[PID, "lpKernelTimeSystem"] := lpKernelTimeSystem
aPIDs[PID, "lpUserTimeSystem"] := lpUserTimeSystem
aPIDs[PID, "lpKernelTimeProcess"] := lpKernelTimeProcess
aPIDs[PID, "lpUserTimeProcess"] := lpUserTimeProcess
aPIDs[PID, "tickPrior"] := A_TickCount
return aPIDs[PID, "usagePrior"] := result
getProcessTimes(Process) {
; RHCP https://autohotkey.com/board/topic/113942-solved-get-cpu-usage-in/
; Return values
; -1 on first run
; -2 if process doesn't exist or you don't have access to it
; Process cpu usage as percent of total CPU
; https://www.autohotkey.com/boards/viewtopic.php?f=76&t=73498&p=317460&hilit=cpu+process+load#p317460
Process, Exist, %Process%
PID := ErrorLevel
If (PID == 0)
Return 0
static aPIDs := [], hasSetDebug
; If called too frequently, will get mostly 0%, so it's better to just return the previous usage
if aPIDs.HasKey(PID) && A_TickCount - aPIDs[PID, "tickPrior"] < 250
return aPIDs[PID, "usagePrior"]
; Open a handle with PROCESS_QUERY_LIMITED_INFORMATION access
if !hProc := DllCall("OpenProcess", "UInt", 0x1000, "Int", 0, "Ptr", pid, "Ptr")
return -2, aPIDs.HasKey(PID) ? aPIDs.Remove(PID, "") : "" ; Process doesn't exist anymore or don't have access to it.
DllCall("GetProcessTimes", "Ptr", hProc, "Int64*", lpCreationTime, "Int64*", lpExitTime, "Int64*", lpKernelTimeProcess, "Int64*", lpUserTimeProcess)
DllCall("CloseHandle", "Ptr", hProc)
DllCall("GetSystemTimes", "Int64*", lpIdleTimeSystem, "Int64*", lpKernelTimeSystem, "Int64*", lpUserTimeSystem)
if aPIDs.HasKey(PID) ; check if previously run
; find the total system run time delta between the two calls
systemKernelDelta := lpKernelTimeSystem - aPIDs[PID, "lpKernelTimeSystem"] ;lpKernelTimeSystemOld
systemUserDelta := lpUserTimeSystem - aPIDs[PID, "lpUserTimeSystem"] ; lpUserTimeSystemOld
; get the total process run time delta between the two calls
procKernalDelta := lpKernelTimeProcess - aPIDs[PID, "lpKernelTimeProcess"] ; lpKernelTimeProcessOld
procUserDelta := lpUserTimeProcess - aPIDs[PID, "lpUserTimeProcess"] ;lpUserTimeProcessOld
; sum the kernal + user time
totalSystem := systemKernelDelta + systemUserDelta
totalProcess := procKernalDelta + procUserDelta
; The result is simply the process delta run time as a percent of system delta run time
result := 100 * totalProcess / totalSystem
else result := -1
aPIDs[PID, "lpKernelTimeSystem"] := lpKernelTimeSystem
aPIDs[PID, "lpKernelTimeSystem"] := lpKernelTimeSystem
aPIDs[PID, "lpUserTimeSystem"] := lpUserTimeSystem
aPIDs[PID, "lpKernelTimeProcess"] := lpKernelTimeProcess
aPIDs[PID, "lpUserTimeProcess"] := lpUserTimeProcess
aPIDs[PID, "tickPrior"] := A_TickCount
return aPIDs[PID, "usagePrior"] := result