##// END OF EJS Templates
Fix a breakpoint bug
Takeshi Kanmae -
Show More
@@ -93,7 +93,7 b' python-profiler package from non-free.""")'
93 empty) statement in the first line. Cell mode allows you to easily
93 empty) statement in the first line. Cell mode allows you to easily
94 profile multiline blocks without having to put them in a separate
94 profile multiline blocks without having to put them in a separate
95 function.
95 function.
96
96
97 The given statement (which doesn't require quote marks) is run via the
97 The given statement (which doesn't require quote marks) is run via the
98 python profiler in a manner similar to the profile.run() function.
98 python profiler in a manner similar to the profile.run() function.
99 Namespaces are internally managed to work correctly; profile.run
99 Namespaces are internally managed to work correctly; profile.run
@@ -555,7 +555,7 b' python-profiler package from non-free.""")'
555 bdb.Breakpoint.bpbynumber = [None]
555 bdb.Breakpoint.bpbynumber = [None]
556 # Set an initial breakpoint to stop execution
556 # Set an initial breakpoint to stop execution
557 maxtries = 10
557 maxtries = 10
558 bp_file, bp_line = parse_breakpoint(opts.get('b', [1])[0], filename)
558 bp_file, bp_line = parse_breakpoint(opts.get('b', ['1'])[0], filename)
559 checkline = deb.checkline(bp_file, bp_line)
559 checkline = deb.checkline(bp_file, bp_line)
560 if not checkline:
560 if not checkline:
561 for bp in range(bp_line + 1, bp_line + maxtries + 1):
561 for bp in range(bp_line + 1, bp_line + maxtries + 1):
@@ -790,7 +790,7 b' python-profiler package from non-free.""")'
790 # but is there a better way to achieve that the code stmt has access
790 # but is there a better way to achieve that the code stmt has access
791 # to the shell namespace?
791 # to the shell namespace?
792 transform = self.shell.input_splitter.transform_cell
792 transform = self.shell.input_splitter.transform_cell
793
793
794 if cell is None:
794 if cell is None:
795 # called as line magic
795 # called as line magic
796 ast_setup = ast.parse("pass")
796 ast_setup = ast.parse("pass")
@@ -798,10 +798,10 b' python-profiler package from non-free.""")'
798 else:
798 else:
799 ast_setup = ast.parse(transform(stmt))
799 ast_setup = ast.parse(transform(stmt))
800 ast_stmt = ast.parse(transform(cell))
800 ast_stmt = ast.parse(transform(cell))
801
801
802 ast_setup = self.shell.transform_ast(ast_setup)
802 ast_setup = self.shell.transform_ast(ast_setup)
803 ast_stmt = self.shell.transform_ast(ast_stmt)
803 ast_stmt = self.shell.transform_ast(ast_stmt)
804
804
805 # This codestring is taken from timeit.template - we fill it in as an
805 # This codestring is taken from timeit.template - we fill it in as an
806 # AST, so that we can apply our AST transformations to the user code
806 # AST, so that we can apply our AST transformations to the user code
807 # without affecting the timing code.
807 # without affecting the timing code.
@@ -812,7 +812,7 b' python-profiler package from non-free.""")'
812 ' stmt\n'
812 ' stmt\n'
813 ' _t1 = _timer()\n'
813 ' _t1 = _timer()\n'
814 ' return _t1 - _t0\n')
814 ' return _t1 - _t0\n')
815
815
816 class TimeitTemplateFiller(ast.NodeTransformer):
816 class TimeitTemplateFiller(ast.NodeTransformer):
817 "This is quite tightly tied to the template definition above."
817 "This is quite tightly tied to the template definition above."
818 def visit_FunctionDef(self, node):
818 def visit_FunctionDef(self, node):
@@ -820,15 +820,15 b' python-profiler package from non-free.""")'
820 self.generic_visit(node)
820 self.generic_visit(node)
821 if node.name == "inner":
821 if node.name == "inner":
822 node.body[:1] = ast_setup.body
822 node.body[:1] = ast_setup.body
823
823
824 return node
824 return node
825
825
826 def visit_For(self, node):
826 def visit_For(self, node):
827 "Fill in the statement to be timed"
827 "Fill in the statement to be timed"
828 if getattr(getattr(node.body[0], 'value', None), 'id', None) == 'stmt':
828 if getattr(getattr(node.body[0], 'value', None), 'id', None) == 'stmt':
829 node.body = ast_stmt.body
829 node.body = ast_stmt.body
830 return node
830 return node
831
831
832 timeit_ast = TimeitTemplateFiller().visit(timeit_ast_template)
832 timeit_ast = TimeitTemplateFiller().visit(timeit_ast_template)
833 timeit_ast = ast.fix_missing_locations(timeit_ast)
833 timeit_ast = ast.fix_missing_locations(timeit_ast)
834
834
@@ -921,14 +921,14 b' python-profiler package from non-free.""")'
921 # fail immediately if the given expression can't be compiled
921 # fail immediately if the given expression can't be compiled
922
922
923 expr = self.shell.prefilter(parameter_s,False)
923 expr = self.shell.prefilter(parameter_s,False)
924
924
925 # Minimum time above which parse time will be reported
925 # Minimum time above which parse time will be reported
926 tp_min = 0.1
926 tp_min = 0.1
927
927
928 t0 = clock()
928 t0 = clock()
929 expr_ast = ast.parse(expr)
929 expr_ast = ast.parse(expr)
930 tp = clock()-t0
930 tp = clock()-t0
931
931
932 # Apply AST transformations
932 # Apply AST transformations
933 expr_ast = self.shell.transform_ast(expr_ast)
933 expr_ast = self.shell.transform_ast(expr_ast)
934
934
@@ -945,7 +945,7 b' python-profiler package from non-free.""")'
945 t0 = clock()
945 t0 = clock()
946 code = compile(expr_ast, source, mode)
946 code = compile(expr_ast, source, mode)
947 tc = clock()-t0
947 tc = clock()-t0
948
948
949 # skew measurement as little as possible
949 # skew measurement as little as possible
950 glob = self.shell.user_ns
950 glob = self.shell.user_ns
951 wtime = time.time
951 wtime = time.time
@@ -1053,17 +1053,17 b' python-profiler package from non-free.""")'
1053 print 'Macro `%s` created. To execute, type its name (without quotes).' % name
1053 print 'Macro `%s` created. To execute, type its name (without quotes).' % name
1054 print '=== Macro contents: ==='
1054 print '=== Macro contents: ==='
1055 print macro,
1055 print macro,
1056
1056
1057 @magic_arguments.magic_arguments()
1057 @magic_arguments.magic_arguments()
1058 @magic_arguments.argument('output', type=str, default='', nargs='?',
1058 @magic_arguments.argument('output', type=str, default='', nargs='?',
1059 help="""The name of the variable in which to store output.
1059 help="""The name of the variable in which to store output.
1060 This is a utils.io.CapturedIO object with stdout/err attributes
1060 This is a utils.io.CapturedIO object with stdout/err attributes
1061 for the text of the captured output.
1061 for the text of the captured output.
1062
1062
1063 CapturedOutput also has a show() method for displaying the output,
1063 CapturedOutput also has a show() method for displaying the output,
1064 and __call__ as well, so you can use that to quickly display the
1064 and __call__ as well, so you can use that to quickly display the
1065 output.
1065 output.
1066
1066
1067 If unspecified, captured output is discarded.
1067 If unspecified, captured output is discarded.
1068 """
1068 """
1069 )
1069 )
General Comments 0
You need to be logged in to leave comments. Login now