1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/build/win32/procmem.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,48 @@ 1.4 +# This Source Code Form is subject to the terms of the Mozilla Public 1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.7 + 1.8 +import os, sys, ctypes, ctypes.wintypes 1.9 + 1.10 +class VM_COUNTERS(ctypes.Structure): 1.11 + _fields_ = [("PeakVirtualSize", ctypes.wintypes.ULONG), 1.12 + ("VirtualSize", ctypes.wintypes.ULONG), 1.13 + ("PageFaultCount", ctypes.wintypes.ULONG), 1.14 + ("PeakWorkingSetSize", ctypes.wintypes.ULONG), 1.15 + ("WorkingSetSize", ctypes.wintypes.ULONG), 1.16 + ("QuotaPeakPagedPoolUsage", ctypes.wintypes.ULONG), 1.17 + ("QuotaPagedPoolUsage", ctypes.wintypes.ULONG), 1.18 + ("QuotaPeakNonPagedPoolUsage", ctypes.wintypes.ULONG), 1.19 + ("QuotaNonPagedPoolUsage", ctypes.wintypes.ULONG), 1.20 + ("PagefileUsage", ctypes.wintypes.ULONG), 1.21 + ("PeakPagefileUsage", ctypes.wintypes.ULONG) 1.22 + ] 1.23 + 1.24 +def get_vmsize(handle): 1.25 + """ 1.26 + Return (peak_virtual_size, virtual_size) for the process |handle|. 1.27 + """ 1.28 + ProcessVmCounters = 3 1.29 + vmc = VM_COUNTERS() 1.30 + if ctypes.windll.ntdll.NtQueryInformationProcess(int(handle), 1.31 + ProcessVmCounters, 1.32 + ctypes.byref(vmc), 1.33 + ctypes.sizeof(vmc), 1.34 + None) == 0: 1.35 + return (vmc.PeakVirtualSize, vmc.VirtualSize) 1.36 + 1.37 + return (-1, -1) 1.38 + 1.39 +if __name__ == '__main__': 1.40 + PROCESS_QUERY_INFORMATION = 0x0400 1.41 + for pid in sys.argv[1:]: 1.42 + handle = ctypes.windll.kernel32.OpenProcess(PROCESS_QUERY_INFORMATION, 1.43 + 0, # no inherit 1.44 + int(pid)) 1.45 + if handle: 1.46 + print "Process %s:" % pid 1.47 + vsize, peak_vsize = get_vmsize(handle) 1.48 + print "peak vsize: %d" % peak_vsize 1.49 + ctypes.windll.kernel32.CloseHandle(handle) 1.50 + else: 1.51 + print "Couldn't open process %s" % pid