summaryrefslogtreecommitdiff
path: root/pagehandler.py
diff options
context:
space:
mode:
authorSean Finney <seanius@debian.org>2009-08-31 22:33:06 +0200
committerSean Finney <seanius@debian.org>2009-08-31 22:35:01 +0200
commitc305176d04603000c7c396b2c789cb4b5226088a (patch)
treed8a26c5918f695d2041c24f0b7736003ae4f31c9 /pagehandler.py
parentd77a60063e61f1748b43c3d7accb8c942402a2cd (diff)
downloadpatch-tracker-c305176d04603000c7c396b2c789cb4b5226088a.tar.gz
even better profiling, new -o output cmdline option
use cProfile instead of profile, it's much faster and better as long as it doesn't need to be extended. the -o option redirects the output to the specified file, instead of printing it to stdout (or not printing it, both of which aren't very good for general testing/profiling purposes).
Diffstat (limited to 'pagehandler.py')
-rwxr-xr-xpagehandler.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/pagehandler.py b/pagehandler.py
index 995f95c..a282aae 100755
--- a/pagehandler.py
+++ b/pagehandler.py
@@ -27,7 +27,7 @@ if __name__ == '__main__':
os.environ['SCRIPT_FILENAME'] = sys.argv[0]
from wsgiref import simple_server as ss
import getopt
- import profile, pstats
+ import cProfile as profile, pstats
def cmd_help():
print """
@@ -44,14 +44,17 @@ usage: %s [-hp]
print "%s: %s"%(h,v)
print
- opts,args = getopt.getopt(sys.argv[1:], "hp")
+ opts,args = getopt.getopt(sys.argv[1:], "ho:p")
profiling = False
+ interactive_ofile = sys.stdout
for o,v in opts:
if o == "-h":
cmd_help()
sys.exit(0)
if o == "-p":
profiling = True
+ if o == "-o":
+ interactive_ofile = file(v, "w")
if not args:
print "pagehandler test server running..."
@@ -70,8 +73,9 @@ usage: %s [-hp]
else:
os.environ['PATH_INFO'] = args[0]
if not profiling:
- application(os.environ, cmdline_resp)
+ interactive_ofile.write(application(os.environ, cmdline_resp))
else:
- profile.run("application(os.environ, cmdline_resp)", "profile.out")
+ profile.run("interactive_ofile.write(application(os.environ, cmdline_resp))", "profile.out")
p = pstats.Stats("profile.out")
p.strip_dirs().sort_stats('time').print_stats(20)
+ p.strip_dirs().sort_stats('time').print_callers(20)