changeset 1167:5e905ff44e84

CC now suports statprof profiling, and every other profile() call is now broken Ignore-this: bc7c31af6598e7c132d2f847afe8de68
author drewp@bigasterisk.com
date Sun, 15 Jun 2014 03:09:48 +0000
parents f0d752c0a772
children 5c2678c189d5
files bin/curvecalc light9/prof.py
diffstat 2 files changed, 17 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/bin/curvecalc	Sun Jun 15 02:53:33 2014 +0000
+++ b/bin/curvecalc	Sun Jun 15 03:09:48 2014 +0000
@@ -490,7 +490,7 @@
                       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()
 
--- a/light9/prof.py	Sun Jun 15 02:53:33 2014 +0000
+++ b/light9/prof.py	Sun Jun 15 03:09:48 2014 +0000
@@ -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'