1 | n/a | """Memory watchdog: periodically read the memory usage of the main test process |
---|
2 | n/a | and print it out, until terminated.""" |
---|
3 | n/a | # stdin should refer to the process' /proc/<PID>/statm: we don't pass the |
---|
4 | n/a | # process' PID to avoid a race condition in case of - unlikely - PID recycling. |
---|
5 | n/a | # If the process crashes, reading from the /proc entry will fail with ESRCH. |
---|
6 | n/a | |
---|
7 | n/a | |
---|
8 | n/a | import os |
---|
9 | n/a | import sys |
---|
10 | n/a | import time |
---|
11 | n/a | |
---|
12 | n/a | |
---|
13 | n/a | try: |
---|
14 | n/a | page_size = os.sysconf('SC_PAGESIZE') |
---|
15 | n/a | except (ValueError, AttributeError): |
---|
16 | n/a | try: |
---|
17 | n/a | page_size = os.sysconf('SC_PAGE_SIZE') |
---|
18 | n/a | except (ValueError, AttributeError): |
---|
19 | n/a | page_size = 4096 |
---|
20 | n/a | |
---|
21 | n/a | while True: |
---|
22 | n/a | sys.stdin.seek(0) |
---|
23 | n/a | statm = sys.stdin.read() |
---|
24 | n/a | data = int(statm.split()[5]) |
---|
25 | n/a | sys.stdout.write(" ... process data size: {data:.1f}G\n" |
---|
26 | n/a | .format(data=data * page_size / (1024 ** 3))) |
---|
27 | n/a | sys.stdout.flush() |
---|
28 | n/a | time.sleep(1) |
---|