ยปCore Development>Code coverage>Lib/test/memory_watchdog.py

Python code coverage for Lib/test/memory_watchdog.py

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