コード例 #1
0
ファイル: test_parser.py プロジェクト: sota/pypy-old
def test_parse_log_counts():
    loop = parse('''
    [i7]
    i9 = int_lt(i7, 1003)
    label(i9, descr=grrr)
    guard_true(i9, descr=<Guard0xaf>) []
    i13 = getfield_raw(151937600, descr=<SignedFieldDescr pypysig_long_struct.c_value 0>)
    label(i13, descr=asb)
    i19 = int_lt(i13, 1003)
    guard_true(i19, descr=<Guard0x3>) []
    i113 = getfield_raw(151937600, descr=<SignedFieldDescr pypysig_long_struct.c_value 0>)
    ''')
    bridge = parse('''
    # bridge out of Guard 0xaf with 1 ops
    []
    i0 = int_lt(1, 2)
    finish(i0)
    ''')
    bridge.comment = 'bridge out of Guard 0xaf with 1 ops'
    loop.comment = 'Loop 0'
    loops = split_trace(loop) + split_trace(bridge)
    input = ['grrr:123\nasb:12\nbridge 175:1234']
    parse_log_counts(input, loops)
    assert loops[-1].count == 1234
    assert loops[1].count == 123
    assert loops[2].count == 12
コード例 #2
0
def test_parse_log_counts():
    loop = parse('''
    [i7]
    i9 = int_lt(i7, 1003)
    label(i9, descr=grrr)
    guard_true(i9, descr=<Guard2>) []
    i13 = getfield_raw(151937600, descr=<SignedFieldDescr pypysig_long_struct.c_value 0>)
    label(i13, descr=asb)
    i19 = int_lt(i13, 1003)
    guard_true(i19, descr=<Guard3>) []
    i113 = getfield_raw(151937600, descr=<SignedFieldDescr pypysig_long_struct.c_value 0>)
    ''')
    bridge = parse('''
    # bridge out of Guard 2 with 1 ops
    []
    i0 = int_lt(1, 2)
    finish(i0)
    ''')
    bridge.comment = 'bridge out of Guard 2 with 1 ops'
    loop.comment = 'Loop 0'
    loops = split_trace(loop) + split_trace(bridge)
    input = ['grrr:123\nasb:12\nbridge 2:1234']
    parse_log_counts(input, loops)
    assert loops[-1].count == 1234
    assert loops[1].count == 123
    assert loops[2].count == 12
コード例 #3
0
def getMySources(filename):
    extra_path = os.path.dirname(filename)
    storage = LoopStorage(extra_path)

    log, loops = import_log(filename, ParserWithHtmlRepr)
    parse_log_counts(extract_category(log, "jit-backend-count"), loops)
    storage.loops = [loop for loop in loops if not loop.descr.startswith("bridge")]
    [l.force_asm() for l in storage.loops]
    storage.loop_dict = create_loop_dict(loops)
    loops = index(storage)
    ids = [item.descr for item in loops]

    mySources = []
    for item in ids:
        source, name, up, filename, startline, callstack = loopfunc(item, storage)
        i = 1
        mySource = []
        pending = False
        pendingLine = 0
        pendingCode = ""
        for sourceline in source.lines:
            # print  str(i) + ": " + sourceline.line
            line = sourceline.line
            chunks = []
            if sourceline.in_loop and line.strip != "":
                if sourceline.chunks:
                    makePending = True
                    for chunk in sourceline.chunks:
                        if chunk.is_bytecode:
                            ops = []
                            for op in chunk.operations:
                                if op.name != "debug_merge_point":
                                    op_repr = (op.html_repr(), op.asm)
                                    ops.append(op_repr)
                            chunks.append((chunk.html_repr(), chunk, ops))

            if len(chunks) == 0:
                if pending:
                    pendingCode += "\n" + line
                else:
                    pendingCode = line
                    pendingLine = i
                    pending = True
            else:
                if pending:
                    pending = False
                    mySource.append((pendingLine, pendingCode, None))
                mySource.append((i, line, chunks))
            i += 1
        if pending:
            pending = False
            mySource.append((pendingLine, pendingCode, None))
        mySources.append((filename, mySource))

    return mySources
コード例 #4
0
def main():
    filename = sys.argv[1]
    extra_path = os.path.dirname(filename)
    storage = LoopStorage(extra_path)
    
    log, loops = import_log(filename, ParserWithHtmlRepr)
    parse_log_counts(extract_category(log, 'jit-backend-count'), loops)
    storage.loops = [loop for loop in loops
                     if not loop.descr.startswith('bridge')]
    storage.loop_dict = create_loop_dict(loops)
    print loops,log,storage
    server = Server(filename, storage)
コード例 #5
0
ファイル: app.py プロジェクト: michielbaird/VisJitViewer
def main():
    if not '__pypy__' in sys.builtin_module_names:
        print "Please run it using pypy-c"
        sys.exit(1)
    #
    server_mode = True
    if '--qt' in sys.argv:
        server_mode = False
        sys.argv.remove('--qt')
    #
    if len(sys.argv) != 2 and len(sys.argv) != 3:
        print __doc__
        sys.exit(1)
    filename = sys.argv[1]
    extra_path = os.path.dirname(filename)
    if len(sys.argv) != 3:
        port = 5000
    else:
        port = int(sys.argv[2])
    storage = LoopStorage(extra_path)
    log, loops = import_log(filename, ParserWithHtmlRepr)
    parse_log_counts(extract_category(log, 'jit-backend-count'), loops)
    storage.loops = [loop for loop in loops
                     if not loop.descr.startswith('bridge')]
    storage.loop_dict = create_loop_dict(loops)
    print loops,log,storage
    app = OverrideFlask('_jitviewer')
    server = Server(filename, storage)
    app.debug = True
    app.route('/')(server.index)
    app.route('/loop')(server.loop)
    def run():
        app.run(use_reloader=False, host='0.0.0.0', port=port)

    if server_mode:
        run()
    else:
        url = "http://localhost:%d/" % port
        run_server_and_browser(app, run, url, filename)
コード例 #6
0
ファイル: test_jitlogparser.py プロジェクト: charred/pypy
    def test(self):
        def fn_with_bridges(N):
            def is_prime(x):
                for y in xrange(2, x):
                    if x % y == 0:
                        return False
                return True
            result = 0
            for x in xrange(N):
                if x % 3 == 0:
                    result += 5
                elif x % 5 == 0:
                    result += 3
                elif is_prime(x):
                    result += x
                elif x == 99:
                    result *= 2
            return result
        #
        N = 10000
        _log = self.run(fn_with_bridges, [N])
        log, loops = import_log(_log.logfile)
        parse_log_counts(extract_category(log, 'jit-backend-count'), loops)

        is_prime_loops = []
        fn_with_bridges_loops = []
        bridges = {}

        lib_re = re.compile("file '.*lib-python.*'")
        for loop in loops:
            if hasattr(loop, 'force_asm'):
                try:
                    loop.force_asm()
                except ObjdumpNotFound:
                    py.test.skip("ObjDump was not found, skipping")
            if lib_re.search(loop.comment) or \
                    lib_re.search(loop.operations[0].repr()):
                # do not care for _optimize_charset or _mk_bitmap
                continue
            assert loop.count > 0
            if ' is_prime, ' in loop.comment:
                is_prime_loops.append(loop)
            elif ' fn_with_bridges, ' in loop.comment:
                fn_with_bridges_loops.append(loop)
            else:
                assert ' bridge ' in loop.comment
                key = mangle_descr(loop.descr)
                assert key not in bridges
                bridges[key] = loop

        by_count = lambda l: -l.count
        is_prime_loops.sort(key=by_count)
        fn_with_bridges_loops.sort(key=by_count)

        # check that we can find bridges corresponding to " % 3" and " % 5"
        mod_bridges = []
        for op in fn_with_bridges_loops[0].operations:
            if op.descr is not None:
                bridge = bridges.get(mangle_descr(op.descr))
                if bridge is not None:
                    mod_bridges.append(bridge)
        assert len(mod_bridges) in (1, 2)

        # check that counts are reasonable (precise # may change in the future)
        assert N - 2000 < sum(l.count for l in fn_with_bridges_loops) < N