Last active
August 2, 2018 12:46
-
-
Save tos-kamiya/d167371d2e624707123dce8cf6e1b398 to your computer and use it in GitHub Desktop.
timemem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import subprocess | |
import resource | |
import sys | |
import time | |
USAGE = '''usage: timemem <command-line>... | |
Run the command line and show total time usage (sum of the process, its | |
children, its grand children, etc) and the max resident memory usage (the | |
largest of these processes, not total). | |
''' | |
if len(sys.argv) == 1 or sys.argv[1] in ('-h', '--help'): | |
print(USAGE) | |
sys.exit(0) | |
start = time.time() | |
retcode = subprocess.run(sys.argv[1:]).returncode | |
end = time.time() | |
ru = resource.getrusage(resource.RUSAGE_CHILDREN) | |
print('real %g' % (end - start)) | |
print('user %g' % ru.ru_utime) | |
print('sys %g' % ru.ru_stime) | |
print('maxrss %g' % ru.ru_maxrss) | |
sys.exit(retcode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment