Beispiel #1
0
def get_location(next_instr, is_being_profiled, bytecode):
    from pypy.tool.stdlib_opcode import opcode_method_names
    from rpython.tool.error import offset2lineno
    bcindex = ord(bytecode.co_code[next_instr])
    opname = ""
    if 0 <= bcindex < len(opcode_method_names):
        opname = opcode_method_names[bcindex]
    name = bytecode.co_name
    if not name:
        name = ""
    line = offset2lineno(bytecode, intmask(next_instr))
    return (bytecode.co_filename, line, name, intmask(next_instr), opname)
Beispiel #2
0
def get_location(next_instr, is_being_profiled, bytecode):
    from pypy.tool.stdlib_opcode import opcode_method_names
    from rpython.tool.error import offset2lineno
    bcindex = ord(bytecode.co_code[next_instr])
    opname = ""
    if 0 <= bcindex < len(opcode_method_names):
        opname = opcode_method_names[bcindex]
    name = bytecode.co_name
    if not name:
        name = ""
    line = offset2lineno(bytecode, intmask(next_instr))
    return (bytecode.co_filename, line,
            name, intmask(next_instr), opname)
Beispiel #3
0
    def visit_Block(self, block, tagcolor):
        # do the block itself
        name = self.blockname(block)
        if not isinstance(block, Block):
            data = "BROKEN BLOCK\\n%r" % (block, )
            self.emit_node(name, label=data)
            return

        lines = []
        for op in block.operations:
            lines.extend(repr(op).split('\n'))
        lines.append("")
        numblocks = len(block.exits)
        color = "black"
        fillcolor = getattr(block, "blockcolor", "white")
        if not numblocks:
            shape = "box"
            if len(block.inputargs) == 1:
                lines[-1] += 'return %s' % tuple(block.inputargs)
                fillcolor = RETURN_COLOR
            elif len(block.inputargs) == 2:
                lines[-1] += 'raise %s, %s' % tuple(block.inputargs)
                fillcolor = EXCEPT_COLOR
        elif numblocks == 1:
            shape = "box"
        else:
            color = "red"
            shape = "octagon"

        if block.exitswitch is not None:
            lines.append("exitswitch: %s" % (block.exitswitch, ))

        iargs = " ".join(map(repr, block.inputargs))
        if self.VERBOSE:
            if block.exc_handler:
                eh = ' (EH)'
            else:
                eh = ''
            data = "%s%s%s\\n" % (name, block.at(), eh)
        else:
            data = "%s\\n" % (name, )
        data += "inputargs: %s\\n\\n" % (iargs, )
        if self.VERBOSE and block.operations and self.func:
            maxoffs = max([op.offset for op in block.operations])
            if maxoffs >= 0:
                minoffs = min(
                    [op.offset for op in block.operations if op.offset >= 0])
                minlineno = offset2lineno(self.func.__code__, minoffs)
                maxlineno = offset2lineno(self.func.__code__, maxoffs)
                filename = inspect.getsourcefile(self.func)
                source = "\l".join([
                    linecache.getline(filename, line).rstrip()
                    for line in range(minlineno, maxlineno + 1)
                ])
                if minlineno == maxlineno:
                    data = data + r"line %d:\n%s\l\n" % (minlineno, source)
                else:
                    data = data + r"lines %d-%d:\n%s\l\n" % (minlineno,
                                                             maxlineno, source)

        data = data + "\l".join(lines)

        self.emit_node(name,
                       label=data,
                       shape=shape,
                       color=color,
                       style="filled",
                       fillcolor=fillcolor)

        # do links/exits
        for link in block.exits:
            name2 = self.blockname(link.target)
            label = " ".join(map(repr, link.args))
            if link.exitcase is not None:
                label = "%s: %s" % (repr(link.exitcase).replace('\\',
                                                                '\\\\'), label)
                self.emit_edge(name, name2, label, style="dotted", color="red")
            else:
                self.emit_edge(name, name2, label, style="solid")
Beispiel #4
0
 def get_lineno(self):
     return offset2lineno(self.frame.pycode, self.lasti)
Beispiel #5
0
    def visit_Block(self, block, tagcolor):
        # do the block itself
        name = self.blockname(block)
        if not isinstance(block, Block):
            data = "BROKEN BLOCK\\n%r" % (block,)
            self.emit_node(name, label=data)
            return

        lines = []
        for op in block.operations:
            lines.extend(repr(op).split('\n'))
        lines.append("")
        numblocks = len(block.exits)
        color = "black"
        fillcolor = getattr(block, "blockcolor", "white")
        if not numblocks:
            shape = "box"
            if len(block.inputargs) == 1:
                lines[-1] += 'return %s' % tuple(block.inputargs)
                fillcolor = RETURN_COLOR
            elif len(block.inputargs) == 2:
                lines[-1] += 'raise %s, %s' % tuple(block.inputargs)
                fillcolor = EXCEPT_COLOR
        elif numblocks == 1:
            shape = "box"
        else:
            color = "red"
            shape = "octagon"

        if block.exitswitch is not None:
            lines.append("exitswitch: %s" % (block.exitswitch,))

        iargs = " ".join(map(repr, block.inputargs))
        if self.VERBOSE:
            if block.exc_handler:
                eh = ' (EH)'
            else:
                eh = ''
            data = "%s%s%s\\n" % (name, block.at(), eh)
        else:
            data = "%s\\n" % (name,)
        data += "inputargs: %s\\n\\n" % (iargs,)
        if self.VERBOSE and block.operations and self.func:
            maxoffs = max([op.offset for op in block.operations])
            if maxoffs >= 0:
                minoffs = min([op.offset for op in block.operations
                               if op.offset >= 0])
                minlineno = offset2lineno(self.func.func_code, minoffs)
                maxlineno = offset2lineno(self.func.func_code, maxoffs)
                filename = inspect.getsourcefile(self.func)
                source = "\l".join([linecache.getline(filename, line).rstrip()
                                    for line in range(minlineno, maxlineno+1)])
                if minlineno == maxlineno:
                    data = data + r"line %d:\n%s\l\n" % (minlineno, source)
                else:
                    data = data + r"lines %d-%d:\n%s\l\n" % (minlineno,
                                                             maxlineno, source)

        data = data + "\l".join(lines)

        self.emit_node(name, label=data, shape=shape, color=color, style="filled", fillcolor=fillcolor)

        # do links/exits
        for link in block.exits:
            name2 = self.blockname(link.target)
            label = " ".join(map(repr, link.args))
            if link.exitcase is not None:
                label = "%s: %s" %(repr(link.exitcase).replace('\\', '\\\\'), label)
                self.emit_edge(name, name2, label, style="dotted", color="red")
            else:
                self.emit_edge(name, name2, label, style="solid")