Hi,
is it possible to create a function that sleep/wait until CPU usage is under 10%?
Waiting for CPU usage?
Re: Waiting for CPU usage?
Code: Select all
#SingleInstance Force
Process, Priority,, B
While ((9 < cpu := CPULoad()) || !cpu) {
ToolTip, %cpu%
Sleep, 1000
}
ToolTip
MsgBox, 64, CPU load, %cpu%`%
CPULoad() { ; CPULoad() by SKAN
; https://github.com/jNizM/SysMeter/blob/master/src/SysMeter.ahk#L335
Static PIT, PKT, PUT
If (PIT = "")
Return 0, DllCall("GetSystemTimes", "Int64P", PIT, "Int64P", PKT, "Int64P", PUT)
DllCall("GetSystemTimes", "Int64P", CIT, "Int64P", CKT, "Int64P", CUT)
IdleTime := PIT - CIT, KernelTime := PKT - CKT, UserTime := PUT - CUT
SystemTime := KernelTime + UserTime
Return (SystemTime - IdleTime) * 100 // SystemTime, PIT := CIT, PKT := CKT, PUT := CUT
}
-
- Posts: 6
- Joined: 25 Jun 2022, 02:46
Re: Waiting for CPU usage?
Thx a lot, i will give this a trymikeyww wrote: ↑25 Jun 2022, 05:45Code: Select all
#SingleInstance Force Process, Priority,, B While ((9 < cpu := CPULoad()) || !cpu) { ToolTip, %cpu% Sleep, 1000 } ToolTip MsgBox, 64, CPU load, %cpu%`% CPULoad() { ; CPULoad() by SKAN ; https://github.com/jNizM/SysMeter/blob/master/src/SysMeter.ahk#L335 Static PIT, PKT, PUT If (PIT = "") Return 0, DllCall("GetSystemTimes", "Int64P", PIT, "Int64P", PKT, "Int64P", PUT) DllCall("GetSystemTimes", "Int64P", CIT, "Int64P", CKT, "Int64P", CUT) IdleTime := PIT - CIT, KernelTime := PKT - CKT, UserTime := PUT - CUT SystemTime := KernelTime + UserTime Return (SystemTime - IdleTime) * 100 // SystemTime, PIT := CIT, PKT := CKT, PUT := CUT }