red0fireus Posted May 29, 2018 Posted May 29, 2018 Hello, I'm very stumped with finding the decimal place for the CPU %. I found some example code online #include <Array.au3> $aProcess_Info = GetCPU("RzSynapse") _ArrayDisplay($aProcess_Info) Func GetCPU($sProcess = "") Local $aAllProcess_Info[1000][3] = [[0]], $aOneProcess_Info[3] $oWinMgmts = ObjGet("winmgmts:\\.\root\cimv2") $aCPU_Usage = $oWinMgmts.ExecQuery("SELECT Name, IDProcess, PercentProcessorTime FROM Win32_PerfFormattedData_PerfProc_Process") For $vCPU_Info In $aCPU_Usage If $sProcess Then If $vCPU_Info.Name = $sProcess Then $aOneProcess_Info[0] = $sProcess $aOneProcess_Info[1] = $vCPU_Info.IDProcess $aOneProcess_Info[2] = $vCPU_Info.PercentProcessorTime & " %" Return $aOneProcess_Info EndIf Else $aAllProcess_Info[0][0] += 1 $aAllProcess_Info[$aAllProcess_Info[0][0]][0] = $vCPU_Info.Name $aAllProcess_Info[$aAllProcess_Info[0][0]][1] = $vCPU_Info.IDProcess $aAllProcess_Info[$aAllProcess_Info[0][0]][2] = $vCPU_Info.PercentProcessorTime & " %.1f" EndIf Next ReDim $aAllProcess_Info[$aAllProcess_Info[0][0] +1][3] Return $aAllProcess_Info EndFunc ;==>GetCPU Currently the code shows the CPU % as 0 % and I want to show 0.0 % I found this online for strings "%.1f" but i'm not sure how to incorporate it.
TheDcoder Posted May 29, 2018 Posted May 29, 2018 I think you are looking for StringFormat StringFormat EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
red0fireus Posted May 29, 2018 Author Posted May 29, 2018 I do see that but I've been looking through other examples and I can't find any CPU percentages with a decimal. The "PercentProcessorTime" is what returns the number back and I don't think it will work with StringFormat. I could be wrong though PercentProcessorTime
TheDcoder Posted May 29, 2018 Posted May 29, 2018 ; Try this Local $iPercentage = 0 Local $sPercentage = StringFormat('%.1f', $iPercentage) ConsoleWrite($sPercentage & @CRLF) EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
red0fireus Posted May 29, 2018 Author Posted May 29, 2018 (edited) Okay, I got the decimal after the CPU usage to show up but the program is not reading the decimals from the task manager. Its at Example: 11.0 %, 5.0 %, 22.0%. It never reads 5.4% or 12.8% #include <Array.au3> $aProcess_Info = GetCPU("Explorer") _ArrayDisplay($aProcess_Info) Func GetCPU($sProcess = "") Local $aAllProcess_Info[1000][3] = [[0]], $aOneProcess_Info[3] $oWinMgmts = ObjGet("winmgmts:\\.\root\cimv2") $aCPU_Usage = $oWinMgmts.ExecQuery("SELECT Name, IDProcess, PercentProcessorTime FROM Win32_PerfFormattedData_PerfProc_Process") For $vCPU_Info In $aCPU_Usage If $sProcess Then If $vCPU_Info.Name = $sProcess Then $aOneProcess_Info[0] = $sProcess $aOneProcess_Info[1] = $vCPU_Info.IDProcess $aOneProcess_Info[2] = StringFormat('%.1f', $vCPU_Info.PercentProcessorTime) & " %" Return $aOneProcess_Info EndIf Else $aAllProcess_Info[0][0] += 1 $aAllProcess_Info[$aAllProcess_Info[0][0]][0] = $vCPU_Info.Name $aAllProcess_Info[$aAllProcess_Info[0][0]][1] = $vCPU_Info.IDProcess $aAllProcess_Info[$aAllProcess_Info[0][0]][2] = StringFormat('%.1f', $vCPU_Info.PercentProcessorTime) & " %" EndIf Next ReDim $aAllProcess_Info[$aAllProcess_Info[0][0] +1][3] Return $aAllProcess_Info EndFunc ;==>GetCPU Sorry for my crappy explanation. Edited May 29, 2018 by red0fireus
jchd Posted May 29, 2018 Posted May 29, 2018 Add this debug line: ConsoleWrite($vCPU_Info.PercentProcessorTime & @TAB & VarGetType($vCPU_Info.PercentProcessorTime) & @LF) and see that this property returns a string datatype containing an integer. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
Earthshine Posted May 29, 2018 Posted May 29, 2018 (edited) snip Edited May 29, 2018 by Earthshine TheDcoder 1 My resources are limited. You must ask the right questions
RTFC Posted May 29, 2018 Posted May 29, 2018 It really isn't that difficult to find a pure AutoIt Example script that produces this (google: site:autoitscript.com cpu load, near bottom of first page). My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O
Earthshine Posted May 29, 2018 Posted May 29, 2018 wowsers that lots of code... lol My resources are limited. You must ask the right questions
RTFC Posted May 29, 2018 Posted May 29, 2018 1 hour ago, Earthshine said: lots of code Oh really? kernel32.dll + ntdll.dll + CPU_ProcessorUsage.au3 = 687 Kb + 1909 Kb + 14 Kb = 2,610 Kb .NET = 4.5 GB TheDcoder 1 My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O
Earthshine Posted May 29, 2018 Posted May 29, 2018 (edited) what doesnt have .net installed. I'm only using handful of dll Edited May 29, 2018 by Earthshine My resources are limited. You must ask the right questions
TheDcoder Posted May 29, 2018 Posted May 29, 2018 @Earthshine Well we are obviously looking for something which we can easily use in AutoIt code, and it is simpler to add more AutoIt code rather than learning C# and writing your program in it Earthshine 1 EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
Earthshine Posted May 29, 2018 Posted May 29, 2018 you can use c# with autoit though with CLR3.au3 just in case you guys determine some kind of bug, but it looks like it's covered. Thanks. My resources are limited. You must ask the right questions
RTFC Posted May 29, 2018 Posted May 29, 2018 (edited) @Earthshine: There's actually a C#/.Net AutoIt subforum for your suggestion; I think it's neither apposite nor helpful if your first post in someone's request for Help with AutoIt in the main AutoIt GH & S forum is producing a C# snippet, especially when responding to New Members and obvious beginners, and even more so when native AutoIt solutions are readily available. Thanks. Edited May 29, 2018 by RTFC TheDcoder 1 My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O
Moderators Melba23 Posted May 29, 2018 Moderators Posted May 29, 2018 Earthshine, I entirely agree with RTFC's comments above - your constant suggestions of using other languages or offering of non-AutoIt code in response to questions is becoming annoying. Please remember that this is an AutoIt forum and we should try and focus on that language when we can. Thanks for your future cooperation in this. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Earthshine Posted May 29, 2018 Posted May 29, 2018 (edited) ok. but i have not any examples that give anything but integer percentages. using the suggested google search as mentioned above. going through samples from search pages. thanks. Edited May 29, 2018 by Earthshine My resources are limited. You must ask the right questions
Moderators JLogan3o13 Posted May 29, 2018 Moderators Posted May 29, 2018 27 minutes ago, Earthshine said: ok. but i have not any examples that give anything but integer percentages Then stay out of the topic... "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
RTFC Posted May 29, 2018 Posted May 29, 2018 Ascendant's Example script I linked to earlier in this thread actually reports CPU usage with decimal. And if you look for the Round() function in that script, you can add more decimals (by editing its second parameter). My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O
Earthshine Posted May 29, 2018 Posted May 29, 2018 (edited) yes indeed. sorry all. @RTFC link led me to what he was talking about, which does, in fact give the OP what he wants. CPU_ProcessorUsage.au3 Sorry again. Edited May 29, 2018 by Earthshine My resources are limited. You must ask the right questions
red0fireus Posted May 29, 2018 Author Posted May 29, 2018 Thank you so much for the help! I really appreciate it
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