summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)