From c305176d04603000c7c396b2c789cb4b5226088a Mon Sep 17 00:00:00 2001 From: Sean Finney Date: Mon, 31 Aug 2009 22:33:06 +0200 Subject: 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). --- pagehandler.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'pagehandler.py') 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) -- cgit v1.2.3