如何在python 2.7 32bit中获得64bit进程的内存工作集? [英] How to get the memory working set of a 64bit process in python 2.7 32bit?
问题描述
对于自动化测试框架,我需要监视我开始的64位进程的工作集.我以某种方式找不到能够监视超过4GB数据的解决方案.我尝试了WMI和psutil,但是两者都卡在32位边界中.我做这样的事情:
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 )
这提供了:
-0.00 M
4096.00 M
在流程浏览器提供
6.806.976 K
还有另一种获取真实数据的方法吗?
is there another way to get the real data?
谢谢!
推荐答案
好吧,在发生一些WMI工具/谷歌事故后,我发现了另一种用短语表达可提供正确数字的查询的方法.这是新代码:
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?
这篇关于如何在python 2.7 32bit中获得64bit进程的内存工作集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!