]> granicus.if.org Git - python/commitdiff
Add -p option to invoke Python profiler
authorJeremy Hylton <jeremy@alum.mit.edu>
Mon, 17 Sep 2001 18:08:40 +0000 (18:08 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Mon, 17 Sep 2001 18:08:40 +0000 (18:08 +0000)
Tools/compiler/compile.py

index 41dc8984d35b7883d90402edcd6c29ff2c90ae26..1a843e2eb5843d983c4d808ce0f0f5dcf7198b1f 100644 (file)
@@ -3,13 +3,14 @@ import getopt
 
 from compiler import compile, visitor
 
-##import profile
+import profile
 
 def main():
     VERBOSE = 0
     DISPLAY = 0
+    PROFILE = 0
     CONTINUE = 0
-    opts, args = getopt.getopt(sys.argv[1:], 'vqdc')
+    opts, args = getopt.getopt(sys.argv[1:], 'vqdcp')
     for k, v in opts:
         if k == '-v':
             VERBOSE = 1
@@ -24,6 +25,8 @@ def main():
             DISPLAY = 1
         if k == '-c':
             CONTINUE = 1
+        if k == '-p':
+            PROFILE = 1
     if not args:
         print "no files to compile"
     else:
@@ -31,9 +34,12 @@ def main():
             if VERBOSE:
                 print filename
             try:
-                compile(filename, DISPLAY)
-##                profile.run('compile(%s, %s)' % (`filename`, `DISPLAY`),
-##                            filename + ".prof")
+                if PROFILE:
+                    profile.run('compile(%s, %s)' % (`filename`, `DISPLAY`),
+                                filename + ".prof")
+                else:
+                    compile(filename, DISPLAY)
+                    
             except SyntaxError, err:
                 print err
                 print err.lineno