mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Add -p option to invoke Python profiler
This commit is contained in:
		
							parent
							
								
									ce0c19c4a8
								
							
						
					
					
						commit
						bf80a033ee
					
				
					 1 changed files with 11 additions and 5 deletions
				
			
		|  | @ -3,13 +3,14 @@ | ||||||
| 
 | 
 | ||||||
| from compiler import compile, visitor | from compiler import compile, visitor | ||||||
| 
 | 
 | ||||||
| ##import profile | import profile | ||||||
| 
 | 
 | ||||||
| def main(): | def main(): | ||||||
|     VERBOSE = 0 |     VERBOSE = 0 | ||||||
|     DISPLAY = 0 |     DISPLAY = 0 | ||||||
|  |     PROFILE = 0 | ||||||
|     CONTINUE = 0 |     CONTINUE = 0 | ||||||
|     opts, args = getopt.getopt(sys.argv[1:], 'vqdc') |     opts, args = getopt.getopt(sys.argv[1:], 'vqdcp') | ||||||
|     for k, v in opts: |     for k, v in opts: | ||||||
|         if k == '-v': |         if k == '-v': | ||||||
|             VERBOSE = 1 |             VERBOSE = 1 | ||||||
|  | @ -24,6 +25,8 @@ def main(): | ||||||
|             DISPLAY = 1 |             DISPLAY = 1 | ||||||
|         if k == '-c': |         if k == '-c': | ||||||
|             CONTINUE = 1 |             CONTINUE = 1 | ||||||
|  |         if k == '-p': | ||||||
|  |             PROFILE = 1 | ||||||
|     if not args: |     if not args: | ||||||
|         print "no files to compile" |         print "no files to compile" | ||||||
|     else: |     else: | ||||||
|  | @ -31,9 +34,12 @@ def main(): | ||||||
|             if VERBOSE: |             if VERBOSE: | ||||||
|                 print filename |                 print filename | ||||||
|             try: |             try: | ||||||
|                 compile(filename, DISPLAY) |                 if PROFILE: | ||||||
| ##                profile.run('compile(%s, %s)' % (`filename`, `DISPLAY`), |                     profile.run('compile(%s, %s)' % (`filename`, `DISPLAY`), | ||||||
| ##                            filename + ".prof") |                                 filename + ".prof") | ||||||
|  |                 else: | ||||||
|  |                     compile(filename, DISPLAY) | ||||||
|  |                      | ||||||
|             except SyntaxError, err: |             except SyntaxError, err: | ||||||
|                 print err |                 print err | ||||||
|                 print err.lineno |                 print err.lineno | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jeremy Hylton
						Jeremy Hylton