Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Unified Diff: tools/telemetry/third_party/coverage/tests/osinfo.py

Issue 1366913004: Add coverage Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/third_party/coverage/tests/osinfo.py
diff --git a/tools/telemetry/third_party/coverage/tests/osinfo.py b/tools/telemetry/third_party/coverage/tests/osinfo.py
new file mode 100644
index 0000000000000000000000000000000000000000..a7ebd2efd1e19c0bcb7f63e769b558e909041d3f
--- /dev/null
+++ b/tools/telemetry/third_party/coverage/tests/osinfo.py
@@ -0,0 +1,72 @@
+# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
+
+"""OS information for testing."""
+
+from coverage import env
+
+
+if env.WINDOWS:
+ # Windows implementation
+ def process_ram():
+ """How much RAM is this process using? (Windows)"""
+ import ctypes
+ # From: http://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
+
+elif env.LINUX:
+ # Linux implementation
+ import os
+
+ _scale = {'kb': 1024, 'mb': 1024*1024}
+
+ def _VmB(key):
+ """Read the /proc/PID/status file to find memory use."""
+ try:
+ # Get pseudo file /proc/<pid>/status
+ with open('/proc/%d/status' % os.getpid()) as t:
+ v = t.read()
+ except IOError:
+ return 0 # non-Linux?
+ # Get VmKey line e.g. 'VmRSS: 9999 kB\n ...'
+ i = v.index(key)
+ v = v[i:].split(None, 3)
+ if len(v) < 3:
+ return 0 # Invalid format?
+ # Convert Vm value to bytes.
+ return int(float(v[1]) * _scale[v[2].lower()])
+
+ def process_ram():
+ """How much RAM is this process using? (Linux implementation)"""
+ return _VmB('VmRSS')
+
+else:
+ # Generic implementation.
+ def process_ram():
+ """How much RAM is this process using? (stdlib implementation)"""
+ import resource
+ return resource.getrusage(resource.RUSAGE_SELF).ru_maxrss

Powered by Google App Engine
This is Rietveld 408576698