@@ -4,7 +4,7 @@ import compiler
44import optparse
55import os .path
66import sys
7-
7+ from time import time
88
99from java2python .lib .lexer import Lexer
1010from java2python .lib .parser import Parser
@@ -25,15 +25,19 @@ def transform(options):
2525 L = Lexer (* lexer_args )
2626 P = Parser (L )
2727 W = Walker ()
28-
28+
29+ comp_start = start = time ()
2930 try :
3031 P .compilationUnit ()
3132 except (Exception , ), exc :
3233 print '*** exception while parsing:'
3334 print exc
3435 return 1
36+ comp_finish = time ()
3537
38+ ast_start = time ()
3639 ast = P .getAST ()
40+ ast_finish = time ()
3741 if not ast :
3842 print '*** error: no AST generated.'
3943 return 2
@@ -51,11 +55,13 @@ def transform(options):
5155 else :
5256 output = open (fileout , 'w' )
5357
58+ walk_start = time ()
5459 set_config (options .configs , options .includedefaults )
5560 M = Module (filein , fileout )
5661 W .walk (ast , M )
5762 source = str (M )
58- print >> output , source
63+ print >> output , source
64+ walk_finish = time ()
5965
6066 if options .syntaxcheck :
6167 try :
@@ -65,6 +71,13 @@ def transform(options):
6571 else :
6672 msg = '## INFO: generated source has valid syntax.'
6773 print >> sys .stderr , msg
74+
75+ finish = time ()
76+ if options .timerun :
77+ print >> sys .stderr , "## INFO: parser comp unit time: %.4f" % (comp_finish - comp_start )
78+ print >> sys .stderr , "## INFO: ast get time: %.4f" % (ast_finish - ast_start )
79+ print >> sys .stderr , "## INFO: walk and generate time: %.4f" % (walk_finish - walk_start )
80+ print >> sys .stderr , "## INFO: total time: %.4f" % (finish - start )
6881 return 0
6982
7083
@@ -86,6 +99,9 @@ def cli_options(argv):
8699 parser .add_option ('-s' , '--syntaxcheck' , dest = 'syntaxcheck' ,
87100 help = 'Check source syntax after generation' ,
88101 default = False , action = 'store_true' )
102+ parser .add_option ('-t' , '--time' , dest = 'timerun' ,
103+ help = 'Write processing time to stderr' ,
104+ default = False , action = 'store_true' )
89105 options , args = parser .parse_args (argv )
90106 return options , args
91107
0 commit comments