How to find out CPU utilization and Memory usage as displayed in the Windows Task Manager.
We can get these values using WMI service.
Below is the code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'Get the CPU utilization %
myQuery = "SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'"
For Each objItem in objWMIService.ExecQuery(myQuery)
print "Processor time " & objItem.PercentProcessorTime & " %"
next
'Get the total Physical Memory
myQuery="Select * from Win32_ComputerSystem"
Set colItems = objWMIService.ExecQuery(myQuery)
For each objitem in colItems
print "Total Physical Memory "&objitem.TotalPhysicalMemory/1024
Next
'Get the total available physical memory
myQuery="Select * from Win32_PerfFormattedData_PerfOS_Memory"
Set colItems = objWMIService.ExecQuery(myQuery)
For Each objItem in colItems
print "Available GB: " & objItem.AvailableKBytes
Next
Showing posts with label memory usage using QTP. Show all posts
Showing posts with label memory usage using QTP. Show all posts
Friday, November 9, 2012
Saturday, February 25, 2012
How to find the Memory usage and Processor usage using QTP
QTP provides the object called "SystemMonitor" which can be used to get Memory and Processor usage.
'To find the Memory usage of an application, use below:
SystemMonitor.GetValue("Application name without extension", "counter name")
Ex: msgbox SystemMonitor.GetValue("QTPro","Memory Usage (in MB)")
'To find the Processor usage of an application, use below:
Ex: msgbox SystemMonitor.GetValue("javaw","% Processor Time")
'To find the Memory usage of an application, use below:
SystemMonitor.GetValue("Application name without extension", "counter name")
Ex: msgbox SystemMonitor.GetValue("QTPro","Memory Usage (in MB)")
'To find the Processor usage of an application, use below:
Ex: msgbox SystemMonitor.GetValue("javaw","% Processor Time")
Subscribe to:
Posts (Atom)