#!/usr/bin/env python3 """Run a command and report the peak RSS (GiB) and wall time of the process tree on stderr. usage: measure_rss.py [args...] Exit code is the child's exit code. """ import resource import subprocess import sys import time t0 = time.time() rc = subprocess.call(sys.argv[1:]) peak_gib = resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss / 1024 / 1024 print(f"EXIT={rc} PEAK_RSS={peak_gib:.2f} GiB WALL={time.time() - t0:.1f}s", file=sys.stderr) sys.exit(rc)