Spacetech Posted May 8, 2008 Share Posted May 8, 2008 I have this function and the cpu usage always comes out to 0 even when the process is at like 10+Here is the code (UpdateCPUToolTip() just updates the tray icons tooltip):Most of it is from hereexpandcollapse popupFunc UpdateCPU() Local $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") $CPU = "ERROR" If(@error) Then UpdateCPUToolTip() Return EndIf $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfRawData_PerfProc_Process WHERE IDProcess = '" & $PID & "'") For $objItem In $colItems $iT1 = $objItem.TimeStamp_Sys100NS $iP1 = $objItem.PercentProcessorTime If($objItem = "") Then UpdateCPUToolTip() Return EndIf Sleep(300) Next $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfRawData_PerfProc_Process WHERE IDProcess = '" & $PID & "'") For $objItem In $colItems $iP2 = $objItem.PercentProcessorTime $iT2 = $objItem.TimeStamp_Sys100NS Next If($objItem = "") Then UpdateCPUToolTip() Return EndIf $iPP = ($iP2 - $iP1) $iTT = ($iT2 - $iT1) If($iTT = 0) Then $CPU = 100 Else $CPU = round(($iPP/$iTT) * 100, 0) EndIf UpdateCPUToolTip() EndFuncIs there anything wrong with this code? Link to comment Share on other sites More sharing options...
weaponx Posted May 8, 2008 Share Posted May 8, 2008 I would take some tips from this ProcessListProperties function:http://www.autoitscript.com/forum/index.php?showtopic=70538 Link to comment Share on other sites More sharing options...
Spacetech Posted May 8, 2008 Author Share Posted May 8, 2008 I would take some tips from this ProcessListProperties function:http://www.autoitscript.com/forum/index.php?showtopic=70538I tried that before but the PercentProcessorTime usually returns a really big number. Link to comment Share on other sites More sharing options...
Spacetech Posted May 8, 2008 Author Share Posted May 8, 2008 So does anyone know this? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 8, 2008 Moderators Share Posted May 8, 2008 http://www.autoitscript.com/forum/index.ph...st&p=198122 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Spacetech Posted May 9, 2008 Author Share Posted May 9, 2008 (edited) http://www.autoitscript.com/forum/index.ph...st&p=198122It seems to only return 0 and 100 I'm using $colItems = "" $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfProc_Process WHERE IDProcess = '" & $PID & "'", "WQL", 0x30) If(IsObj($colItems)) Then For $objItem In $colItems $CPU = $objItem.PercentProcessorTime MsgBox(64, "$CPU", $CPU) Next EndIf Edited May 9, 2008 by Spacetech Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 9, 2008 Moderators Share Posted May 9, 2008 It seems to only return 0 and 100 I'm using $colItems = "" $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfProc_Process WHERE IDProcess = '" & $PID & "'", "WQL", 0x30) If(IsObj($colItems)) Then For $objItem In $colItems $CPU = $objItem.PercentProcessorTime MsgBox(64, "$CPU", $CPU) Next EndIfWhy not just run the example as it is written, I can already tell just from looking at this snippet you are missing at least one value. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
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