예제 #1
0
def test_read_profile(here):

    prof_path = os.path.join(here, 'test.prof')
    prof_content = open(prof_path, 'rb')

    period, profiles, symbols, ranges = read_prof(prof_content)

    assert ranges[5].name == '/lib/x86_64-linux-gnu/liblzma.so.5.0.0'
    assert ranges[5].start == 140682901667840
    assert ranges[5].end == 140682901803008

    # symbols contains all kinds of crap, reverse it
    sym_dict = {}
    for k, v in symbols:
        sym_dict[v] = k
    assert 'py:f:7:x.py' in sym_dict
    assert 'py:g:4:x.py' in sym_dict
    assert 'py:<module>:2:x.py' in sym_dict

    addrspace = AddressSpace([
        LibraryData('virtual',
                    0x7000000000000000,
                    0x7000000000010000,
                    True,
                    symbols=symbols)
    ])
    name, start_addr, is_virtual = addrspace.lookup(
        sym_dict['py:<module>:2:x.py'])
    assert name == 'py:<module>:2:x.py'
    assert is_virtual
예제 #2
0
def test_read_profile(here):

    prof_path = os.path.join(here, 'test.prof')
    prof_content = open(prof_path, 'rb')

    period, profiles, symbols, ranges, interp_name = read_prof(prof_content)

    assert ranges[5].name == '/lib/x86_64-linux-gnu/liblzma.so.5.0.0'
    assert ranges[5].start == 140682901667840
    assert ranges[5].end == 140682901803008

    # symbols contains all kinds of crap, reverse it
    sym_dict = {}
    for k, v in symbols:
        sym_dict[v] = k
    assert 'py:f:7:x.py' in sym_dict
    assert 'py:g:4:x.py' in sym_dict
    assert 'py:<module>:2:x.py' in sym_dict

    addrspace = AddressSpace([
        LibraryData(
            'virtual',
            0x7000000000000000,
            0x7000000000010000,
            True,
            symbols=symbols)
    ])
    name, start_addr, is_virtual, _ = addrspace.lookup(sym_dict['py:<module>:2:x.py'])
    assert name == 'py:<module>:2:x.py'
    assert is_virtual
예제 #3
0
def read_profile(prof_filename, lib_cache={}, extra_libs=None,
                 virtual_only=True, include_extra_info=True):
    prof = open(str(prof_filename), 'rb')

    period, profiles, virtual_symbols, libs, interp_name = read_prof(prof)

    if not virtual_only or include_extra_info:
        for i, lib in enumerate(libs):
            if lib.name in lib_cache:
                libs[i].get_symbols_from(lib_cache[lib.name])
            else:
                lib.read_object_data(lib.start)
                lib_cache[lib.name] = lib
    libs.append(
        LibraryData(
            '<virtual>',
            0x7000000000000000,
            0x7fffffffffffffff,
            True,
            symbols=virtual_symbols)
    )
    if extra_libs:
        libs += extra_libs
    addrspace = AddressSpace(libs)
    filtered_profiles, addr_set, jit_frames = addrspace.filter_addr(profiles,
        virtual_only, include_extra_info, interp_name)
    d = {}
    for addr in addr_set:
        name, _, _, _ = addrspace.lookup(addr)
        d[addr] = name
    if include_extra_info:
        d.update(addrspace.meta_data)
    s = Stats(filtered_profiles, d, jit_frames, interp_name)
    s.addrspace = addrspace
    return s
예제 #4
0
def read_profile(prof_filename,
                 lib_cache={},
                 extra_libs=None,
                 virtual_only=True):
    prof = open(prof_filename, 'rb')

    period, profiles, virtual_symbols, libs = read_prof(prof)

    if not virtual_only:
        for i, lib in enumerate(libs):
            if lib.name in lib_cache:
                libs[i] = lib_cache[lib.name]
            else:
                lib.read_object_data(lib.start)
                lib_cache[lib.name] = lib
    libs.append(
        LibraryData('<virtual>',
                    0x7000000000000000,
                    0x7fffffffffffffff,
                    True,
                    symbols=virtual_symbols))
    if extra_libs:
        libs += extra_libs
    addrspace = AddressSpace(libs)
    filtered_profiles, addr_set = addrspace.filter_addr(profiles, virtual_only)
    d = {}
    for addr in addr_set:
        name, _, _ = addrspace.lookup(addr)
        d[addr] = name
    return Stats(filtered_profiles, d)
예제 #5
0
 def test_filter_gc_frames(self):
     l = LibraryData('foo', 100, 200, True)
     l.symbols = [(101, 'py:one'), (105, 'py:two'), (107, 'py:three')]
     l2 = LibraryData("binary", 1000, 2000, False)
     l2.symbols = [(1500, "pypy_g_resume_in_blackhole")]
     addr_space = AddressSpace([l, l2])
     r = addr_space.filter_addr([
         ([1, 1, 1, 1500, 101, 105], 1, 1)])
     assert r[0][0][0] == [VirtualFrame(105), VirtualFrame(101), BlackholeWarmupFrame(1500)]
예제 #6
0
 def test_lookup(self):
     d = LibraryData("lib", 1234, 1300)
     d.symbols = [(1234, "a"), (1260, "b")]
     d2 = LibraryData("lib2", 1400, 1500)
     d2.symbols = []
     addr = AddressSpace([d, d2])
     fn, _, is_virtual, _ = addr.lookup(1350)
     assert fn == '0x0000000000000547'  # outside of range
     fn, _, is_virtual, _ = addr.lookup(1250)
     assert fn == "a"
예제 #7
0
 def test_lookup(self):
     d = LibraryData("lib", 1234, 1300)
     d.symbols = [(1234, "a"), (1260, "b")]
     d2 = LibraryData("lib2", 1400, 1500)
     d2.symbols = []
     addr = AddressSpace([d, d2])
     fn, _, is_virtual = addr.lookup(1350)
     assert fn == '0x0000000000000547'  # outside of range
     fn, _, is_virtual = addr.lookup(1250)
     assert fn == "a"
예제 #8
0
 def test_filter_jit_2(self):
     l = LibraryData("python", 100, 200, True)
     l.symbols = [(101, 'py:one'), (105, 'py:two'), (107, 'py:three')]
     addr_space = AddressSpace([l])
     r = addr_space.filter_addr([
         ([0x2222, 0x1111, 0x1, 100, 104, 0x2, 0x3333,
         0x1, 104, 106, 0x2], 1, 1)
         ], interp_name='pypy')
     assert r[0][0][0] == [JitAddr(0x3334), JittedVirtual(107),
                           JitAddr(0x1112),
                           JittedVirtual(105), JittedVirtual(101)]
예제 #9
0
 def test_filter_jit(self):
     l = LibraryData("lib", 100, 200, True)
     l.symbols = [(112, "py:one"), (113, "py:two")]
     addr_space = AddressSpace([l])
     r = addr_space.filter_addr([
         ([213, 0x1, 111, 112, 0x2], 1, 1)
         ], interp_name='pypy')
     assert r[0] == [([JitAddr(214), JittedVirtual(113), JittedVirtual(112)], 1, 1)]
     r = addr_space.filter_addr([
         ([111, 213, 0x1, 111, 112, 0x2], 1, 1)
         ], interp_name='pypy')
     assert r[0] == [([JitAddr(214), JittedVirtual(113), JittedVirtual(112)], 1, 1)]
예제 #10
0
 def test_filter_profiles(self):
     d = LibraryData("lib", 12, 20)
     d.symbols = [(12, "lib:a"), (15, "lib:b")]
     d2 = LibraryData("<virtual>", 1000, 1500, True, symbols=[
         (1000, "py:one"), (1010, "py:two"),
         ])
     addr_space = AddressSpace([d, d2])
     profiles = [([12, 17, 1007], 1),
                 ([12, 12, 12], 1),
                 ([1000, 1020, 17], 1)]
     profiles = addr_space.filter(profiles)
     assert profiles == [
         (["py:one"], 1),
         (["py:two", "py:one"], 1),
         ]
     p = Stats(profiles)
     assert p.functions == {"py:one": 2, "py:two": 1}
     assert p.function_profile("py:two") == ([('py:one', 1)], 1)
예제 #11
0
def read_profile(prof_filename,
                 lib_cache={},
                 extra_libs=None,
                 virtual_only=True,
                 include_extra_info=True):
    prof = open(str(prof_filename), 'rb')

    period, profiles, virtual_symbols, libs, interp_name = read_prof(prof)

    if not virtual_only or include_extra_info:
        exe_name = libs[0].name
        for lib in libs:
            executable = lib.name == exe_name
            if lib.name in lib_cache:
                lib.get_symbols_from(lib_cache[lib.name], executable)
            else:
                lib.read_object_data(executable)
                lib_cache[lib.name] = lib
    libs.append(
        LibraryData('<virtual>',
                    0x7000000000000000,
                    0x7fffffffffffffff,
                    True,
                    symbols=virtual_symbols))
    if extra_libs:
        libs += extra_libs
    addrspace = AddressSpace(libs)
    filtered_profiles, addr_set, jit_frames = addrspace.filter_addr(
        profiles, virtual_only, include_extra_info, interp_name)
    d = {}
    for addr in addr_set:
        name, _, _, lib = addrspace.lookup(addr)
        if lib is None:
            name = 'jit:' + name
        d[addr] = name
    if include_extra_info:
        d.update(addrspace.meta_data)
    s = Stats(filtered_profiles, d, jit_frames, interp_name)
    s.addrspace = addrspace
    return s
예제 #12
0
 def test_filter_profiles(self):
     d = LibraryData("lib", 12, 20)
     d.symbols = [(12, "lib:a"), (15, "lib:b")]
     d2 = LibraryData("<virtual>",
                      1000,
                      1500,
                      True,
                      symbols=[
                          (1000, "py:one"),
                          (1010, "py:two"),
                      ])
     addr_space = AddressSpace([d, d2])
     profiles = [([12, 17, 1007], 1), ([12, 12, 12], 1),
                 ([1000, 1020, 17], 1)]
     profiles = addr_space.filter(profiles)
     assert profiles == [
         (["py:one"], 1),
         (["py:two", "py:one"], 1),
     ]
     p = Stats(profiles)
     assert p.functions == {"py:one": 2, "py:two": 1}
     assert p.function_profile("py:two") == ([('py:one', 1)], 1)