Beispiel #1
0
    def index(self):
        all = flask.request.args.get('all', None)
        loops = []
        for index, loop in enumerate(self.storage.loops):
            try:
                start, stop = loop.comment.find('('), loop.comment.rfind(')')
                name = loop.comment[start + 1:stop]
                func = FunctionHtml.from_operations(loop.operations, self.storage,
                                                    limit=1,
                                                    inputargs=loop.inputargs,
                                                    loopname=name)
            except CannotFindFile:
                func = DummyFunc()
            func.count = getattr(loop, 'count', '?')
            func.descr = mangle_descr(loop.descr)
            loops.append(func)
        loops.sort(lambda a, b: cmp(b.count, a.count))
        if len(loops) > CUTOFF:
            extra_data = "Show all (%d) loops" % len(loops)
        else:
            extra_data = ""
        if not all:
            loops = loops[:CUTOFF]

        qt_workaround = ('Qt/4.7.2' in flask.request.user_agent.string)
        return flask.render_template('index.html', loops=loops,
                                     filename=self.filename,
                                     qt_workaround=qt_workaround,
                                     extra_data=extra_data)
Beispiel #2
0
def index(storage):
    loops = []
    for index, loop in enumerate(storage.loops):
        try:
            start, stop = loop.comment.find("("), loop.comment.rfind(")")
            name = loop.comment[start + 1 : stop]
            func = FunctionHtml.from_operations(
                loop.operations, storage, limit=1, inputargs=loop.inputargs, loopname=name
            )
        except CannotFindFile:
            func = DummyFunc()
        func.descr = mangle_descr(loop.descr)
        loops.append(func)
    return loops
Beispiel #3
0
def loopfunc(id, storage):
    name = mangle_descr(id)
    orig_loop = storage.loop_dict[name]

    ops = orig_loop.operations
    for op in ops:
        if op.is_guard():
            descr = mangle_descr(op.descr)
            subloop = storage.loop_dict.get(descr, None)
            if subloop is not None:
                op.bridge = descr
    loop = FunctionHtml.from_operations(ops, storage, inputargs=orig_loop.inputargs)
    path = []
    if path:
        up = '"' + ",".join(path[:-1]) + '"'
    else:
        up = '""'
    callstack = []
    path_so_far = []
    for e in path:
        if e:
            callstack.append((",".join(path_so_far), "%s in %s at %d" % (loop.name, loop.filename, loop.startlineno)))
            loop = loop.chunks[int(e)]
            path_so_far.append(e)
    callstack.append((",".join(path_so_far), "%s in %s at %d" % (loop.name, loop.filename, loop.startlineno)))

    if not loop.has_valid_code() or loop.filename is None:
        startline = 0
        source = CodeReprNoFile(loop)
    else:
        startline, endline = loop.linerange
        try:
            code = storage.load_code(loop.filename)[(loop.startlineno, loop.name)]
            if code.co_name == "<module>" and code.co_firstlineno == 1:
                with open(code.co_filename) as f:
                    source = CodeRepr(f.read(), code, loop)
            else:
                source = CodeRepr(inspect.getsource(code), code, loop)
        except (IOError, OSError):
            source = CodeReprNoFile(loop)
    d = (source, name, up, loop.filename, startline, callstack)
    return d
Beispiel #4
0
    def loop(self):
        name = mangle_descr(flask.request.args['name'])
        orig_loop = self.storage.loop_dict[name]
        if hasattr(orig_loop, 'force_asm'):
            orig_loop.force_asm()
        ops = orig_loop.operations
        for op in ops:
            if op.is_guard():
                descr = mangle_descr(op.descr)
                subloop = self.storage.loop_dict.get(descr, None)
                if subloop is not None:
                    op.bridge = descr
                    op.count = getattr(subloop, 'count', '?')
                    if (hasattr(subloop, 'count') and
                        hasattr(orig_loop, 'count')):
                        op.percentage = int((float(subloop.count) / orig_loop.count)*100)
                    else:
                        op.percentage = '?'
        print orig_loop.inputargs
        loop = FunctionHtml.from_operations(ops, self.storage,
                                            inputargs=orig_loop.inputargs)
        path = flask.request.args.get('path', '').split(',')
        if path:
            up = '"' + ','.join(path[:-1]) + '"'
        else:
            up = '""'
        callstack = []
        path_so_far = []
        for e in path:
            if e:
                callstack.append((','.join(path_so_far),
                                  '%s in %s at %d' % (loop.name,
                                                      loop.filename,
                                                      loop.startlineno)))
                loop = loop.chunks[int(e)]
                path_so_far.append(e)
        callstack.append((','.join(path_so_far), '%s in %s at %d' % (loop.name,
                                        loop.filename, loop.startlineno)))

        if not loop.has_valid_code() or loop.filename is None:
            startline = 0
            source = CodeReprNoFile(loop)
        else:
            startline, endline = loop.linerange
            try:
                code = self.storage.load_code(loop.filename)[(loop.startlineno,
                                                              loop.name)]
                if code.co_name == '<module>' and code.co_firstlineno == 1:
                    with open(code.co_filename) as f:
                        source = CodeRepr(f.read(), code, loop)
                else:
                    source = CodeRepr(inspect.getsource(code), code, loop)
            except (IOError, OSError):
                source = CodeReprNoFile(loop)
        d = {'html': flask.render_template('loop.html',
                                           source=source,
                                           current_loop=name,
                                           upper_path=up,
                                           show_upper_path=bool(path)),
             'scrollto': startline,
             'callstack': callstack}
        return flask.jsonify(d)