TheBrainiac Posted May 17, 2015 Posted May 17, 2015 (edited) I'm using WMI to poll my system's CPU load:$objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2") $cpu = 0 While 1 $init = TimerInit() $colItems = $objWMIService.ExecQuery("SELECT LoadPercentage FROM Win32_Processor", "WQL", 0x30) For $objItem In $colItems $cpu = $objItem.LoadPercentage Next ConsoleWrite($cpu & "%" & @CRLF) ConsoleWrite(TimerDiff($init) & @CRLF) WEnd The For-loop in this example suspiciously always takes exactly one second (1008-1012ms) to finish, while not consuming large amounts of CPU time. Using debug lines, I have also confirmed that $colItems contains just one element. In fact it is For $objItem In $colItems that's taking this one second.I understand there will be some conversion from the WMI return value to actual usable data, but it looks very much like there is either a delay or a timeout of some sort going on. Has anyone had similar issues? Have you found a way to get rid of it? If not, is there a similarly easy way to get CPU load without WMI?Thanks for your feedback. Edited May 17, 2015 by TheBrainiac
mikell Posted May 17, 2015 Posted May 17, 2015 Seems to be a common issue as mentioned herehttp://stackoverflow.com/questions/5465653/wmi-loadpercentage-call-is-very-slowLoadPercentage : Load capacity of each processor, averaged to the last second. (msdn)
TheBrainiac Posted May 17, 2015 Author Posted May 17, 2015 Ah, so it starts measuring CPU load and waits a second to get an average value. That explains the one second delay. Now this makes me wonder why it seemed to run fine in the past.Thank you!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now