Jump to content

Search the Community

Showing results for tags 'cpu usage'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 9 results

  1. PDH Performance Counters Measure Process, CPU, Network, Process, Disk (etc) Usage (note that the above dialog appears differently on Vista+) New ObjectBase interface!! *x64 and Localization Issues have been resolved!* *Download and License agreement are at the bottom of this post! About The Project: Performance Counters gather all kind of performance data about the PC and the Network using the standard PDH.DLL module (standard since Windows 2000). Among the performance data you can collect and monitor are: Processor Stats (including total usage)Process (programs) Stats (including CPU usage)Disk Stats (speed/access)TCP, UDP, IP Connection Counts, Speed/Error StatsNetwork Stats..and so onNote that one example is a WIP. 'TaskManager' mockup UDF, I'm looking at you. You can jump right in, download the two AutoIT files (below) and run one of the following to see what the PDH Performance Counters project can get you: TestPDH_PerformanceCounters - this is where you should start! It allows you to visually experiment with most all of the Counters available on your PC and Network. NOTES: - Currently the 'Refresh' rate is set to 1/2 second - this can be changed by altering the Adlib() function frequency - New Counters that come into existence during monitoring will *not* be added to the list (this would be a function I've yet to add) - Counters that become invalid are simply given a prefix of '[Dead Counter Handle]:' TestPDH_ProcessLoop - this basically repeatedly shows an extended Process-information list for all processes. NOTE: You must hit 'ESC' to exit the loop TestPDH_TaskManager - this gathers and displays most everything you'd see in the Process and Performance sections of Task Manager. NOTES: - The screen does NOT update, and the UDF is a MESS. This is due to a number of reasons - the biggest one being laziness on my behalf. Plus I need to figure out how best to manage ListView changes. - TWO fields need Windows XP+ to display correctly (or a version of psapi.dll that supports 'GetPerformanceInfo'): Commit Charge (Peak) and System Cache TestPDH_ProcessGetRelatives - this shows how the PDH Performance Counters can be used to get 'parent' and 'children' process information. There are more practical means of getting this info of course (a few you'll see in my 'Process Functions' module, but hey - its just yet another example of what can be done.TestPDH_ObjectTests - this is more for reading/understanding the code than anything. It is there to show how the new 'ObjectBase' Interface works to make coding Performance Counters *much* easier.Multipile extra 'TestPDH*' examplesAt its most basic, interacting with Performance Counters is as such: The brand new ObjectBase Interface removes some of the difficulty in interacting with Performance Counters, and works like this: Examples of the new ObjectBase interface: % CPU Usage of a Process % CPU Usage of Multiple Instances of a Process (+monitoring and adjustment based on new/dead Instances) Other Examples: Waiting for Hard Disk activity to Idle for 'x' ms % System CPU Usage (by Processor) Network Usage (bytes sent/received) I've put a LOT of work into this project, and all I ask is that you follow my License Agreement when using the code (very easy, see below). Any feedback is welcome. I apologize for the unpolished GUI interfaces (especially the unfinished one), but I will get to that TaskManager GUI one day, hah. Enough chatter -now go on and experience the awesome power of Performance Counters Download the ZIP Here NOTE: Bundled in the ZIP (and included in the License agreement) are other UDF's I wrote that are necessary to run some of the 'Test' programs:_WinAPI_GetSystemInfo.au3, _WinAPI_GetPerformanceInfo.au3, _WinTimeFunctions.au3, and the unnecessary, but provided for those who are interested in the _WinTimeFunctions 'filetime' usage, program: TestWinTimeFunctions.au3. Ascend4nt's AutoIT Code License agreement: While I provide this source code freely, if you do use the code in your projects, all I ask is that: If you provide source, keep the header as I have put it, OR, if you expand it, then at least acknowledge me as the original author, and any other authors I creditIf the program is released, acknowledge me in your credits (it doesn't have to state which functions came from me, though again if the source is provided - see #1)The source on it's own (as opposed to part of a project) can not be posted unless a link to the page(s) where the code were retrieved from is provided and a message stating that the latest updates will be available on the page(s) linked to.Pieces of the code can however be discussed on the threads where Ascend4nt has posted the code without worrying about further linking.Enjoy!Ascend4nt UPDATES:
  2. I'm building a tool to remotely monitor CPU usage on my server. I have a working tool but I have a few issues I'd like some help with. 1. The app uses more system memory on a continual growth rate... It eventually starts displaying strange artifacts and the background flashes between black and and white behind the GDI+ elements. I determined this couldn't be left to run for any amount of time (greater than 15-20 minutes) - Very frustrating. I suspect it's because it keeps drawing new GDI+ elements to replace the previous cycle ... the $bar1 = "" is enough to remove the image and allow the new image to be drawn there, but I don't have a handle for the original GDI+ element to throw it away... Not sure where they go... I also suspect there could be a better way to do what I'm doing here, but from a problem solving perspective - this is what I came up with - I will accept suggestions for how better to accomplish the same / better or acceptable results I will not however accept corrections on grammar, punctuation or commenting - I didn't comment this as I was going, I use the variables that make sense to me (or as they were when I lifted them from the scraps I found on the internet) and you can never be too careful with punctuation. 2. I have a WMI query that is used to remotely pull the CPU data from the server - if I supply the wrong credentials the app crashes... I tried to make it show an error and go back to allow me to try again ... doesn't work. Any help with catching that error and preventing the crash would be super helpful. (works great if the credentials are correct; domain or local) The whole thing below... #include <Date.au3> #include <WindowsConstants.au3> #include <GuiConstantsEX.au3> #include <EditConstants.au3> #include <ButtonConstants.au3> #include <GDIPlus.au3> Global $__g_hGDIPDll Global $graph[21] Global $timer, $timeout = 500 Global $hFlag = 0 $timer = TimerInit() $main = GUICreate("CPU Graph", 125, 220, Default, Default, Default, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) $bar1 = GUICtrlCreatePic("", 10, 10, 5, 100) $bar2 = GUICtrlCreatePic("", 15, 10, 5, 100) $bar3 = GUICtrlCreatePic("", 20, 10, 5, 100) $bar4 = GUICtrlCreatePic("", 25, 10, 5, 100) $bar5 = GUICtrlCreatePic("", 30, 10, 5, 100) $bar6 = GUICtrlCreatePic("", 35, 10, 5, 100) $bar7 = GUICtrlCreatePic("", 40, 10, 5, 100) $bar8 = GUICtrlCreatePic("", 45, 10, 5, 100) $bar9 = GUICtrlCreatePic("", 50, 10, 5, 100) $bar10 = GUICtrlCreatePic("", 55, 10, 5, 100) $bar11 = GUICtrlCreatePic("", 60, 10, 5, 100) $bar12 = GUICtrlCreatePic("", 65, 10, 5, 100) $bar13 = GUICtrlCreatePic("", 70, 10, 5, 100) $bar14 = GUICtrlCreatePic("", 75, 10, 5, 100) $bar15 = GUICtrlCreatePic("", 80, 10, 5, 100) $bar16 = GUICtrlCreatePic("", 85, 10, 5, 100) $bar17 = GUICtrlCreatePic("", 90, 10, 5, 100) $bar18 = GUICtrlCreatePic("", 95, 10, 5, 100) $bar19 = GUICtrlCreatePic("", 100, 10, 5, 100) $bar20 = GUICtrlCreatePic("", 105, 10, 5, 100) $host = GUICtrlCreateInput("Host", 10, 115, 100, 20, $ES_AUTOHSCROLL) $user = GUICtrlCreateInput("User", 10, 140, 100, 20, $ES_AUTOHSCROLL) GUICtrlSetFont(-1, 8, 400) $pass = GUICtrlCreateInput("Pass", 10, 165, 100, 20, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL)) GUICtrlSetFont(-1, 8, 400) $start = GUICtrlCreateButton("Start", 10, 190, 100, 20, $BS_DEFPUSHBUTTON) GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop If $msg = $start Then ConnectWMI() If $hFlag = 1 Then If TimerDiff($timer) > $timeout Then UpdateGraph() EndIf WEnd Func ConnectWMI() Global $hostname = GUICtrlRead($host) If Ping($hostname, 2000) = 0 Then Msgbox(0, "Error", "Unable to reach specified host") Return 0 EndIf Local $usr = GUICtrlRead($user) Local $pwd = GUICtrlRead($pass) Global $objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator") Global $objWMIService = $objSWbemLocator.ConnectServer($hostname, "root\cimv2", $usr, $pwd) If @error Then Msgbox(0, "Error", "Unable to connect to the Host with the supplied credentials") Return 0 EndIf $hFlag = 1 UpdateGraph() EndFunc Func UpdateGraph() $usage = _Processor_Usage() For $i = 1 to 19 $graph[$i] = $graph[$i+1] Next $graph[20] = $usage GUICtrlSetImage($bar1, "") CreateBar($bar1, $graph[1]) GUICtrlSetImage($bar2, "") CreateBar($bar2, $graph[2]) GUICtrlSetImage($bar3, "") CreateBar($bar3, $graph[3]) GUICtrlSetImage($bar4, "") CreateBar($bar4, $graph[4]) GUICtrlSetImage($bar5, "") CreateBar($bar5, $graph[5]) GUICtrlSetImage($bar6, "") CreateBar($bar6, $graph[6]) GUICtrlSetImage($bar7, "") CreateBar($bar7, $graph[7]) GUICtrlSetImage($bar8, "") CreateBar($bar8, $graph[8]) GUICtrlSetImage($bar9, "") CreateBar($bar9, $graph[9]) GUICtrlSetImage($bar10, "") CreateBar($bar10, $graph[10]) GUICtrlSetImage($bar11, "") CreateBar($bar11, $graph[11]) GUICtrlSetImage($bar12, "") CreateBar($bar12, $graph[12]) GUICtrlSetImage($bar13, "") CreateBar($bar13, $graph[13]) GUICtrlSetImage($bar14, "") CreateBar($bar14, $graph[14]) GUICtrlSetImage($bar15, "") CreateBar($bar15, $graph[15]) GUICtrlSetImage($bar16, "") CreateBar($bar16, $graph[16]) GUICtrlSetImage($bar17, "") CreateBar($bar17, $graph[17]) GUICtrlSetImage($bar18, "") CreateBar($bar18, $graph[18]) GUICtrlSetImage($bar19, "") CreateBar($bar19, $graph[19]) GUICtrlSetImage($bar20, "") CreateBar($bar20, $graph[20]) $timer = TimerInit() EndFunc Func _Processor_Usage() Dim $Col_Items = $objWMIService.ExecQuery('SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor', 'WQL') Local $Obj_Item For $Obj_Item In $Col_Items Return $Obj_Item.PercentProcessorTime Next EndFunc Func CreateBar($target, $value) Local $width=5, $height=2 _GDIPlus_Startup() $hImage = DLL_BitmapCreate($width, $height*50) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage) _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2) ;100 If $value > 98 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF00F2F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $width, $height, $hBrush) EndIf ;98 If $value > 96 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF0182C") _GDIPlus_GraphicsFillRect($hGraphic, 0, 2, $width, $height, $hBrush) EndIf ;96 If $value > 94 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF0212A") _GDIPlus_GraphicsFillRect($hGraphic, 0, 4, $width, $height, $hBrush) EndIf ;94 If $value > 92 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF02B28") _GDIPlus_GraphicsFillRect($hGraphic, 0, 6, $width, $height, $hBrush) EndIf ;92 If $value > 90 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF03426") _GDIPlus_GraphicsFillRect($hGraphic, 0, 8, $width, $height, $hBrush) EndIf ;90 If $value > 88 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF03E24") _GDIPlus_GraphicsFillRect($hGraphic, 0, 10, $width, $height, $hBrush) EndIf ;88 If $value > 86 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF04722") _GDIPlus_GraphicsFillRect($hGraphic, 0, 12, $width, $height, $hBrush) EndIf ;86 If $value > 84 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF05120") _GDIPlus_GraphicsFillRect($hGraphic, 0, 14, $width, $height, $hBrush) EndIf ;84 If $value > 82 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF05A1D") _GDIPlus_GraphicsFillRect($hGraphic, 0, 16, $width, $height, $hBrush) EndIf ;82 If $value > 80 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF0641B") _GDIPlus_GraphicsFillRect($hGraphic, 0, 18, $width, $height, $hBrush) EndIf ;80 If $value > 78 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF06D19") _GDIPlus_GraphicsFillRect($hGraphic, 0, 20, $width, $height, $hBrush) EndIf ;78 If $value > 76 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF07717") _GDIPlus_GraphicsFillRect($hGraphic, 0, 22, $width, $height, $hBrush) EndIf ;76 If $value > 74 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF08015") _GDIPlus_GraphicsFillRect($hGraphic, 0, 24, $width, $height, $hBrush) EndIf ;74 If $value > 72 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF08A13") _GDIPlus_GraphicsFillRect($hGraphic, 0, 26, $width, $height, $hBrush) EndIf ;72 If $value > 70 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF09311") _GDIPlus_GraphicsFillRect($hGraphic, 0, 28, $width, $height, $hBrush) EndIf ;70 If $value > 68 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF09311") _GDIPlus_GraphicsFillRect($hGraphic, 0, 30, $width, $height, $hBrush) EndIf ;68 If $value > 66 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF09D0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 32, $width, $height, $hBrush) EndIf ;66 If $value > 64 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFECA20F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 34, $width, $height, $hBrush) EndIf ;64 If $value > 62 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFE8A80F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 36, $width, $height, $hBrush) EndIf ;62 If $value > 60 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFE5AD0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 38, $width, $height, $hBrush) EndIf ;60 If $value > 58 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFE1B30F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 40, $width, $height, $hBrush) EndIf ;58 If $value > 56 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFDEB80F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 42, $width, $height, $hBrush) EndIf ;56 If $value > 54 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFDABE0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 44, $width, $height, $hBrush) EndIf ;54 If $value > 52 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFD6C30F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 46, $width, $height, $hBrush) EndIf ;52 If $value > 50 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFCFCE0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 48, $width, $height, $hBrush) EndIf ;50 If $value > 48 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFCCD40F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 50, $width, $height, $hBrush) EndIf ;48 If $value > 46 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFC8D90F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 52, $width, $height, $hBrush) EndIf ;46 If $value > 44 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFC4DF0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 54, $width, $height, $hBrush) EndIf ;44 If $value > 42 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFC1E40F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 56, $width, $height, $hBrush) EndIf ;42 If $value > 40 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFBDEA0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 58, $width, $height, $hBrush) EndIf ;40 If $value > 38 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFBAF00F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 60, $width, $height, $hBrush) EndIf ;38 If $value > 36 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFBAF00F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 62, $width, $height, $hBrush) EndIf ;36 If $value > 34 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFADEF0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 64, $width, $height, $hBrush) EndIf ;34 If $value > 32 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFA1EE0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 66, $width, $height, $hBrush) EndIf ;32 If $value > 30 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF94ED0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 68, $width, $height, $hBrush) EndIf ;30 If $value > 28 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF88ED0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 70, $width, $height, $hBrush) EndIf ;28 If $value > 26 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF7CEC0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 72, $width, $height, $hBrush) EndIf ;26 If $value > 24 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF6FEB0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 74, $width, $height, $hBrush) EndIf ;24 If $value > 22 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF63EA0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 76, $width, $height, $hBrush) EndIf ;22 If $value > 20 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF56EA0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 78, $width, $height, $hBrush) EndIf ;20 If $value > 18 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF56EA0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 80, $width, $height, $hBrush) EndIf ;18 If $value > 16 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF4AE90F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 82, $width, $height, $hBrush) EndIf ;16 If $value > 14 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF3EE80F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 84, $width, $height, $hBrush) EndIf ;14 If $value > 12 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF31E70F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 86, $width, $height, $hBrush) EndIf ;12 If $value > 10 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF25E70F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 88, $width, $height, $hBrush) EndIf ;10 If $value > 8 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF18E60F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 90, $width, $height, $hBrush) EndIf ;8 If $value > 6 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF0CE50F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 92, $width, $height, $hBrush) EndIf ;6 If $value > 4 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF00E510") _GDIPlus_GraphicsFillRect($hGraphic, 0, 94, $width, $height, $hBrush) EndIf ;4 If $value > 2 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF00E509") _GDIPlus_GraphicsFillRect($hGraphic, 0, 96, $width, $height, $hBrush) EndIf ;2 $hBrush = _GDIPlus_BrushCreateSolid("0xFF00E509") _GDIPlus_GraphicsFillRect($hGraphic, 0, 98, $width, $height, $hBrush) $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) GUICtrlSendMsg($target, 0x172, 0, $hBitmap) _WinAPI_DeleteObject($hBitmap) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() EndFunc ;==>_CreateBar Func DLL_BitmapCreate($width, $height) Local $aResult = DllCall($__g_hGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $width, "int", $height, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0) Return $aResult[6] EndFunc ;==>DLL_BitmapCreate
  3. How do I setup a Hotkey without using so much of the CPU. There must be a better way. A.T. HotKey Patient History.au3
  4. Im looking to measure cpu usage thats free, and measure cpu usage of a program. My goal is to turn intel speed step off under light cpu load. I think I can do that, if I can find the cpu usage.
  5. Hi Everyone, I have been using a script at work for the last 6 months or so. It gets some information from the window title and keeps it in its memory for retrieval. currently I am running an infinite loop to look for the window title, the information in the memory is only updated if a few window title is detected. The trouble with this approach as you can see, is the cpu usage. I was wondering if somehow I can only run this script when a windows change event occurs, otherwise the script stays dormant. I have no idea how to do that, searched on forum and found some solutions that were years old and did not work for me. Thanks
  6. CPU Multi-Processor Usage This is an example of getting and displaying processor usage for all processors in a system. It uses the 'undocumented' NtQuerySystemInformation function to gather processor usage information and then does calculations based on the delta of two readings. I wrote this as an alternative to using my >Performance Counters UDF - specifically, check out >Example # 4: System CPU Usage (by Processor). There is now a new interface, as well as two ways to track CPU usage. The first method tracks usage for all CPU's, and additionally produces an overall CPU usage result. The second method tracks Overall CPU usage - a combined value representing all cores as one unit. Note that this second method uses GetSystemTimes, which requires Windows XP SP1 or higher. The usage works like this for all CPU's: $aCPUsUsageTracker = _CPUsUsageTracker_Create() $iTotalCPUs = $aCPUsUsageTracker[0][0] ; Call the following repeatedly - $aCPUsUsageTracker will be updated automatically: $aPercents = _CPUsUsageTracker_GetUsage($aCPUsUsageTracker) For Overall CPU usage, either look at $aPercents[$iTotalCPUs] above, or use this interface (reliant on GetSystemTimes): $aCPUOverallTracker = _CPUOverallUsageTracker_Create() ; Call the following repeatedly - $aCPUOverallTracker will be updated automatically: $fUsage = _CPUOverallUsageTracker_GetUsage($aCPUOverallTracker) _ Need to see how CPU usage is affected? A simple tool I use to stress-test individual CPU cores is Stress Prime 2004, which can be run multiple times. P.S. All I ask is that you acknowledge me in some way if you use any of this code. updates: 2013-08-31: - Added a simple Overall and Idle CPU usage example 2013-06-18: - Changed interface for getting CPU usage. Now there's no need to juggle arrays around [obsolete version]: - fixed bound check in _CPUCalculateUsages() to look at 2nd dimension CPU_ProcessorUsage.au3 (prev downloads: ~15) ; ======================================================================================================== ; <CPU_ProcessorUsage.au3> ; ; Example of an alternative means to read individual CPU Usages for multiple CPUs, ; along with the combined overall CPU usage. (Alternative to Performance Counters) ; Readings are shown in a 'Splash' window ; ; Functions: ; _CPUGetTotalProcessorTimes() ; Gets Overall (combined CPUs) Processor Times ; _CPUGetIndividualProcessorTimes() ; Returns an array of CPU usage info for individual processors ; _CPUsUsageTracker_Create() ; Creates a CPU usage tracker for all CPUs ; _CPUsUsageTracker_GetUsage() ; Updates CPU usage tracker and returns a CPU usage array ; _CPUOverallUsageTracker_Create() ; Creates a CPU usage tracker for Overall CPU usage ; _CPUOverallUsageTracker_GetUsage(); Updates CPU usage tracker and returns CPU usage [Overall Usage] ; ; See also: ; Performance Counters UDF ; ; ; Author: Ascend4nt ; ======================================================================================================== ; -------------------- HOTKEY FUNCTION & VARIABLE -------------------- Global $bHotKeyPressed=False Func _EscPressed() $bHotKeyPressed=True EndFunc ; ============================================================================================== ; Func _CPUGetTotalProcessorTimes() ; ; Gets the total (combined CPUs) system processor times (as FILETIME) ; Note that Kernel Mode time includes Idle Mode time, so a proper calculation of usage time is ; Kernel + User - Idle ; And percentage (based on two readings): ; (Kernel_b - Kernel_a) + (User_b - User_a) - (Idle_b - Idle_a) * 100 ; / (Kernel_b - Kernal_a) + (User_b - User_a) ; ; O/S Requirements: min. Windows XP SP1+ ; ; Returns: ; Success: Array of info for total (combined CPU's) processor times: ; [0] = Idle Mode Time ; [1] = Kernel Mode Time -> NOTE This INCLUDES Idle Time ; [2] = User Mode Time ; ; Failure: "" with @error set: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: API call returned False - call GetLastError for more info ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUGetTotalProcessorTimes() Local $aRet, $stSystemTimes $stSystemTimes = DllStructCreate("int64 IdleTime;int64 KernelTime;int64 UserTime;") $aRet = DllCall("kernel32.dll", "bool", "GetSystemTimes", "ptr", DllStructGetPtr($stSystemTimes, 1), _ "ptr", DllStructGetPtr($stSystemTimes, 2), "ptr", DllStructGetPtr($stSystemTimes, 3) ) If @error Then Return SetError(2, @error, "") If Not $aRet[0] Then Return SetError(3, 0, "") Dim $aRet[3] = [ _ DllStructGetData($stSystemTimes, 1), _ DllStructGetData($stSystemTimes, 2), _ DllStructGetData($stSystemTimes, 3) ] Return $aRet EndFunc ; ============================================================================================== ; Func _CPUGetIndividualProcessorTimes() ; ; Gets an array of system processor times (as FILETIME) ; Note that Kernel Mode time includes Idle Mode time, so a proper calculation of usage time is ; Kernel + User - Idle ; And percentage (based on two readings): ; (Kernel_b - Kernel_a) + (User_b - User_a) - (Idle_b - Idle_a) * 100 ; / (Kernel_b - Kernal_a) + (User_b - User_a) ; ; Returns: ; Success: 2 Dimensional Array of info [@extended = #of CPU's]: ; [0][0] = # of CPUs (and array elements) ; [1..n][0] = Idle Mode Time for CPU # n ; [1..n][1] = Kernel Mode Time for CPU # n -> NOTE This INCLUDES Idle Time ; [1..n][2] = User Mode Time for CPU # n ; ; Failure: "" with @error set: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: NTSTATUS returned error code, @extended contains error code ; @error = 4: Invalid length returned, @extended is length ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUGetIndividualProcessorTimes() ; DPC = Deferred Procedure Calls Local $tagSYSTEM_PROCESSOR_TIMES = "int64 IdleTime;int64 KernelTime;int64 UserTime;int64 DpcTime;int64 InterruptTime;ulong InterruptCount;" Local $aRet, $stProcessorTimes, $stBuffer Local $i, $nTotalCPUStructs, $pStructPtr ; 256 [maximum CPU's] * 48 (structure size) = 12288 $stBuffer = DllStructCreate("byte Buffer[12288];") ; SystemProcessorTimes = 8 Local $aRet=DllCall("ntdll.dll", "long", "NtQuerySystemInformation", "int", 8, "ptr", DllStructGetPtr($stBuffer), "ulong", 12288, "ulong*", 0) If @error Then Return SetError(2, @error, "") ; NTSTATUS of something OTHER than success? If $aRet[0] Then Return SetError(3, $aRet[0], "") ; Length invalid? If $aRet[4] = 0 Or $aRet[0] > 12288 Or Mod($aRet[4], 48) <> 0 Then Return SetError(4, $aRet[4], "") $nTotalCPUStructs = $aRet[4] / 48 ;~ ConsoleWrite("Returned buffer length = " & $aRet[4] & ", len/48 (struct size) = "& $nTotalCPUStructs & @CRLF) ; We are interested in Idle, Kernel, and User Times (3) Dim $aRet[$nTotalCPUStructs + 1][3] $aRet[0][0] = $nTotalCPUStructs ; Traversal Pointer for individual CPU structs $pStructPtr = DllStructGetPtr($stBuffer) For $i = 1 To $nTotalCPUStructs $stProcessorTimes = DllStructCreate($tagSYSTEM_PROCESSOR_TIMES, $pStructPtr) $aRet[$i][0] = DllStructGetData($stProcessorTimes, "IdleTime") $aRet[$i][1] = DllStructGetData($stProcessorTimes, "KernelTime") $aRet[$i][2] = DllStructGetData($stProcessorTimes, "UserTime") ; Next CPU structure $pStructPtr += 48 Next Return SetExtended($nTotalCPUStructs, $aRet) EndFunc ; ============================================================================================== ; Func _CPUsUsageTracker_Create() ; ; Creates a CPU usage tracker array for all processors. This array should be passed ; to _CPUsUsageTracker_GetUsage() to get current usage information back. ; ; Returns: ; Success: An array used to track CPU usage [@extended = # of CPU's] ; Array 'internal' format: ; $arr[0][0] = # of CPU's ; $arr[1..n][0] = Total CPU Time (Kernel + User Mode) ; $arr[1..n][1] = Total Active CPU Time (Kernel + User - Idle) ; ; Failure: "" with @error set [reflects _CPUGetIndividualProcessorTimes codes]: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: NTSTATUS returned error code, @extended contains error code ; @error = 4: Invalid length returned, @extended is length ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUsUsageTracker_Create() Local $nTotalCPUs, $aCPUTimes, $aCPUsUsage $aCPUTimes = _CPUGetIndividualProcessorTimes() If @error Then Return SetError(@error, @extended, "") $nTotalCPUs = @extended Dim $aCPUsUsage[$nTotalCPUs + 1][2] $aCPUsUsage[0][0] = $nTotalCPUs For $i = 1 To $nTotalCPUs ; Total $aCPUsUsage[$i][0] = $aCPUTimes[$i][1] + $aCPUTimes[$i][2] ; TotalActive (Kernel Time includes Idle time, so we need to subtract that) $aCPUsUsage[$i][1] = $aCPUTimes[$i][1] + $aCPUTimes[$i][2] - $aCPUTimes[$i][0] Next Return SetExtended($nTotalCPUs, $aCPUsUsage) EndFunc ; ============================================================================================== ; Func _CPUOverallUsageTracker_Create() ; ; Creates a CPU usage tracker array for Overall combined processors usage. ; This array should be passed to _CPUOverallUsageTracker_GetUsage() to get ; current usage information. ; ; Returns: ; Success: An array used to track Overall CPU usage ; Array 'internal' format: ; $arr[0] = Total Overall CPU Time (Kernel + User Mode) ; $arr[1] = Total Active Overall CPU Time (Kernel + User - Idle) ; ; Failure: "" with @error set [reflects _CPUGetTotalProcessorTimes codes]: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: API call returned False - call GetLastError for more info ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUOverallUsageTracker_Create() Local $aCPUTimes, $aCPUsUsage[2] $aCPUTimes = _CPUGetTotalProcessorTimes() If @error Then Return SetError(@error, @extended, "") ; Total $aCPUsUsage[0] = $aCPUTimes[1] + $aCPUTimes[2] ; TotalActive (Kernel Time includes Idle time, so we need to subtract that) $aCPUsUsage[1] = $aCPUTimes[1] + $aCPUTimes[2] - $aCPUTimes[0] Return $aCPUsUsage EndFunc ; ============================================================================================== ; Func _CPUsUsageTracker_GetUsage(ByRef $aCPUsUsage) ; ; Updates a CPUsUsage array and returns an array of CPU Usage information for all processors. ; ; Returns: ; Success: Array of CPU Usage -> 1 for each processor + 1 for Overall [@extended = # of processors] ; [0..n] = CPU Usage (Percentage) ; [#CPUs] = CPUs Overall Usage (Percentage) ; Failure: "" with @error set to 1 for invalid parameters, or: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: NTSTATUS returned error code, @extended contains error code ; @error = 4: Invalid length returned, @extended is length ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUsUsageTracker_GetUsage(ByRef $aCPUsUsage) If Not IsArray($aCPUsUsage) Or UBound($aCPUsUsage, 2) < 2 Then Return SetError(1, 0, "") Local $nTotalCPUs, $aUsage, $aCPUsCurInfo Local $nTotalActive, $nTotal Local $nOverallActive, $nOverallTotal $aCPUsCurInfo = _CPUsUsageTracker_Create() If @error Then Return SetError(@error, @extended, "") $nTotalCPUs = $aCPUsCurInfo[0][0] Dim $aUsage[$nTotalCPUs + 1] $nOverallActive = 0 $nOverallTotal = 0 For $i = 1 To $nTotalCPUs $nTotal = $aCPUsCurInfo[$i][0] - $aCPUsUsage[$i][0] $nTotalActive = $aCPUsCurInfo[$i][1] - $aCPUsUsage[$i][1] $aUsage[$i - 1] = Round($nTotalActive * 100 / $nTotal, 1) $nOverallActive += $nTotalActive $nOverallTotal += $nTotal Next $aUsage[$nTotalCPUs] = Round( ($nOverallActive / $nTotalCPUs) * 100 / ($nOverallTotal / $nTotalCPUs), 1) ; Replace current usage tracker info $aCPUsUsage = $aCPUsCurInfo Return SetExtended($nTotalCPUs, $aUsage) EndFunc ; ============================================================================================== ; Func _CPUOverallUsageTracker_GetUsage(ByRef $aCPUsUsage) ; ; Updates a CPUsUsage array and returns CPU Usage information [Overall processor usage] ; ; Returns: ; Success: CPU Usage (Percentage) ; Failure: 0 with @error set to 1 for invalid parameters, or: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: API call returned False - call GetLastError for more info ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUOverallUsageTracker_GetUsage(ByRef $aCPUsUsage) If Not IsArray($aCPUsUsage) Or UBound($aCPUsUsage) < 2 Then Return SetError(1, 0, "") Local $aCPUsCurInfo, $fUsage, $nTotalActive, $nTotal $aCPUsCurInfo = _CPUOverallUsageTracker_Create() If @error Then Return SetError(@error, @extended, 0) $nTotal = $aCPUsCurInfo[0] - $aCPUsUsage[0] $nTotalActive = $aCPUsCurInfo[1] - $aCPUsUsage[1] ; Replace current usage tracker info $aCPUsUsage = $aCPUsCurInfo Return Round($nTotalActive * 100 / $nTotal, 1) EndFunc ; -------------------- MAIN PROGRAM CODE -------------------- HotKeySet("{Esc}", "_EscPressed") Local $hSplash, $sSplashText ; CPU Usage for all CPU's Local $iTotalCPUs, $aCPUsUsageTracker, $aPercents ; Overall CPU Usage Tracker ; (GetSystemTimes) ;~ Local $aCPUOverallTracker ; CPUs Usage Tracker $aCPUsUsageTracker = _CPUsUsageTracker_Create() If @error Then Exit ConsoleWrite("Error calling _CPUsUsageTracker_Create():" & @error & ", @extended = " & @extended & @CRLF) ; Overall CPU Usage tracker ;~ $aCPUOverallTracker = _CPUOverallUsageTracker_Create() ;~ If @error Then Exit ConsoleWrite("Error calling _CPUOverallUsageTracker_Create():" & @error & ", @extended = " & @extended & @CRLF) $iTotalCPUs = $aCPUsUsageTracker[0][0] ConsoleWrite("Total # CPU's: " & $iTotalCPUs & @CRLF) Sleep(250) $hSplash=SplashTextOn("CPU Usage Information [" & $iTotalCPUs & " total CPU's]", "", _ 240, 20 + ($iTotalCPUs + 1) * 35, Default, Default, 16, Default, 12) ; Start loop Do $aPercents = _CPUsUsageTracker_GetUsage($aCPUsUsageTracker) $sSplashText="" For $i=0 To $iTotalCPUs - 1 $sSplashText &= "CPU #"& $i+1 & ": " & $aPercents[$i] & " %" & @CRLF Next $sSplashText &= @CRLF &"[Overall CPU Usage] :" & $aPercents[$iTotalCPUs] & " %" & @CRLF ; Alternative, if all we wanted was Overall CPU Usage: ;~ $sSplashText &= @CRLF &"[Overall CPU Usage] :" & _CPUOverallUsageTracker_GetUsage($aCPUOverallTracker) & " %" & @CRLF $sSplashText &= @CRLF & "[Esc] exits" ControlSetText($hSplash, "", "[CLASS:Static; INSTANCE:1]", $sSplashText) Sleep(500) Until $bHotKeyPressed _ Overall CPU Usage (and Idle calculation) example: ; ======================================================================================================== ; <CPU_ProcessorUsageOverall.au3> ; ; Example of reading combined overall CPU usage and deducing Idle CPU usage as well ; Readings are shown in a 'Splash' window ; ; Functions: ; _CPUGetTotalProcessorTimes() ; Gets Overall (combined CPUs) Processor Times ; _CPUOverallUsageTracker_Create() ; Creates a CPU usage tracker for Overall CPU usage ; _CPUOverallUsageTracker_GetUsage(); Updates CPU usage tracker and returns CPU usage [Overall Usage] ; ; External Functions: ; _CPUGetIndividualProcessorTimes() ; Returns an array of CPU usage info for individual processors ; _CPUsUsageTracker_Create() ; Creates a CPU usage tracker for all CPUs ; _CPUsUsageTracker_GetUsage() ; Updates CPU usage tracker and returns a CPU usage array ; ; See also: ; <CPU_ProcessorUsage.au3> ; Individual CPU processor usage example ; Performance Counters UDF ; ; ; Author: Ascend4nt ; ======================================================================================================== ; --- UDF's --- ; ============================================================================================== ; Func _CPUGetTotalProcessorTimes() ; ; Gets the total (combined CPUs) system processor times (as FILETIME) ; Note that Kernel Mode time includes Idle Mode time, so a proper calculation of usage time is ; Kernel + User - Idle ; And percentage (based on two readings): ; (Kernel_b - Kernel_a) + (User_b - User_a) - (Idle_b - Idle_a) * 100 ; / (Kernel_b - Kernal_a) + (User_b - User_a) ; ; O/S Requirements: min. Windows XP SP1+ ; ; Returns: ; Success: Array of info for total (combined CPU's) processor times: ; [0] = Idle Mode Time ; [1] = Kernel Mode Time -> NOTE This INCLUDES Idle Time ; [2] = User Mode Time ; ; Failure: "" with @error set: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: API call returned False - call GetLastError for more info ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUGetTotalProcessorTimes() Local $aRet, $aTimes $aRet = DllCall("kernel32.dll", "bool", "GetSystemTimes", "uint64*", 0, "uint64*", 0, "uint64*", 0) If @error Then Return SetError(2, @error, "") If Not $aRet[0] Then Return SetError(3, 0, "") Dim $aTimes[3] = [ $aRet[1], $aRet[2], $aRet[3] ] Return $aTimes EndFunc ; ============================================================================================== ; Func _CPUOverallUsageTracker_Create() ; ; Creates a CPU usage tracker array for Overall combined processors usage. ; This array should be passed to _CPUOverallUsageTracker_GetUsage() to get ; current usage information. ; ; Returns: ; Success: An array used to track Overall CPU usage ; Array 'internal' format: ; $arr[0] = Total Overall CPU Time (Kernel + User Mode) ; $arr[1] = Total Active Overall CPU Time (Kernel + User - Idle) ; ; Failure: "" with @error set [reflects _CPUGetTotalProcessorTimes codes]: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: API call returned False - call GetLastError for more info ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUOverallUsageTracker_Create() Local $aCPUTimes, $aCPUsUsage[2] $aCPUTimes = _CPUGetTotalProcessorTimes() If @error Then Return SetError(@error, @extended, "") ; Total $aCPUsUsage[0] = $aCPUTimes[1] + $aCPUTimes[2] ; TotalActive (Kernel Time includes Idle time, so we need to subtract that) $aCPUsUsage[1] = $aCPUTimes[1] + $aCPUTimes[2] - $aCPUTimes[0] Return $aCPUsUsage EndFunc ; ============================================================================================== ; Func _CPUOverallUsageTracker_GetUsage(ByRef $aCPUsUsage) ; ; Updates a CPUsUsage array and returns CPU Usage information [Overall processor usage] ; ; Returns: ; Success: CPU Usage (Percentage) ; Failure: 0 with @error set to 1 for invalid parameters, or: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: API call returned False - call GetLastError for more info ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUOverallUsageTracker_GetUsage(ByRef $aCPUsUsage) If Not IsArray($aCPUsUsage) Or UBound($aCPUsUsage) < 2 Then Return SetError(1, 0, "") Local $aCPUsCurInfo, $fUsage, $nTotalActive, $nTotal $aCPUsCurInfo = _CPUOverallUsageTracker_Create() If @error Then Return SetError(@error, @extended, 0) $nTotal = $aCPUsCurInfo[0] - $aCPUsUsage[0] $nTotalActive = $aCPUsCurInfo[1] - $aCPUsUsage[1] ; Replace current usage tracker info $aCPUsUsage = $aCPUsCurInfo Return Round($nTotalActive * 100 / $nTotal, 1) EndFunc ; -------------------- HOTKEY FUNCTION & VARIABLE -------------------- Global $bHotKeyPressed=False Func _EscPressed() $bHotKeyPressed=True EndFunc ; -------------------- MAIN PROGRAM CODE -------------------- HotKeySet("{Esc}", "_EscPressed") Local $hSplash, $sSplashText ; Overall CPU Usage Tracker ; (GetSystemTimes) Local $aCPUOverallTracker, $fPercent ; Overall CPU Usage tracker $aCPUOverallTracker = _CPUOverallUsageTracker_Create() If @error Then Exit ConsoleWrite("Error calling _CPUOverallUsageTracker_Create():" & @error & ", @extended = " & @extended & @CRLF) Sleep(250) $hSplash=SplashTextOn("CPU [Overall] Usage Information", "", _ 240, 100, Default, Default, 16, Default, 12) ; Start loop Do $fPercent = _CPUOverallUsageTracker_GetUsage($aCPUOverallTracker) $sSplashText="" $sSplashText &= "[Overall CPU Usage] :" & $fPercent & " %" & @CRLF $sSplashText &= "[Idle] : " & (100 - $fPercent) & " %" & @CRLF $sSplashText &= @CRLF & "[Esc] exits" ControlSetText($hSplash, "", "[CLASS:Static; INSTANCE:1]", $sSplashText) Sleep(500) Until $bHotKeyPressed CPU_ProcessorUsageOverall.au3
  7. Hi all this is a part from my script #include <Misc.au3> $dll = DllOpen("user32.dll") While 1 If _IsPressed("31", $dll) Then one() If _IsPressed("32", $dll) Then two() WEnd Func one() MsgBox(0, "", "1") While _IsPressed("31") or _IsPressed("61") Sleep(1) WEnd EndFunc Func two() MsgBox(0,"", "2") While _IsPressed("32") or _IsPressed("62") Sleep(1) WEnd EndFunc it is working fine but it takes 30 % of the CPU usage and it is a small simple script when i put sleep(100) in the while loop the CPU is 1% i think that this is a good solution but not for my case cuz the rest of my script really depends on time and 100 msec will matter can i reduce the CPU usage without using sleep ?
  8. Process CPU Usage Trackers As yet another alternative to the Performance Counters UDF, I've created this UDF to allow easy tracking of one or more processes's CPU usage. While this has obviously been done before, I haven't seen it done the way I've created it. Basically, just as the Performance Counters had Process Counter objects, so this too has Process Usage trackers. They are relatively simple to use, and require very little interaction other than invoking the functions. To create a new tracker object, call one of these: _ProcessUsageTracker_Create() ; Single process tracker _ProcessesUsageTracker_Create() ; Multiple processes tracker The multiple-process tracker requires addition of processes, which can be done one of 2 ways: _ProcessesUsageTracker_Add() ; add a single process _ProcessesUsageTracker_AddMultiple() ; multiple processes in a ProcessList-style array After the usage tracker object has been created, stats can be collected via one of two calls: _ProcessUsageTracker_GetUsage() ; single process - returns a percentage _ProcessesUsageTracker_GetUsage() ; multiple Processes - returns an array of %'s Basically the main loop of the program can be filled with 'GetUsage' calls without juggling anything around. If a process dies out, an @error code will be returned in the single-process version. The multiple-process tracker version however lets you retain dead processes in the list although their process handles will be closed. These can be alternatively cleared up on each call to 'GetUsage' (setting $bRemoveDead to True), or you can opt to clean them up with the following call: _ProcessesUsageTracker_RemoveDead() ; Removes any dead processes from the tracker object Finally, to destroy the trackers and close handles, just call the appropriate function: _ProcessUsageTracker_Destroy() _ProcessesUsageTracker_Destroy() That's about it. More info is in the headers. Here's an example of a single process cpu usage tracker: ; ======================================================================================================== ; <Process_CPUUsageExample.au3> ; ; Example usage of <Process_CPUUsage.au3> ; ; Author: Ascend4nt ; ======================================================================================================== #include "Process_CPUUsage.au3" ; -------------------- HOTKEY FUNCTION & VARIABLE -------------------- Global $bHotKeyPressed=False Func _EscPressed() $bHotKeyPressed=True EndFunc ; -------------------- MAIN PROGRAM CODE -------------------- HotKeySet("{Esc}", "_EscPressed") Local $hSplash, $sSplashText Local $sProcess, $aProcUsage, $fUsage ; Regular Process: ;~ $sProcess = "firefox.exe" ;~ $sProcess = "sp2004.exe" ; Stress Prime 2004 ; Protected Process (opens a different way): ;~ $sProcess = "audiodg.exe" ; Processes Requiring elevated privilege (will fail even with limited access rights): ;~ $sProcess = "CTAudSvc.exe" $sProcess = InputBox("Enter Process Name", "Process Name:", "", "", 320, 140) If @error Or $sProcess = "" Then Exit $aProcUsage = _ProcessUsageTracker_Create($sProcess) If @error Then Exit ConsoleWrite("Error calling _ProcessUsageTracker_Create(): " & @error & ", @extended = " & @extended & @CRLF) Sleep(250) $hSplash=SplashTextOn("Process CPU Usage Information", "", 360, 20 + 60, Default, Default, 16, Default, 12) ; Start loop Do $sSplashText="" $fUsage = _ProcessUsageTracker_GetUsage($aProcUsage) If @error Then ConsoleWrite("Error from _ProcessUsageTracker_GetUsage(): " & @error & ", @extended = " &@extended & @CRLF) ExitLoop EndIf $sSplashText &= "'"&$sProcess&"' CPU usage: " & $fUsage & " %" & @CRLF $sSplashText &= @CRLF & "[Esc] exits" ControlSetText($hSplash, "", "[CLASS:Static; INSTANCE:1]", $sSplashText) Sleep(500) Until $bHotKeyPressed _ProcessUsageTracker_Destroy($aProcUsage) _ Multiple processes example, which is best used with something like 'chrome' which spawns a number of processes with the same name: ; ======================================================================================================== ; <Processes_CPUUsageExample.au3> ; ; Example usage of <Processes_CPUUsage.au3> ; ; Author: Ascend4nt ; ======================================================================================================== #include "Processes_CPUUsage.au3" ; -------------------- HOTKEY FUNCTION & VARIABLE -------------------- Global $bHotKeyPressed=False Func _EscPressed() $bHotKeyPressed=True EndFunc ; -------------------- MAIN PROGRAM CODE -------------------- HotKeySet("{Esc}", "_EscPressed") Local $hSplash, $sSplashText Local $sProcess, $aProcList, $aProcUsage, $aPercents, $nPercents ; Regular Process: ;~ $sProcess = "firefox.exe" ;~ $sProcess = "sp2004.exe" ; Stress Prime 2004 ; Protected Process (opens a different way): ;~ $sProcess = "audiodg.exe" ; Processes Requiring elevated privilege (will fail even with limited access rights): ;~ $sProcess = "CTAudSvc.exe" $sProcess = InputBox("Enter Process Name", "Process Name:", "", "", 320, 140) If @error Or $sProcess = "" Then Exit $aProcUsage = _ProcessesUsageTracker_Create() _ProcessesUsageTracker_Add($aProcUsage, "sp2004.exe") _ProcessesUsageTracker_Add($aProcUsage, "CPUStabTest.exe") $aProcList = ProcessList("chrome.exe") _ProcessesUsageTracker_AddMultiple($aProcUsage, $aProcList) _ProcessesUsageTracker_Add($aProcUsage, $sProcess) _ProcessesUsageTracker_Add($aProcUsage, "audiodg.exe") Sleep(250) $hSplash=SplashTextOn("Process CPU Usage Information", "", 380, 24 + 15*2 + $aProcUsage[0][0]*15, Default, Default, 16+4, "Lucida Console", 11) ; Start loop Do ; DEBUG: Interrupt to allow multiple process termination ;MsgBox(0, "Next usage", "Next usage time..") $sSplashText="" $aPercents = _ProcessesUsageTracker_GetUsage($aProcUsage, True) ; True = Remove dead $nPercents = @extended If @error Then ConsoleWrite("Error from _ProcessesUsageTracker_GetUsage(): " & @error & ", @extended = " &@extended & @CRLF) ExitLoop EndIf For $i = 0 To $nPercents - 1 $sSplashText &= "'"&$aProcUsage[$i+1][0]&"' [PID #"&$aProcUsage[$i+1][1]&"] CPU usage: " & $aPercents[$i] & " %" & @CRLF Next $sSplashText &= @CRLF & "[Esc] exits" ControlSetText($hSplash, "", "[CLASS:Static; INSTANCE:1]", $sSplashText) Sleep(500) Until $bHotKeyPressed _ProcessesUsageTracker_Destroy($aProcUsage) ProcessCPUUsage.zip
  9. AutoIt SysInfo Clock is a small tool in widget style to show the clock, current CPU usage, CPU speed, memory usage and network activity (tcp, ip and udp). Additionally you can use it as an alarm clock. To stop alarm clock tone press the left LED (mail) or wait 60 seconds. The current CPU usage code is beta and might be not working for some CPUs! Main window: Move mouse to area below seconds and press rmb to select different color scheme. Alarm Clock window: Tray menu: Credits: see scroller (select About). Special thanks to trancexx for helping me to read out current CPU speed using the WinAPI stuff, AndyG for troubleshooting performance counter issue, czardas for composing "Für Elise" and Ascend4nt for the support! Download source code + compiled version: Click Me (previous downloads: 1386) (Please don't use any download manager!) Compiled version only: MediaFire.com or 4Shared.com Coded on Win7 x64 using Aero / Win8.1 x64 and AutoIt v3.3.12.0. Br, UEZ This project is discontinued! Change log: v0.9.5.0 build 2013-06-14: initial release v0.9.6.0 build 2013-06-15: added _WinAPI_CreateRoundRectRgn() to fix transparency issue on non Aero desktops, small internal modifications and added check for whether performance counters are enabled v0.9.6.5 build 2013-06-15: fixed a bug when "Reset Windows Position" was selected twice and color of scroller will fit to clock color schema v0.9.8.0 build 2013-06-20: added little music to About part -> many thanks to czardas for mus++ and arranging "Für Elise", added date to clock, replaced CPU usage code -> thanks Ascend4nt v0.9.9.0 build 2013-06-21: added 2 more color schemas (mint and purple), added network traffic LED, compiled exe now included in archive v0.9.9.0 build 2013-06-22: forgot to increase a variable in ini section v0.9.9.0 build 2013-06-24: found also missing modification in context menue after adding two more color schemas v0.9.9.0 build 2013-06-26: Ops, forgot to change also radio item proper check in clock color schema sub menu v0.9.9.1 build 2013-06-27: added option to select whether SysInfo Clock should start at windows startup v0.9.9.2 build 2013-07-01: added yellow-red mark to the small info indicators and additional info when hovering about the small indicators, small internal changes v0.9.9.5 build 2013-07-05: added features: singleton, update check, visit web site, bring GUI to front and fixed some smaller bugs + some internal changes v0.9.9.6 build 2013-07-11: added alarm clock feature v0.9.9.7 build 2014-06-23: adapted code to run on AutoIt version 3.3.12.0 v0.9.9.7 build 2014-08-27: some internal "cosmetic" changes -> this project is discontinued!
×
×
  • Create New...