Can someone explain how to get to the MEM Usage as shown on the
performance tab of Task Manager?
I have been looking at WorkingSetSize and PeakWorkingSetSize under
Win32_Process, but these seem to be something else.
I think the WorkingSetSize is the MEM Usage Task Manager shows in the
Processes pane, but this is _less_ than that shown on the Performance
pane. Using PeakWorkingSetSize gives a higher figure than task
manager shows.
Why the discrepancy, and what memory usage are these actually
describing ?
Hi
WorkingSetSize is the relevant value to compare with. You did divide the values
with 1024 to get KB? The script below gives me pretty much the same values as
the ones in Task Manager.
sComputer = "."
Set oWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
Set colProcessList = oWMIService.ExecQuery _
("Select Name, WorkingSetSize from Win32_Process")
For Each oProcess in colProcessList
WScript.Echo oProcess.Name, oProcess.WorkingSetSize \ 1024
Next
--
torgeir
Microsoft MVP Scripting and WMI
Porsgrunn Norway
WorkingSet gives the same values per process as task manager shows in
the processes pane. However, if you add them all up, this comes to less
than task manager shows as mem usage under the performance tab, or do
they add up correctly for you ?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
> Yes, I did divide them.
>
> WorkingSet gives the same values per process as task manager shows in
> the processes pane. However, if you add them all up, this comes to less
> than task manager shows as mem usage under the performance tab, or do
> they add up correctly for you ?
Hi
I misread your question the first time. To get to the physical memory values
under the Performance tab, you can use properties in the win32_operatingsystem
class.
Win32_OperatingSystem class
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_operatingsystem.asp
Here is a script that give you the "Available" and "Total" values.
s = ""
servername = "." 'use "." for local machine...
set wmi = getobject("winmgmts://" & servername & "/root/cimv2")
wql = "select * from win32_operatingsystem"
set results = wmi.execquery(wql)
for each obj in results
set os = obj:exit for
next
s = s & "FreePhysicalMemory = " & os.FreePhysicalMemory & vbcrlf
s = s & "TotalVisibleMemorySize = " & os.TotalVisibleMemorySize & vbcrlf
s = s & string(40,"=") & vbcrlf
s = s & "(Note: all memory amounts are in kilobytes)"
Available memory can be obtained from the Win32_PerfRawData_PerfOS_Memory class
also.
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_perfrawdata_perfos_memory.asp
sHostName = "."
Set Memory = GetObject("winmgmts:{impersonationLevel=impersonate}!//" _
& sHostName & "/root/cimv2:Win32_PerfRawData_PerfOS_Memory=@")
WScript.Echo "Free Memory in KB: " & Memory.AvailableKBytes
OK, using these TotalVisibleMemorySize - FreePhysicalMemory gives yet
another figure for memory used. This one is sometimes more than
workingsetsize and sometimes less, but always less than the MEM Usage
on the Performance tab of task manager - this is the figure i would
like to get.
Also, is there any info anywhere on what these are actually measuring
?
Thanks
Jon
What figures? I don't recall your earlier post. It's possible it got lost
in the never-never land that is USENET.
The previous posts in this thread between Torgeir and myself describe
several different ways of getting at memory usage through wmi - all of
these give a different figure for memory usage and none of them give
the figure I was originally after, namely the MEM Usage figure on the
performance tab of task manager.
Obviously they are all calculating memory usage slightly differently
and I was wondering what exactly the different figures represent.
Apologies if i sounded ungrateful, it just seems that trying to get
info on wmi is like trying to get blood out of a stone sometimes :(