Skip to content

Instantly share code, notes, and snippets.

@vadimkantorov
Created July 18, 2013 15:05
Show Gist options
  • Save vadimkantorov/6030072 to your computer and use it in GitHub Desktop.
Save vadimkantorov/6030072 to your computer and use it in GitHub Desktop.
import sys
import psutil
import subprocess
import datetime
import time
bashScriptPath = sys.argv[1]
stdoutPath, stderrPath = sys.argv[2:] or (None, None)
peakRssBytes = 0
timeRealStart = datetime.datetime.utcnow()
p = subprocess.Popen(['bash', bashScriptPath], stdout = open(stdoutPath, 'w') if stdoutPath else subprocess.STDOUT, stderr = open(stderrPath, 'w') if stderrPath else subprocess.STDERR)
pp = psutil.Process(p.pid)
while True:
returnCode = p.poll()
if returnCode != None:
break
peakRssBytes = max(peakRssBytes, pp.get_memory_info()[0])
for childProc in pp.get_children(recursive = True):
peakRssBytes = max(peakRssBytes, childProc.get_memory_info()[0])
time.sleep(0.1)
timeReal = datetime.datetime.utcnow() - timeRealStart
print 'timeReal\t%s' % timeReal
print 'returnCode\t%s' % returnCode
print 'peakRssMegaBytes\t%.2f' % (peakRssBytes / 1024.0 / 1024.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment