- Notifications
You must be signed in to change notification settings - Fork 31.7k
/
Copy pathmemory_watchdog.py
28 lines (23 loc) · 859 Bytes
/
memory_watchdog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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.
importos
importsys
importtime
try:
page_size=os.sysconf('SC_PAGESIZE')
except (ValueError, AttributeError):
try:
page_size=os.sysconf('SC_PAGE_SIZE')
except (ValueError, AttributeError):
page_size=4096
whileTrue:
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)