Пример #1
0
def test_tree_jit():
    profiles = [([1], 1, 1),
                ([1, AssemblerCode(100), JittedCode(1)], 1, 1)]
    stats = Stats(profiles, adr_dict={1: 'foo'})
    tree = stats.get_tree()
    assert tree == Node(1, 'foo', 2)
    assert tree.meta['jit'] == 1
Пример #2
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
Пример #3
0
def test_tree_gc():
    profiles = [([VirtualFrame(1)], 1, 1),
                ([VirtualFrame(1), MinorGCFrame(100)], 1, 1)]
    stats = Stats(profiles, adr_dict={1: 'foo', 100: 'gc_collect'})
    tree = stats.get_tree()
    assert tree == Node(1, 'foo', 2)
    assert tree.meta['gc:minor'] == 1
Пример #4
0
def test_read_bit_by_bit():
    tmpfile = tempfile.NamedTemporaryFile(delete=False)
    vmprof.enable(tmpfile.fileno())
    function_foo()
    vmprof.disable()
    tmpfile.close()
    with open(tmpfile.name, "rb") as f:
        period, profiles, virtual_symbols, interp_name = read_prof_bit_by_bit(f)
        stats = Stats(profiles, virtual_symbols, interp_name)
        stats.get_tree()
Пример #5
0
def test_read_bit_by_bit():
    tmpfile = tempfile.NamedTemporaryFile(delete=False)
    vmprof.enable(tmpfile.fileno())
    function_foo()
    vmprof.disable()
    tmpfile.close()
    with open(tmpfile.name, 'rb') as f:
        period, profiles, virtual_symbols, interp_name = read_prof_bit_by_bit(
            f)
        stats = Stats(profiles, virtual_symbols, interp_name)
        stats.get_tree()
Пример #6
0
def test_tree_basic():
    profiles = [([VirtualFrame(1), VirtualFrame(2)], 1, 1),
                ([VirtualFrame(1), VirtualFrame(2)], 1, 1)]
    stats = Stats(profiles, adr_dict={1: 'foo', 2: 'bar'})
    tree = stats.get_tree()
    assert tree == Node(1, 'foo', 2, {2: Node(2, 'bar', 2)})
    assert repr(tree) == '<Node: foo (2) [(2, bar)]>'

    profiles = [([VirtualFrame(1), VirtualFrame(2)], 1, 1),
                ([VirtualFrame(1), VirtualFrame(3)], 1, 1)]
    stats = Stats(profiles, adr_dict={1: 'foo', 2: 'bar', 3: 'baz'})
    tree = stats.get_tree()
    assert tree == Node(1, 'foo', 2, {
        2: Node(2, 'bar', 1),
        3: Node(3, 'baz', 1)})
Пример #7
0
def test_line_profiling():
    tmpfile = tempfile.NamedTemporaryFile(delete=False)
    vmprof.enable(tmpfile.fileno(), lines=True)  # enable lines profiling
    function_foo()
    vmprof.disable()
    tmpfile.close()

    def walk(tree):
        assert len(tree.lines) >= len(tree.children)

        for v in six.itervalues(tree.children):
            walk(v)

    with open(tmpfile.name, "rb") as f:
        period, profiles, virtual_symbols, interp_name = read_prof_bit_by_bit(f)
        stats = Stats(profiles, virtual_symbols, interp_name)
        walk(stats.get_tree())
Пример #8
0
def read_profile(prof_filename):
    prof = open(str(prof_filename), 'rb')

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

    jit_frames = {}
    d = dict(virtual_symbols)
    s = Stats(profiles, d, jit_frames, interp_name)
    return s
Пример #9
0
def test_line_profiling():
    tmpfile = tempfile.NamedTemporaryFile(delete=False)
    vmprof.enable(tmpfile.fileno(), lines=True)  # enable lines profiling
    function_foo()
    vmprof.disable()
    tmpfile.close()

    def walk(tree):
        assert len(tree.lines) >= len(tree.children)

        for v in six.itervalues(tree.children):
            walk(v)

    with open(tmpfile.name, 'rb') as f:
        period, profiles, virtual_symbols, interp_name = read_prof_bit_by_bit(
            f)
        stats = Stats(profiles, virtual_symbols, interp_name)
        walk(stats.get_tree())
Пример #10
0
def read_profile(prof_file):
    if not hasattr(prof_file, 'read'):
        prof_file = open(str(prof_file), 'rb')

    period, profiles, virtual_symbols, interp_name = read_prof(prof_file)

    jit_frames = {}
    d = dict(virtual_symbols)
    s = Stats(profiles, d, jit_frames, interp=interp_name)
    return s
Пример #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_tree_basic():
    profiles = [([1, 2], 1, 1), ([1, 2], 1, 1)]
    stats = Stats(profiles, adr_dict={1: 'foo', 2: 'bar'})
    tree = stats.get_tree()
    assert tree == Node(1, 'foo', 2, {2: Node(2, 'bar', 2)})
    assert repr(tree) == '<Node: foo (2) [(2, bar)]>'

    profiles = [([1, 2], 1, 1), ([1, 3], 1, 1)]
    stats = Stats(profiles, adr_dict={1: 'foo', 2: 'bar', 3: 'baz'})
    tree = stats.get_tree()
    assert tree == Node(1, 'foo', 2, {
        2: Node(2, 'bar', 1),
        3: Node(3, 'baz', 1)
    })
Пример #13
0
def read_profile(prof_file):
    file_to_close = None
    if not hasattr(prof_file, 'read'):
        prof_file = file_to_close = open(str(prof_file), 'rb')

    period, profiles, virtual_symbols, interp_name, meta, start_time, end_time = read_prof(
        prof_file)

    if file_to_close:
        file_to_close.close()

    jit_frames = {}
    d = dict(virtual_symbols)
    s = Stats(profiles,
              d,
              jit_frames,
              interp=interp_name,
              start_time=start_time,
              end_time=end_time,
              meta=meta)
    return s
Пример #14
0
def read_profile(prof_file):
    file_to_close = None
    if not hasattr(prof_file, 'read'):
        prof_file = file_to_close = open(str(prof_file), 'rb')

    state = _read_prof(prof_file)

    if file_to_close:
        file_to_close.close()

    jit_frames = {}
    d = dict(state.virtual_ips)
    s = Stats(state.profiles,
              d,
              jit_frames,
              interp=state.interp_name,
              start_time=state.start_time,
              end_time=state.end_time,
              meta=state.meta,
              state=state)
    return s
Пример #15
0
def test_tree_jit():
    profiles = [([1], 1, 1), ([1, AssemblerCode(100), JittedCode(1)], 1, 1)]
    stats = Stats(profiles, adr_dict={1: 'foo'})
    tree = stats.get_tree()
    assert tree == Node(1, 'foo', 2)
    assert tree.meta['jit'] == 1