Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 4 | |
michael@0 | 5 | import os, sys, ctypes, ctypes.wintypes |
michael@0 | 6 | |
michael@0 | 7 | class VM_COUNTERS(ctypes.Structure): |
michael@0 | 8 | _fields_ = [("PeakVirtualSize", ctypes.wintypes.ULONG), |
michael@0 | 9 | ("VirtualSize", ctypes.wintypes.ULONG), |
michael@0 | 10 | ("PageFaultCount", ctypes.wintypes.ULONG), |
michael@0 | 11 | ("PeakWorkingSetSize", ctypes.wintypes.ULONG), |
michael@0 | 12 | ("WorkingSetSize", ctypes.wintypes.ULONG), |
michael@0 | 13 | ("QuotaPeakPagedPoolUsage", ctypes.wintypes.ULONG), |
michael@0 | 14 | ("QuotaPagedPoolUsage", ctypes.wintypes.ULONG), |
michael@0 | 15 | ("QuotaPeakNonPagedPoolUsage", ctypes.wintypes.ULONG), |
michael@0 | 16 | ("QuotaNonPagedPoolUsage", ctypes.wintypes.ULONG), |
michael@0 | 17 | ("PagefileUsage", ctypes.wintypes.ULONG), |
michael@0 | 18 | ("PeakPagefileUsage", ctypes.wintypes.ULONG) |
michael@0 | 19 | ] |
michael@0 | 20 | |
michael@0 | 21 | def get_vmsize(handle): |
michael@0 | 22 | """ |
michael@0 | 23 | Return (peak_virtual_size, virtual_size) for the process |handle|. |
michael@0 | 24 | """ |
michael@0 | 25 | ProcessVmCounters = 3 |
michael@0 | 26 | vmc = VM_COUNTERS() |
michael@0 | 27 | if ctypes.windll.ntdll.NtQueryInformationProcess(int(handle), |
michael@0 | 28 | ProcessVmCounters, |
michael@0 | 29 | ctypes.byref(vmc), |
michael@0 | 30 | ctypes.sizeof(vmc), |
michael@0 | 31 | None) == 0: |
michael@0 | 32 | return (vmc.PeakVirtualSize, vmc.VirtualSize) |
michael@0 | 33 | |
michael@0 | 34 | return (-1, -1) |
michael@0 | 35 | |
michael@0 | 36 | if __name__ == '__main__': |
michael@0 | 37 | PROCESS_QUERY_INFORMATION = 0x0400 |
michael@0 | 38 | for pid in sys.argv[1:]: |
michael@0 | 39 | handle = ctypes.windll.kernel32.OpenProcess(PROCESS_QUERY_INFORMATION, |
michael@0 | 40 | 0, # no inherit |
michael@0 | 41 | int(pid)) |
michael@0 | 42 | if handle: |
michael@0 | 43 | print "Process %s:" % pid |
michael@0 | 44 | vsize, peak_vsize = get_vmsize(handle) |
michael@0 | 45 | print "peak vsize: %d" % peak_vsize |
michael@0 | 46 | ctypes.windll.kernel32.CloseHandle(handle) |
michael@0 | 47 | else: |
michael@0 | 48 | print "Couldn't open process %s" % pid |