Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#! /usr/bin/python
from __future__ import print_function
import subprocess
import sys
import time
if (len(sys.argv)) != 2:
print("usage:", sys.argv[0], "<pid>")
sys.exit(1)
pid = sys.argv[1]
peak_rss = 0
try:
while True:
# Use -p because --pid doesn't work on Mac.
# Also, have to split the output because --no-headers doesn't work on
# Mac.
cmd = ["ps", "-o", "rss", "-p", pid];
heading, rss = (subprocess.check_output(cmd).rstrip()).split('\n');
rss = int(rss)
print("{0:.2f} MiB".format(rss / 1024.0))
if (rss > peak_rss):
peak_rss = rss
time.sleep(0.05)
except:
print("\npeak: {0:.2f} MiB".format(peak_rss / 1024.0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment