Polyphem Posted March 22, 2007 Share Posted March 22, 2007 (edited) Good Evening Geeks , Gents and Ladys , I searched the forum about acquiring CPU usage and stumbled over WMI. So, the script below does exactly what I want it to... but... its performance is really bad. As I read, and guess, this might be inherent to the WMI service. Can anybody point me to another source / another method for the LoadPercentage info? What's important is, that I want the info per Core, found some methods (Statusbar of Taskmanager) to get the overall usage, but not per core. Read something about a Statistic in the Registry, but that entry does not seem to exist in XP (my current OS). expandcollapse popup; ============================================================================ ; Program Name: CPU Meter ; Version: V0.1 ; AutoIt Version : v3.2.2.0 ; Author : Polyphem ; Description: ; ; Usage Monitor for a Multi-Core CPUs, using the WMI Service to retrieve the actual workload / utilization (similar to the Windows TaskManager) ; Should work on any system, just showing the actual processors / cores (hyperthreading?) present ; ; Currently it supports 4 processors... now guess which processor I have :).... ; ; ============================================================================ ; ============================================================================ ; Declare includes, opts and local/global variables ; ============================================================================ #include <GUIConstants.au3> Opt("GUIOnEventMode", 1) Local $CenterWidth = (@DesktopWidth - 200) / 2 Local $CenterHeight = (@DesktopHeight - 300) / 2 $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") ; ============================================================================ ; GUI Definition ; ============================================================================ $gui = GUICreate("CPU Meter",200,300,$CenterWidth, $CenterHeight,-1,$WS_EX_TOPMOST) GUISetOnEvent(-3, "_Exit_Event", $gui) GUISetIcon (@SystemDir & "\shell32.dll",12) GUICtrlCreateLabel ("CPU1",5,3,40,20,$SS_CENTER) $progressbar_core1 = GUICtrlCreateProgress (10,20,30,250,$PBS_VERTICAL) $label_core1 = GUICtrlCreateLabel ("",10,275,30,20,$SS_CENTER) GUICtrlCreateLabel ("CPU2",55,3,40,20,$SS_CENTER) $progressbar_core2 = GUICtrlCreateProgress (60,20,30,250,$PBS_VERTICAL) $label_core2 = GUICtrlCreateLabel ("",60,275,30,20,$SS_CENTER) GUICtrlCreateLabel ("CPU3",105,3,40,20,$SS_CENTER) $progressbar_core3 = GUICtrlCreateProgress (110,20,30,250,$PBS_VERTICAL) $label_core3 = GUICtrlCreateLabel ("",110,275,30,20,$SS_CENTER) GUICtrlCreateLabel ("CPU4",155,3,40,20,$SS_CENTER) $progressbar_core4 = GUICtrlCreateProgress (160,20,30,250,$PBS_VERTICAL) $label_core4 = GUICtrlCreateLabel ("",160,275,30,20,$SS_CENTER) GUISetState () ; ============================================================================ ; Main Loop ; ============================================================================ While 1 $colItems = $objWMIService.ExecQuery("SELECT LoadPercentage FROM Win32_Processor", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then $i = 0 For $objItem In $colItems if $i = 0 Then GUICtrlSetData ($progressbar_core1,$objItem.LoadPercentage) GUICtrlSetData ($label_core1,$objItem.LoadPercentage & "%") ElseIf $i = 1 Then GUICtrlSetData ($progressbar_core2,$objItem.LoadPercentage) GUICtrlSetData ($label_core2,$objItem.LoadPercentage & "%") ElseIf $i = 2 Then GUICtrlSetData ($progressbar_core3,$objItem.LoadPercentage) GUICtrlSetData ($label_core3,$objItem.LoadPercentage & "%") ElseIf $i = 3 Then GUICtrlSetData ($progressbar_core4,$objItem.LoadPercentage) GUICtrlSetData ($label_core4,$objItem.LoadPercentage & "%") EndIf $i += 1 Next Else MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "Win32_Processor") EndIf WEnd ; ============================================================================ ; Functions ; ============================================================================ Func _Exit_Event() Exit EndFunc I would be happy, if someone can point me to a method offering a better performance. Regards Polyphem P.S.: The AUTOIT Tag seems to be a bit lazy, parsing the smily, hu ? Edit: Code cleanup. Edited March 22, 2007 by Polyphem This post will be edited again by Polyphem: Tomorrow, 11:55 AM Link to comment Share on other sites More sharing options...
ptrex Posted March 24, 2007 Share Posted March 24, 2007 @Polyphem If you want to monitor something using WMI you best use the native monitor functions of WMI. See my signature for File Monitor or USB monitor. regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
jvanegmond Posted March 24, 2007 Share Posted March 24, 2007 Wow.. 4 cores http://www.tomshardware.com/2006/07/10/pro...keifer_32_core/ github.com/jvanegmond Link to comment Share on other sites More sharing options...
weaponx Posted November 26, 2007 Share Posted November 26, 2007 If you want better performance you should put a Sleep(10) in your while loop. The WMI query probably takes quite some time to process, so you use TimerInit() and TimerDiff() to benchmark how long it takes the query to return. Based on the result of the benchmark you should make the sleep at or above that. Link to comment Share on other sites More sharing options...
Achilles Posted November 27, 2007 Share Posted November 27, 2007 Not sure if I missed something but it's giving recordings for two CPU's and I only have a single core processor that's 3.0 GHz. My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
weaponx Posted November 27, 2007 Share Posted November 27, 2007 Not sure if I missed something but it's giving recordings for two CPU's and I only have a single core processor that's 3.0 GHz.Do you have hyperthreading enabled? If so, it's considered as 2 cpus. Link to comment Share on other sites More sharing options...
mrpq Posted November 27, 2007 Share Posted November 27, 2007 It only shows one CPU value. I've got two CPU's. Gr. Link to comment Share on other sites More sharing options...
weaponx Posted November 27, 2007 Share Posted November 27, 2007 It only shows one CPU value. I've got two CPU's. Gr.What do you mean? It draws 4 meters regardless of how many processors you have. Are you saying its only showing activity on one of them? Link to comment Share on other sites More sharing options...
mrpq Posted November 28, 2007 Share Posted November 28, 2007 It draw four meters, but only one is showing activity. I checked the activity in the taskmanager and there is activity on the two CPU's 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