diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2009-11-22 19:51:55 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2009-11-22 19:51:55 -0500 |
commit | d8775b5f8dfbc4f47c78ac50f0947bafe4b77744 (patch) | |
tree | 6b08d551993b7cfc1e854e27c80674165dc4cf59 /test/osinfo.py | |
parent | 411d1943e5cb901a3d65dbb263f26ed606942c25 (diff) | |
download | python-coveragepy-git-d8775b5f8dfbc4f47c78ac50f0947bafe4b77744.tar.gz |
Add a test for leaking memory in the C extension. Windows only for now, kind of experimental.
Diffstat (limited to 'test/osinfo.py')
-rw-r--r-- | test/osinfo.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/osinfo.py b/test/osinfo.py new file mode 100644 index 00000000..5932c537 --- /dev/null +++ b/test/osinfo.py @@ -0,0 +1,40 @@ +"""OS information for testing.""" + +import sys + +if sys.hexversion >= 0x02050000 and sys.platform == 'win32': + # Windows implementation + def process_ram(): + """How much RAM is this process using? (Windows)""" + import ctypes + # lifted from: + # lists.ubuntu.com/archives/bazaar-commits/2009-February/011990.html + class PROCESS_MEMORY_COUNTERS_EX(ctypes.Structure): + """Used by GetProcessMemoryInfo""" + _fields_ = [('cb', ctypes.c_ulong), + ('PageFaultCount', ctypes.c_ulong), + ('PeakWorkingSetSize', ctypes.c_size_t), + ('WorkingSetSize', ctypes.c_size_t), + ('QuotaPeakPagedPoolUsage', ctypes.c_size_t), + ('QuotaPagedPoolUsage', ctypes.c_size_t), + ('QuotaPeakNonPagedPoolUsage', ctypes.c_size_t), + ('QuotaNonPagedPoolUsage', ctypes.c_size_t), + ('PagefileUsage', ctypes.c_size_t), + ('PeakPagefileUsage', ctypes.c_size_t), + ('PrivateUsage', ctypes.c_size_t), + ] + + mem_struct = PROCESS_MEMORY_COUNTERS_EX() + ret = ctypes.windll.psapi.GetProcessMemoryInfo( + ctypes.windll.kernel32.GetCurrentProcess(), + ctypes.byref(mem_struct), + ctypes.sizeof(mem_struct) + ) + if not ret: + return 0 + return mem_struct.PrivateUsage + +else: + def process_ram(): + """How much RAM is this process using? (no implementation)""" + return 0 |