Example #1
0
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
Example #2
0
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
Example #3
0
def main(progname, logfilename, outfilename):
    storage = LoopStorage(extrapath=os.path.dirname(progname))
    log, loops = import_log(logfilename)
    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)
    json.dump([loop.force_asm().as_json() for loop in storage.loops],
              open(outfilename, "w"), indent=4)
Example #4
0
def main(progname, logfilename, outfilename):
    storage = LoopStorage(extrapath=os.path.dirname(progname))
    log, loops = import_log(logfilename)
    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)
    json.dump([loop.force_asm().as_json() for loop in storage.loops],
              open(outfilename, "w"),
              indent=4)
Example #5
0
    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, 3)

        # 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 + 1500
Example #6
0
    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, 3)

        # 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 + 1000