diff --git a/bin/curvecalc b/bin/curvecalc --- a/bin/curvecalc +++ b/bin/curvecalc @@ -490,7 +490,7 @@ def main(): help="live reload of themes and code") parser.add_option("--startup-only", action='store_true', help="quit after loading everything (for timing tests)") - parser.add_option("--profile", action='store_true', help='profile') + parser.add_option("--profile", help='"hotshot" or "stat"') clientsession.add_option(parser) opts, args = parser.parse_args() diff --git a/light9/prof.py b/light9/prof.py --- a/light9/prof.py +++ b/light9/prof.py @@ -1,16 +1,25 @@ import sys, traceback, time, logging log = logging.getLogger() -def run(main, profile=False): +def run(main, profile=None): if not profile: main() return - - import hotshot, hotshot.stats - p = hotshot.Profile("/tmp/pro") - p.runcall(main) - p.close() - hotshot.stats.load("/tmp/pro").sort_stats('cumulative').print_stats() + + if profile == 'hotshot': + import hotshot, hotshot.stats + p = hotshot.Profile("/tmp/pro") + p.runcall(main) + p.close() + hotshot.stats.load("/tmp/pro").sort_stats('cumulative').print_stats() + elif profile == 'stat': + import statprof + statprof.start() + try: + main() + finally: + statprof.stop() + statprof.display() def watchPoint(filename, lineno, event="call"): """whenever we hit this line, print a stack trace. event='call'