1
# This Source Code Form is subject to the terms of the Mozilla Public
2
# License, v. 2.0. If a copy of the MPL was not distributed with this
3
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
import os, sys, ctypes, ctypes.wintypes
7
class VM_COUNTERS(ctypes.Structure):
8
_fields_ = [("PeakVirtualSize", ctypes.wintypes.ULONG),
9
("VirtualSize", ctypes.wintypes.ULONG),
10
("PageFaultCount", ctypes.wintypes.ULONG),
11
("PeakWorkingSetSize", ctypes.wintypes.ULONG),
12
("WorkingSetSize", ctypes.wintypes.ULONG),
13
("QuotaPeakPagedPoolUsage", ctypes.wintypes.ULONG),
14
("QuotaPagedPoolUsage", ctypes.wintypes.ULONG),
15
("QuotaPeakNonPagedPoolUsage", ctypes.wintypes.ULONG),
16
("QuotaNonPagedPoolUsage", ctypes.wintypes.ULONG),
17
("PagefileUsage", ctypes.wintypes.ULONG),
18
("PeakPagefileUsage", ctypes.wintypes.ULONG)
21
def get_vmsize(handle):
23
Return (peak_virtual_size, virtual_size) for the process |handle|.
27
if ctypes.windll.ntdll.NtQueryInformationProcess(int(handle),
32
return (vmc.PeakVirtualSize, vmc.VirtualSize)
36
if __name__ == '__main__':
37
PROCESS_QUERY_INFORMATION = 0x0400
38
for pid in sys.argv[1:]:
39
handle = ctypes.windll.kernel32.OpenProcess(PROCESS_QUERY_INFORMATION,
43
print "Process %s:" % pid
44
vsize, peak_vsize = get_vmsize(handle)
45
print "peak vsize: %d" % peak_vsize
46
ctypes.windll.kernel32.CloseHandle(handle)
48
print "Couldn't open process %s" % pid