summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Finney <seanius@debian.org>2009-09-01 08:53:36 +0200
committerSean Finney <seanius@debian.org>2009-09-01 08:59:04 +0200
commit58da155bfdf44010a964778421fcf9cae298532a (patch)
tree7f1d44f5d51b34392bcb8a69b2870c7173dc2236
parentf28a60d7373b5d23599c111ff18d69a94ae69a36 (diff)
downloadpatch-tracker-58da155bfdf44010a964778421fcf9cae298532a.tar.gz
consolidate profiling in pagehandler, removing duplicate code
-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))")
+