Jump to content

ProcessGetStats() returns higher number of memory use then the number in task manager


Recommended Posts

Posted

hello,

in this test:

$Process = "firefox.exe"
While 1
    $test = ProcessGetStats($Process)
    ConsoleWrite($test[0]/1024&@CRLF)
    Sleep(300)
WEnd

ProcessGetStats() returns a higher number of memory use then what i see in task manager.

in task manager firefox.exe taks 582,000 kb and in this code i get 678,500 kb.

i don't know why..

Maybe the number 1024 is not right?

  • Developers
Posted

Look at the Resource Manager. There you will find "WorkingSet" and "Private" Memory usage.

The Taskmanager shows the Private memory and ProcessGetStats() returns the WorkingSet value.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

Look at the Resource Manager. There you will find "WorkingSet" and "Private" Memory usage.

The Taskmanager shows the Private memory and ProcessGetStats() returns the WorkingSet value.

Jos

so this is the total mamory use?

if so then i didn't know that..

this is new to me

Posted

After reading about the differences between working set and private working set, i want to get the private working set..

how can i do that?

Posted (edited)

This is one approach via COM: (note that it uses the Win32_PerfRawData_PerfProc_Process class in lieu of Win32_Process):

Local $objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfRawData_PerfProc_Process WHERE NAME = 'firefox' OR NAME = 'autoit3'")

If IsObj($colItems) Then
    ConsoleWrite("Parsing [ " & ObjName($colItems, 6) & " ]" & @LF)

    For $objItem In $colItems
        ConsoleWrite("Name: " & $objItem.Name & @CRLF & _
                @TAB & "WorkingSetPrivate: " & @TAB & _SimpleSize($objItem.WorkingSetPrivate) & @CRLF & _
                @TAB & "ReservedPrivate: " & @TAB & _SimpleSize($objItem.PrivateBytes) & @CRLF & _
                @TAB & "WorkingSetSize: " & @TAB & _SimpleSize($objItem.WorkingSet) & @CRLF)
    Next
Else
    ConsoleWrite("No WMI Objects Found" & @CRLF)
EndIf

Func _SimpleSize($Bytes, $Places = 2)
    Local $y, $Human[4] = [" KB", " MB", " GB", " TB"]

    For $y = 4 To 1 Step -1
        If $Bytes >= 1024 ^ $y Then Return Round($Bytes / (1024 ^ $y), $Places) & $Human[$y - 1]
    Next

    Return $Bytes & " Bytes"
EndFunc
Edited by Kilmatead
Posted (edited)

 

This is one approach via COM: (note that it uses the Win32_PerfRawData_PerfProc_Process class in lieu of Win32_Process):

Local $objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfRawData_PerfProc_Process WHERE NAME = 'firefox'")

If IsObj($colItems) Then
    ConsoleWrite("Parsing [ " & ObjName($colItems, 1) & " ]" & @LF)

    For $objItem In $colItems
        ConsoleWrite("Name: " & $objItem.Name & @CRLF & _
                @TAB & "WorkingSetPrivate: " & @TAB & _SimpleSize($objItem.WorkingSetPrivate) & @CRLF & _
                @TAB & "WorkingSetSize: " & @TAB & _SimpleSize($objItem.WorkingSet) & @CRLF)
    Next
Else
    ConsoleWrite("No WMI Objects Found" & @CRLF)
EndIf

Func _SimpleSize($Bytes, $Places = 2)
    Local $y, $Human[4] = [" KB", " MB", " GB", " TB"]

    For $y = 4 To 1 Step -1
        If $Bytes >= 1024 ^ $y Then Return Round($Bytes / (1024 ^ $y), $Places) & $Human[$y - 1]
    Next

    Return $Bytes & " Bytes"
EndFunc

 

Thank you!

What problems can be if it is using Win32_PerfRawData_PerfProc_Process ?

Edited by Guest
Posted (edited)

There are no problems with it at all - I only added that to show that the WMI library Win32_Process (which was the first thing that came to mind) doesn't include "private" details (but it does have WorkingSet, which some might find confusing) - it just took a little while to dig up the "more obscurely named" library. :)

Note that I updated the original to include the .PrivateBytes as part of the display - as near as I can tell this is the amount of memory which that process has allocated specifically to itself, rather than just the minimum it requires (the number resides roughly between .WorkingSetPrivate and .WorkingSet) so seems more accurate.

Edited by Kilmatead
Posted

There are no problems with it at all - I only added that to show that the WMI library Win32_Process (which was the first thing that came to mind) doesn't include "private" details (but it does have WorkingSet, which some might find confusing) - it just took a little while to dig up the "more obscurely named" library. :)

Note that I updated the original to include the .PrivateBytes as part of the display - as near as I can tell this is the amount of memory which that process has allocated specifically to itself, rather than just the minimum it requires (the number resides roughly between .WorkingSetPrivate and .WorkingSet) so seems more accurate.

ok thank you.

It seems to be good enough.

Thank you

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...