[python-win32] Re: win32pdhutil Processor Time always returns 99
Thomas Heller
theller at python.net
Mon Dec 15 11:34:08 EST 2003
>>Is there a way to use WMI (or something else) to track memory use? I
>>can't see a property that would do it but I could be missing
>>something.
>>
>>Thanks
>>Paul
Here's a code snippet I cut off a small script I have, it uses ctypes to
print the changes in the process memory usage over time:
"""
from ctypes import *
class _PROCESS_MEMORY_COUNTERS(Structure):
_fields_ = [("cb", c_long),
("PageFaultCount", c_long),
("PeakWorkingSetSize", c_long),
("WorkingSetSize", c_long),
("QuotaPeakPagedPoolUsage", c_long),
("QuotaPagedPoolUsage", c_long),
("QuotaPeakNonPagedPoolUsage", c_long),
("QuotaNonPagedPoolUsage", c_long),
("PagefileUsage", c_long),
("PeakPagefileUsage", c_long)]
def __init__(self, *args, **kw):
super(_PROCESS_MEMORY_COUNTERS, self).__init__(*args, **kw)
self.cb = sizeof(self)
lastPagefileUsage = 0
def mem_counters():
counters = _PROCESS_MEMORY_COUNTERS()
handle = windll.kernel32.GetCurrentProcess()
if 0 == windll.psapi.GetProcessMemoryInfo(handle, byref(counters), sizeof(counters)):
print FormatError()
global lastPagefileUsage
print "delta mem [kB]", (counters.PagefileUsage - lastPagefileUsage) / 1024.
print "delta mem [B]", (counters.PagefileUsage - lastPagefileUsage)
lastPagefileUsage = counters.PagefileUsage
"""
Thomas
More information about the Python-win32
mailing list