Skip to content

Instantly share code, notes, and snippets.

@mukulmishra18
Created June 16, 2017 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mukulmishra18/18635de4c82522bde3e7c4c0761f3365 to your computer and use it in GitHub Desktop.
Save mukulmishra18/18635de4c82522bde3e7c4c0761f3365 to your computer and use it in GitHub Desktop.
#! /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