summaryrefslogtreecommitdiffstats
path: root/Lib/test/memory_watchdog.py
diff options
context:
space:
mode:
authorCharles-François Natali <neologix@free.fr>2012-03-24 09:06:23 (GMT)
committerCharles-François Natali <neologix@free.fr>2012-03-24 09:06:23 (GMT)
commit55bce63ea0b6da28a71d4a014bf58b39b91b4e3c (patch)
tree1da6e0f42a7253dd062e70fc1ae814295e59dcc2 /Lib/test/memory_watchdog.py
parent226ed7ecbd47e84bd1e71c967c8130027c02f54f (diff)
downloadcpython-55bce63ea0b6da28a71d4a014bf58b39b91b4e3c.zip
cpython-55bce63ea0b6da28a71d4a014bf58b39b91b4e3c.tar.gz
cpython-55bce63ea0b6da28a71d4a014bf58b39b91b4e3c.tar.bz2
Issue #14154: Reimplement the bigmem test memory watchdog as a subprocess.
Diffstat (limited to 'Lib/test/memory_watchdog.py')
-rw-r--r--Lib/test/memory_watchdog.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/memory_watchdog.py b/Lib/test/memory_watchdog.py
new file mode 100644
index 0000000..88cca8d
--- /dev/null
+++ b/Lib/test/memory_watchdog.py
@@ -0,0 +1,28 @@
+"""Memory watchdog: periodically read the memory usage of the main test process
+and print it out, until terminated."""
+# stdin should refer to the process' /proc/<PID>/statm: we don't pass the
+# process' PID to avoid a race condition in case of - unlikely - PID recycling.
+# If the process crashes, reading from the /proc entry will fail with ESRCH.
+
+
+import os
+import sys
+import time
+
+
+try:
+ page_size = os.sysconf('SC_PAGESIZE')
+except (ValueError, AttributeError):
+ try:
+ page_size = os.sysconf('SC_PAGE_SIZE')
+ except (ValueError, AttributeError):
+ page_size = 4096
+
+while True:
+ sys.stdin.seek(0)
+ statm = sys.stdin.read()
+ data = int(statm.split()[5])
+ sys.stdout.write(" ... process data size: {data:.1f}G\n"
+ .format(data=data * page_size / (1024 ** 3)))
+ sys.stdout.flush()
+ time.sleep(1)