Jump to content

Recommended Posts

Posted

How much information can be obtained about a runing process using autoIT can it get the memory consumption in real time, and log it to a text file when the memory usage changes?

Posted

Generated by scriptomatic! Requires beta

; Generated by AutoIt Scriptomatic

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$Output=""
$Output = $Output & "Computer: " & $strComputer  & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output = $Output & "Caption: " & $objItem.Caption & @CRLF
      $Output = $Output & "CommandLine: " & $objItem.CommandLine & @CRLF
      $Output = $Output & "CreationClassName: " & $objItem.CreationClassName & @CRLF
      $Output = $Output & "CreationDate: " & WMIDateStringToDate($objItem.CreationDate) & @CRLF
      $Output = $Output & "CSCreationClassName: " & $objItem.CSCreationClassName & @CRLF
      $Output = $Output & "CSName: " & $objItem.CSName & @CRLF
      $Output = $Output & "Description: " & $objItem.Description & @CRLF
      $Output = $Output & "ExecutablePath: " & $objItem.ExecutablePath & @CRLF
      $Output = $Output & "ExecutionState: " & $objItem.ExecutionState & @CRLF
      $Output = $Output & "Handle: " & $objItem.Handle & @CRLF
      $Output = $Output & "HandleCount: " & $objItem.HandleCount & @CRLF
      $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF
      $Output = $Output & "KernelModeTime: " & $objItem.KernelModeTime & @CRLF
      $Output = $Output & "MaximumWorkingSetSize: " & $objItem.MaximumWorkingSetSize & @CRLF
      $Output = $Output & "MinimumWorkingSetSize: " & $objItem.MinimumWorkingSetSize & @CRLF
      $Output = $Output & "Name: " & $objItem.Name & @CRLF
      $Output = $Output & "OSCreationClassName: " & $objItem.OSCreationClassName & @CRLF
      $Output = $Output & "OSName: " & $objItem.OSName & @CRLF
      $Output = $Output & "OtherOperationCount: " & $objItem.OtherOperationCount & @CRLF
      $Output = $Output & "OtherTransferCount: " & $objItem.OtherTransferCount & @CRLF
      $Output = $Output & "PageFaults: " & $objItem.PageFaults & @CRLF
      $Output = $Output & "PageFileUsage: " & $objItem.PageFileUsage & @CRLF
      $Output = $Output & "ParentProcessId: " & $objItem.ParentProcessId & @CRLF
      $Output = $Output & "PeakPageFileUsage: " & $objItem.PeakPageFileUsage & @CRLF
      $Output = $Output & "PeakVirtualSize: " & $objItem.PeakVirtualSize & @CRLF
      $Output = $Output & "PeakWorkingSetSize: " & $objItem.PeakWorkingSetSize & @CRLF
      $Output = $Output & "Priority: " & $objItem.Priority & @CRLF
      $Output = $Output & "PrivatePageCount: " & $objItem.PrivatePageCount & @CRLF
      $Output = $Output & "ProcessId: " & $objItem.ProcessId & @CRLF
      $Output = $Output & "QuotaNonPagedPoolUsage: " & $objItem.QuotaNonPagedPoolUsage & @CRLF
      $Output = $Output & "QuotaPagedPoolUsage: " & $objItem.QuotaPagedPoolUsage & @CRLF
      $Output = $Output & "QuotaPeakNonPagedPoolUsage: " & $objItem.QuotaPeakNonPagedPoolUsage & @CRLF
      $Output = $Output & "QuotaPeakPagedPoolUsage: " & $objItem.QuotaPeakPagedPoolUsage & @CRLF
      $Output = $Output & "ReadOperationCount: " & $objItem.ReadOperationCount & @CRLF
      $Output = $Output & "ReadTransferCount: " & $objItem.ReadTransferCount & @CRLF
      $Output = $Output & "SessionId: " & $objItem.SessionId & @CRLF
      $Output = $Output & "Status: " & $objItem.Status & @CRLF
      $Output = $Output & "TerminationDate: " & WMIDateStringToDate($objItem.TerminationDate) & @CRLF
      $Output = $Output & "ThreadCount: " & $objItem.ThreadCount & @CRLF
      $Output = $Output & "UserModeTime: " & $objItem.UserModeTime & @CRLF
      $Output = $Output & "VirtualSize: " & $objItem.VirtualSize & @CRLF
      $Output = $Output & "WindowsVersion: " & $objItem.WindowsVersion & @CRLF
      $Output = $Output & "WorkingSetSize: " & $objItem.WorkingSetSize & @CRLF
      $Output = $Output & "WriteOperationCount: " & $objItem.WriteOperationCount & @CRLF
      $Output = $Output & "WriteTransferCount: " & $objItem.WriteTransferCount & @CRLF
      if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
      $Output=""
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_Process" )
Endif


Func WMIDateStringToDate($dtmDate)

    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc
  • 1 year later...
Posted

I need to monitor the average of CPU and RAM percentage consuming for a given process in a given period of time.

Anyone can help?

Thanks and best regards

Peppe

  • Moderators
Posted

Works fine in 3.2.8.1, don't need beta.

That post you just quoted was 19 months ago <_< ... back then, it did require beta :)

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.

  • Moderators
Posted (edited)

I need to monitor the average of CPU and RAM percentage consuming for a given process in a given period of time.

Anyone can help?

Thanks and best regards

Peppe

http://www.autoitscript.com/forum/index.ph...st&p=136637

Edit:

Also: http://www.autoitscript.com/forum/index.ph...st&p=138811

Edited by SmOke_N

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.

Posted (edited)

Check this out. Using PsaltyDS' _ProcessListProperties() UDF:

#409276

#include <array.au3> ; for _ArrayDisplay()

;Poll Frequency in milliseconds
Dim $PollFrequency = 1000

;Number of times to execute poll
Dim $PollCount = 5

;Combined CPU usage
Dim $totalCpu = 0

;Combined RAM usage
Dim $totalRam = 0

;Process name
$processName = "winamp.exe"

For $X = 1 to $PollCount
    $avRET = _ProcessListProperties($processName)
    $totalCpu += $avRET[1][6]
    $totalRam += $avRET[1][7]
    
    Sleep($PollFrequency)
    
    TrayTip("Monitoring: " & $processName,"Time Elapsed: " & $X * ($PollFrequency / 1000) & " s" & @CRLF & "Time Remaining: " & ($PollCount * ($PollFrequency / 1000)) - ($X * ($PollFrequency / 1000)) & " s", 1)
Next

MsgBox(0,$processName,"Average CPU usage: " & $totalCpu / $PollCount & @CRLF & "Average RAM usage: " & ($totalRam / $PollCount) / 1024 / 1024 & " mb")

EDIT: Added conversion for kilobytes to mb

Edited by weaponx
Posted

Check this out. Using PsaltyDS' _ProcessListProperties() UDF:

#409276

#include <array.au3> ; for _ArrayDisplay()

;Poll Frequency in milliseconds
Dim $PollFrequency = 1000

;Number of times to execute poll
Dim $PollCount = 5

;Combined CPU usage
Dim $totalCpu = 0

;Combined RAM usage
Dim $totalRam = 0

;Process name
$processName = "winamp.exe"

For $X = 1 to $PollCount
    $avRET = _ProcessListProperties($processName)
    $totalCpu += $avRET[1][6]
    $totalRam += $avRET[1][7]
    
    Sleep($PollFrequency)
    
    TrayTip("Monitoring: " & $processName,"Time Elapsed: " & $X * ($PollFrequency / 1000) & " s" & @CRLF & "Time Remaining: " & ($PollCount * ($PollFrequency / 1000)) - ($X * ($PollFrequency / 1000)) & " s", 1)
Next

MsgBox(0,$processName,"Average CPU usage: " & $totalCpu / $PollCount & @CRLF & "Average RAM usage: " & ($totalRam / $PollCount) / 1024 / 1024 & " mb")

EDIT: Added conversion for kilobytes to mb

It works very fine. Many thanks to you and to Smoke__n.
Posted

That post you just quoted was 19 months ago <_< ... back then, it did require beta :)

I didn't even look at the dates. I just assumed it was newer since it was on the front page.

  • 1 month later...
Posted

Here is an improved version of the weaponx script that shows an inputbox with the process name to monitor (if not listed in the INI file), and writes an output log.

Maybe it could be useful for some of you.

#include "ProcessListProperties.au3"
#include <File.au3>

Local $sProcessName, $sIniRec, $iIniRec, $iPollFrequency, $iPollCount, $iDuration, $iTtotalCpu = 0, $iTtotalRam = 0, $iAverageCPU = 0, $iAverageRAM = 0

;INI File - Section Settings
$sIniRec = IniReadSection(@ScriptDir & "\ProcessMonitor.ini", "Settings")
If @error Then 
    MsgBox(4096, "", "Error occurred, probably no INI file")
    Exit
EndIf

For $iIniRec = 1 To $sIniRec[0][0]
    Select
        Case $sIniRec[$iIniRec][0] = "ProcessName"
            $sProcessName = $sIniRec[$iIniRec][1]

        Case $sIniRec[$iIniRec][0] = "PollFrequency"
            $iPollFrequency = $sIniRec[$iIniRec][1]

        Case $sIniRec[$iIniRec][0] = "Duration"
            $iDuration = $sIniRec[$iIniRec][1]
    EndSelect
Next    

;InputBox features: Title=Yes, Prompt=Yes, Default Text=No, Mandatory
If $sProcessName = "" Then 
    $sProcessName = InputBox("ProcessMonitor","Digitare il nome del processo da monitorare",""," M","-1","-1","-1","-1")
    If @Error <> 0 Then Exit
EndIf
    
_FileWriteLog(@ScriptDir & "\ProcessMonitor.log","Process name: " & $sProcessName & " - Polling Interval in seconds: " & $iPollFrequency & " - Monitor Period in seconds: " & $iDuration & @CRLF)

$iPollCount = $iDuration / $iPollFrequency

;Polling Interval in Milliseconds
$iPollFrequency *= 1000

For $X = 1 to $iPollCount
    $avRET = _ProcessListProperties($sProcessName)
    $iTtotalCpu += $avRET[1][6]
    $iTtotalRam += $avRET[1][7]
    
    Sleep($iPollFrequency)
    
    TrayTip("Monitoring: " & $sProcessName,"Time Elapsed: " & $X * ($iPollFrequency / 1000) & " s" & @CRLF & "Time Remaining: " & ($iPollCount * ($iPollFrequency / 1000)) - ($X * ($iPollFrequency / 1000)) & " s", 1)
    _FileWriteLog(@ScriptDir & "\ProcessMonitor.log","CPU: " & $avRET[1][6] & @TAB & "RAM: " & $avRET[1][7])
Next

$iAverageCPU = Round($iTtotalCpu / $iPollCount, 1)
$iAverageRAM = Round($iTtotalRam / $iPollCount, 1)

_FileWriteLog(@ScriptDir & "\ProcessMonitor.log", "Average CPU usage: " & $iAverageCPU & @TAB & "Average RAM usage: " & $iAverageRAM)
MsgBox(0,$sProcessName,"Average CPU usage: " & $iAverageCPU & @CRLF & "Average RAM usage: " & $iAverageRAM)

ProcessMinitor.ini example

[settings]

;Process Name (Optional)

ProcessName=rtvscan.exe

;Polling Interval in seconds

PollFrequency=5

;Monitor period in seconds

Duration=3600

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...