An object which periodically watches the process' memory consumption and prints it out.
| 1236 | |
| 1237 | |
| 1238 | class _MemoryWatchdog: |
| 1239 | """An object which periodically watches the process' memory consumption |
| 1240 | and prints it out. |
| 1241 | """ |
| 1242 | |
| 1243 | def __init__(self): |
| 1244 | self.procfile = '/proc/{pid}/statm'.format(pid=os.getpid()) |
| 1245 | self.started = False |
| 1246 | |
| 1247 | def start(self): |
| 1248 | try: |
| 1249 | f = open(self.procfile, 'r') |
| 1250 | except OSError as e: |
| 1251 | logging.getLogger(__name__).warning('/proc not available for stats: %s', e, exc_info=e) |
| 1252 | sys.stderr.flush() |
| 1253 | return |
| 1254 | |
| 1255 | import subprocess |
| 1256 | with f: |
| 1257 | watchdog_script = findfile("memory_watchdog.py") |
| 1258 | self.mem_watchdog = subprocess.Popen([sys.executable, watchdog_script], |
| 1259 | stdin=f, |
| 1260 | stderr=subprocess.DEVNULL) |
| 1261 | self.started = True |
| 1262 | |
| 1263 | def stop(self): |
| 1264 | if self.started: |
| 1265 | self.mem_watchdog.terminate() |
| 1266 | self.mem_watchdog.wait() |
| 1267 | |
| 1268 | |
| 1269 | def bigmemtest(size, memuse, dry_run=True): |
no outgoing calls
no test coverage detected
searching dependent graphs…