I saw this question frequently in the Ask section, and I also produced one solution myself using WMI COM.
As I saw the question again, I became curious. Really there have been no other answers about this basic question?
So, I finally searched the forum, and on the contrary found many useful solutions.
IMO, however, they appear rather complicated than really is. So, I wrote it again myself. I wish it could be of help to some users.
DOWNLOAD CPUTimes.ahk.
CPU LoadTimes
Started by
Sean
, May 04 2007 03:27 PM
30 replies to this topic
#1
-
Posted 04 May 2007 - 03:27 PM
I already said that I saw it.Well, there is Laszlo's version long time ago...
BTW, 64bit integer wasn't supported at that time?
#3
-
Posted 04 May 2007 - 04:15 PM
Thx for the functions. They are indeed much more usable then those that were already made, plus we got nice func for single process.
#4
-
Posted 04 May 2007 - 05:18 PM
Very nice! Thanks Sean.
GetSystemTimes() will not work with Win2K ?
GetSystemTimes() will not work with Win2K ?
#6
-
Posted 04 May 2007 - 08:18 PM
GetProcessTimes is nice! Thanks, Sean! I added it to my script collection.
I use now a simple hotkey (Win-P), which pops up the tooltip with the processor load of the *active* window and the system load. Subsequent hotkey presses toggle this tooltip on/off.
I never updated the system load function I posted long-long ago, but below is a modernized version. It gives the same result as your GetSystemTimes(), so chose which one you like.
I use now a simple hotkey (Win-P), which pops up the tooltip with the processor load of the *active* window and the system load. Subsequent hotkey presses toggle this tooltip on/off.
I never updated the system load function I posted long-long ago, but below is a modernized version. It gives the same result as your GetSystemTimes(), so chose which one you like.
#Persistent CoordMode ToolTip SetFormat Float, 6.2 #p:: If (pid) { pid = SetTimer CPUTimes, OFF DllCall("CloseHandle", Uint,hProc) ToolTip } Else { WinGet pid, PID, A hProc := DllCall("OpenProcess", Uint,0x400, Int,0, Uint,pid) SetTimer CPUTimes, 1000 } Return CPUTimes: ToolTip % GetSystemTimes() . "%`n" . GetProcessTimes(hProc) . "% ", 0, 0 Return GetProcessTimes(hProc) { ; Individual CPU Load of the process with pid Static oldKrnlTime, oldUserTime, newKrnlTime, newUserTime oldKrnlTime := newKrnlTime, oldUserTime := newUserTime DllCall("GetProcessTimes", Uint,hProc, Int64P,CreationTime, Int64P,ExitTime, Int64P,newKrnlTime, Int64P,newUserTime) Return (newKrnlTime-oldKrnlTime + newUserTime-oldUserTime)*1.e-5 } GetSystemTimes() { ; Total CPU Load Static IdleTime, IdleTime0, Tick, Tick0 IdleTime0 := IdleTime, Tick0 := Tick DllCall("GetSystemTimes", UInt64P,IdleTime, Int,0, Int,0) Return 100 - .01*(IdleTime0 - IdleTime)/(Tick0 - Tick:=A_TickCount) }
#7
-
Posted 04 May 2007 - 10:32 PM
Oh, sorry. GetSystemTimes is a pretty recent function.GetSystemTimes() will not work with Win2K ?
According to the documentation, it requires at least XP SP1.
The best solution in those OS < XPSP1 might be to retrieve the performance data through HKEY_PERFORMANCE_DATA registry, assuming WMI doesn't provide one either. However, AHK seems to not support this key, which is understandable as this key is not really a registry key. Anyway, it can be done by invoking RegQueryValueEx API so this shouldn't be a problem.
PS. I've never actually tried to obtain the performance data through this method, so I don't know what data should be retrieved yet, either.
PSPS. I forgot mentioning about another useful function, NtQuerySystemInformation.
However, I'm rather reluctant about using it as it's an undocumented function (:seems that it]s now got some documentations).
#8
-
Posted 04 May 2007 - 10:36 PM
Thanks for the update. I hope other authors also update their scripts, so as to have various alternatives.I never updated the system load function I posted long-long ago, but below is a modernized version.
#9
-
Posted 04 May 2007 - 10:44 PM
I added NtQuerySystemInformation() function, which can be used instead of GetSystemTimes().Oh, sorry. GetSystemTimes is a pretty recent function.GetSystemTimes() will not work with Win2K ?
According to the documentation, it requires at least XP SP1.
I hope it works for you.
#10
-
Posted 05 May 2007 - 12:27 AM
I added NtQuerySystemInformation() function, which can be used instead of GetSystemTimes().
I hope it works for you.
Thanks Sean, but NtQuerySystemInformation() does not seem to work in Win2K SP4 :roll:
#11
-
Posted 05 May 2007 - 07:11 AM
Looks like SystemProcessorPerformanceInformation is also a new feature.but NtQuerySystemInformation() does not seem to work in Win2K SP4 :roll:
Then, I'm afraid we have to rely a bit on the undocumented property.
I updated the script adding GetIdleTimes(). You may try it instead of GetSystemTimes().
#12
-
Posted 05 May 2007 - 09:39 AM
I updated the script adding GetIdleTimes().
Yes! That is the One
That works fine for me in Win2K SP4 as well as WinXP SP2
Thank you very much Sean !!!
#13
-
Posted 05 May 2007 - 10:28 AM
I updated the script adding GetIdleTimes()
Can you update it again to use NumGet() ... Please!
#14
-
Posted 17 August 2007 - 11:11 AM