[pypy-commit] pypy default: add the -o option to memusage.py
antocuni
noreply at buildbot.pypy.org
Thu May 19 15:48:01 CEST 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch:
Changeset: r44305:4dcb56365f28
Date: 2011-05-19 15:38 +0200
http://bitbucket.org/pypy/pypy/changeset/4dcb56365f28/
Log: add the -o option to memusage.py
diff --git a/pypy/tool/memusage/memusage.py b/pypy/tool/memusage/memusage.py
--- a/pypy/tool/memusage/memusage.py
+++ b/pypy/tool/memusage/memusage.py
@@ -1,16 +1,32 @@
#! /usr/bin/env python
"""
+Usage: memusage.py [-o filename] command [args...]
+
Runs a subprocess, and measure its RSS (resident set size) every second.
At the end, print the maximum RSS measured, and some statistics.
-Also writes 'memusage.log', reporting every second the RSS.
+
+Also writes "filename", reporting every second the RSS. If filename is not
+given, the output is written to "memusage.log"
"""
import sys, os, re, time
-args = sys.argv[1:]
-if not args:
- print >> sys.stderr, __doc__
+def parse_args():
+ args = sys.argv[1:]
+ if args[0] == '-o':
+ args.pop(0)
+ outname = args.pop(0)
+ else:
+ outname = 'memusage.log'
+ args[0] # make sure there is at least one argument left
+ return outname, args
+
+try:
+ outname, args = parse_args()
+except IndexError:
+ print >> sys.stderr, __doc__.strip()
sys.exit(2)
+
childpid = os.fork()
if childpid == 0:
os.execvp(args[0], args)
@@ -23,7 +39,7 @@
rss_sum = 0
rss_count = 0
-f = open('memusage.log', 'w', 0)
+f = open(outname, 'w', 0)
while os.waitpid(childpid, os.WNOHANG)[0] == 0:
g = open(filename)
s = g.read()
More information about the pypy-commit
mailing list