Beege Posted July 19, 2009 Share Posted July 19, 2009 (edited) Here is a example for calculating how much CPU your script is using and total cpu usage. Any Ideas on how to make this a better Adlib would be great.. Thanks for looking! expandcollapse popup#include <WinAPI.au3> #include <array.au3> HotKeySet('{esc}', '_exit') Global $ProcessCpu, $TotalCpu, $nProcessCpu, $StartUser, $StartIdle, $StartKernel, $ProcStartKern, $ProcStartUser, $bFirstRun = True AdlibEnable("_ProcessCalc", 1000) ;A little bit of work to see if its working. Dim $comboarray, $array[6] = [1, 2, 3, 4, 5, 6] $comboarray = _ArrayCombinations($array, 3) SplashTextOn('Splash', 'message') While 1 For $i = 1 To $comboarray[0] ControlSetText("Splash", "", "Static1", $comboarray[$i]) If $nProcessCpu <> $ProcessCpu Then $nProcessCpu = $ProcessCpu ConsoleWrite('Script Cpu Usage = ' & Round($nProcessCpu, 2) & '%' & @CRLF) ConsoleWrite('Total Cpu Usage = ' & Round($TotalCpu, 2) & '%' & @CRLF) EndIf Next WEnd Func _ProcessCalc() Local $tProcess, $tSystem, $tSystemt, $hScripthandle = _WinAPI_GetCurrentProcess() Local $IDLETIME = DllStructCreate($tagFILETIME), $KERNELTIME = DllStructCreate($tagFILETIME), $USERTIME = DllStructCreate($tagFILETIME) Local $PCreationTime = DllStructCreate($tagFILETIME), $PExitTime = DllStructCreate($tagFILETIME), $PKernelTime = DllStructCreate($tagFILETIME), $PUserTime = DllStructCreate($tagFILETIME) DllCall('Kernel32.dll', "int", "GetSystemTimes", "ptr", DllStructGetPtr($IDLETIME), "ptr", DllStructGetPtr($KERNELTIME), "ptr", DllStructGetPtr($USERTIME)) DllCall('Kernel32.dll', "int", "GetProcessTimes", "hwnd", $hScripthandle, "ptr", DllStructGetPtr($PCreationTime), "ptr", DllStructGetPtr($PExitTime), "ptr", DllStructGetPtr($PKernelTime), "ptr", DllStructGetPtr($PUserTime)) If Not $bFirstRun Then $tProcess = (DllStructGetData($PKernelTime, 1) - $ProcStartKern) + (DllStructGetData($PUserTime, 1) - $ProcStartUser) $tSystem = (DllStructGetData($KERNELTIME, 1) - $StartKernel) + (DllStructGetData($USERTIME, 1) - $StartUser) $tSystemt = (($tSystem - (DllStructGetData($IDLETIME, 1) - $StartIdle)) * (100/$tSystem)) EndIf $ProcStartKern = DllStructGetData($PKernelTime, 1) $ProcStartUser = DllStructGetData($PUserTime, 1) $StartIdle = DllStructGetData($IDLETIME, 1) $StartKernel = DllStructGetData($KERNELTIME, 1) $StartUser = DllStructGetData($USERTIME, 1) If $bFirstRun Then $bFirstRun = False $ProcessCpu = ($tProcess / $tSystem) * 100 $TotalCpu = $tSystemt EndFunc ;==>_ProcessCalc Func _exit() Exit EndFunc ;==>_exit Edited July 19, 2009 by bchris01 Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator Link to comment Share on other sites More sharing options...
Ascend4nt Posted July 19, 2009 Share Posted July 19, 2009 Interesting technique. You need a 'sleep' in the main While loop, and you need to consider multiple CPU's and hyperthreading in order to match it up to the results you see in Task Manager. ..Or you could use something like, say, PDH Performance Counters...hehe. Otherwise, its a pretty cool approach.. My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
Beege Posted July 19, 2009 Author Share Posted July 19, 2009 (edited) Interesting technique. You need a 'sleep' in the main While loop, and you need to consider multiple CPU's and hyperthreading in order to match it up to the results you see in Task Manager...Or you could use something like, say, PDH Performance Counters...hehe. Otherwise, its a pretty cool approach..Im not sure what you mean about the sleep. The main While loop is just there to put a load on the cpu (testing Purposes). If I put a sleep in I would have no load and would make it hard to see if its working. And I'm pretty sure I read that the dll calls "Getsystemtimes" and "GetProcessTimes" return total kernel and user times. Not just single processors. I could be wrong though.. Ill look. Thanks for the comments. Edited July 19, 2009 by bchris01 Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator Link to comment Share on other sites More sharing options...
Ascend4nt Posted July 19, 2009 Share Posted July 19, 2009 (edited) Ahh, okay, didn't get the processor load thing. *edit: just tried again, and it's reporting relatively correct %'s. Did you change something? I'm certain I was getting 100% usage the first time I ran this on my Quad core CPU.. odd Edited July 19, 2009 by Ascend4nt My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
Beege Posted July 19, 2009 Author Share Posted July 19, 2009 Lol no I didn't change anything. I've been looking at your PDH Performance Counters udf which is sweet. I can't believe I haven't seen that before! Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator 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