简体   繁体   中英

How to get the memory working set of a 64bit process in python 2.7 32bit?

for an automated test framework I need to monitor the working set of a 64 bit process that I started. Somehow I can't find a solution that allows to monitor more than 4GB data. I tried WMI and psutil, but both are stuck in 32bit borders. I do something like this:

import wmi
import psutil
import subprocess 

def measure_memory( process ):
    mem = psutil.Process( process.pid ).get_memory_info().rss
    return "%.2f M" % (float(mem)/1024./1024.)

def measure_memory_wmi( process ):
    w = wmi.WMI('.')
    result = w.query("SELECT WorkingSet FROM Win32_PerfRawData_PerfProc_Process WHERE IDProcess="+str(process.pid))
    subset = result[0]
    return "%.2f M" % (float(subset.WorkingSet)/1024./1024.)

process = subprocess.Popen( [path_to_program, '-option'] )
print measure_memory( process )
print measure_memory_wmi( process )

this delivers:

-0.00 M
4096.00 M

while the process explorer delivers

6.806.976 K

is there another way to get the real data?

Thanks!

Ok, after some WMI tools / google accident I found another way to phrase a query that delivers correct numbers. This is the new code:

def measure_memory( process ):
    w = wmi.WMI('.')
    result = w.query("SELECT WorkingSetSize FROM Win32_Process WHERE ProcessID="+str(process.pid))
    print result
    subset = result[0]
    return "%.2f" % (float(subset.WorkingSetSize)/1024./1024.)

This seems to work now. Can anyone confirm that this should work for more than my case now?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM