Jump to content
Sign in to follow this  
gil900

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

Recommended Posts

gil900

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?

Share this post


Link to post
Share on other sites
Jos

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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
gil900

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

Share this post


Link to post
Share on other sites
gil900

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?

Share this post


Link to post
Share on other sites
Kilmatead

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

Share this post


Link to post
Share on other sites
gil900

 

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 gil900

Share this post


Link to post
Share on other sites
Kilmatead

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

Share this post


Link to post
Share on other sites
gil900

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

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.