summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpagehandler.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/pagehandler.py b/pagehandler.py
index a282aae..6298b45 100755
--- a/pagehandler.py
+++ b/pagehandler.py
@@ -23,6 +23,14 @@ def application(env, resp):
resp(e.status, [('Content-Type', 'text/html')])
return ReqHandler.ErrorCmd(str(e), e.status).output()
+def profile_app(call):
+ profile.run(call, "profile.out")
+ p = pstats.Stats("profile.out")
+ p.sort_stats('time', 'cumulative')
+ p.print_stats()
+ p.print_callers()
+ p.print_callees()
+
if __name__ == '__main__':
os.environ['SCRIPT_FILENAME'] = sys.argv[0]
from wsgiref import simple_server as ss
@@ -65,9 +73,7 @@ usage: %s [-hp]
if not profiling:
server.handle_request()
else:
- profile.run("server.handle_request()", "profile.out")
- p = pstats.Stats("profile.out")
- p.strip_dirs().sort_stats('time').print_stats(20)
+ profile_app("server.handle_request()")
except IOError, e:
print "adsf: ",e
else:
@@ -75,7 +81,5 @@ usage: %s [-hp]
if not profiling:
interactive_ofile.write(application(os.environ, cmdline_resp))
else:
- 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)
+ profile_app("interactive_ofile.write(application(os.environ, cmdline_resp))")
+