Example #1
0
def test_get_level(filename):

    call_tree = ct.get_call_tree(filename)

    # testing series version
    df = ct.calltree_to_df(call_tree).set_index('Cnode ID')

    parent_series = df['Parent Cnode ID']

    levels = ct.get_level(parent_series)

    for cnode_id in levels.index:
        assert levels[cnode_id] == 0 or levels[cnode_id] == levels[
            parent_series[cnode_id]] + 1

    # testing df version
    df = ct.calltree_to_df(call_tree)

    parent_series_2 = df[['Cnode ID', 'Parent Cnode ID']]

    levels_2 = ct.get_level(parent_series_2)

    for cnode_id in levels_2.index:
        #assert levels_2[cnode_id] == 0 or levels_2[cnode_id] == levels_2[parent_series_2.set_index('Cnode ID')[cnode_id]] + 1
        assert levels_2[cnode_id] == 0 or levels_2[cnode_id] == levels_2[
            parent_series_2.set_index('Cnode ID').loc[cnode_id,
                                                      'Parent Cnode ID']] + 1
Example #2
0
def test_calltree2(filename):
    call_tree = get_call_tree(filename)
    call_tree_df = calltree_to_df(call_tree, full_path=True)

    print("Calltree:")
    print(call_tree)
    print("Dataframe representation of calltree:")
    print(call_tree_df)
Example #3
0
def convert_df_to_inclusive(df_convertible, call_tree):
    """
    Converts a DataFrame from exclusive to inclusive. A level named
    ``Cnode ID``, ``Full Callpath`` or ``Short Callpath`` must be in the index.

    Parameters
    ----------
    df_convertible : pandas.DataFrame
        A DataFrame containing only metrics that can be converted safely from
        exclusive to inclusive.
    call_tree: CubeTreeNode
        A recursive representation of the call tree.

    Returns
    -------
    res : DataFrame
        A DataFrame

    """

    old_index_name = ic.find_index_col(df_convertible)

    # dfcr = df_convertible_reindexed
    tree_df = ct.calltree_to_df(call_tree)
    dfcr = ic.convert_index(df_convertible, tree_df, target="Cnode ID")

    levels_to_unstack = [
        name for name in df_convertible.index.names if name != "Cnode ID"
    ]
    df_transposed = df_convertible.unstack(levels_to_unstack)

    def aggregate(root):
        value = df_transposed.loc[root.cnode_id, :]
        for child in root.children:
            value += aggregate(child)
        return value

    names = df_transposed.columns.names

    return (pd.concat(
        objs=[aggregate(n) for n in ct.iterate_on_call_tree(call_tree)],
        keys=[n.cnode_id for n in ct.iterate_on_call_tree(call_tree)],
    ).rename_axis(mapper=["Cnode ID"] + names,
                  axis="index").unstack(names).pipe(
                      ic.convert_index, tree_df,
                      old_index_name).stack(levels_to_unstack))
Example #4
0
def process_cubex(profile_file, exclusive=True):
    """
    Processes a single ``.cubex`` file, returning the numeric data from the 
    profiling, plus information about the call tree and the metrics.

    Note: returns a *dict*.

    Parameters
    ----------
    profile_file : str
        The name of the ``.cubex`` file.
    exclusive : bool
        Whether to ask ``cube_dump`` for exclusive (True) or inclusive (False) 
        metrics.

    Returns
    -------
    ctree : calltree.CubeTreeNode
        A call tree recursive object
    ctree_df : pandas.DataFrame
        A DataFrame representation of the call tree object
    df : pandas.DataFrame
        A dataframe containing the profiling data, from 
    conv_info : list
        convertibility information (to inclusive) for the metrics contained
        in the dump.

    """
    # Getting all callgraph information
    logging.debug(f"Reading {profile_file}...")

    ctree = ct.get_call_tree(profile_file)
    ctree_df = ct.calltree_to_df(ctree, full_path=True)
    dump_df = (
        cfu.get_dump(profile_file, exclusive)  #
        .rename_axis('metric', axis='columns')  #
        .set_index(['Cnode ID', 'Thread ID']))  #

    conv_info = mt.get_inclusive_convertible_metrics(profile_file)

    return Box({
        'ctree': ctree,
        'ctree_df': ctree_df,
        'df': dump_df,
        'conv_info': conv_info
    })
Example #5
0
def test_calltree1(filename):
    '''
    This script runs the algorithm, prints the results, and checks 
    that the representation of the call tree matches the one that is 
    "scraped" from the cube_dump output.
    '''
    cube_dump_w_text = get_cube_dump_w_text(filename)
    call_tree_lines = ct.get_call_tree_lines(cube_dump_w_text)
    calltree = ct.calltree_from_lines(call_tree_lines)
    max_len = ct.get_max_len(calltree)
    calltree_repr = ct.calltree_to_string(calltree, max_len)
    print("Tree Representation:")
    print(calltree_repr)
    
    import pandas as pd
    data = ct.get_fpath_vs_id(calltree)
    df = pd.DataFrame(data, columns=['Cnode ID', 'Full Callpath'])
    print("Cnode ID vs. Full Callpath dictionary:")
    print(df)
    
    df = ct.calltree_to_df(calltree)
    print("Dataframe representation of the Call Tree:")
    print(df)
    
    # testing that the tree representation matches the one in the 
    # cube_dump output
    import re
    def clean_line(line):
        l1 = re.sub(r'\s*\[\s*\(\s*id=([0-9]+).*$', r'\g<1>', line)
        return re.sub(r'\s*\[with.*\]\s*','',l1)
    reference = (re.sub(
        r'[:|-]', '', '\n'.join([
            clean_line(line)
            for line in ct.get_call_tree_lines(cube_dump_w_text)
        ])))
    
    calltree_repr = (re.sub(r'[\-:]', '',
                            ct.calltree_to_string(calltree, 0)).replace(
                                '|', ' ').replace('   ', '  '))
    
    for i, (linea, lineb) in enumerate(
            zip(reference.split('\n'), calltree_repr.split('\n'))):
        assert linea == lineb, f" Line {i}: '{linea}' != '{lineb}'"
Example #6
0
    cube_dump_w_text = get_cube_dump_w_text(argv[1])
    call_tree_lines = ct.get_call_tree_lines(cube_dump_w_text)
    calltree = ct.calltree_from_lines(call_tree_lines)
    max_len = ct.get_max_len(calltree)
    calltree_repr = ct.calltree_to_string(calltree, max_len)
    print("Tree Representation:")
    print(calltree_repr)

    import pandas as pd
    data = ct.get_fpath_vs_id(calltree)
    df = pd.DataFrame(data, columns=['Cnode ID', 'Full Callpath'])
    print("Cnode ID vs. Full Callpath dictionary:")
    print(df)

    df = ct.calltree_to_df(calltree)
    print("Dataframe representation of the Call Tree:")
    print(df)

    # testing that the tree representation matches the one in the
    # cube_dump output
    import re
    reference = (re.sub(
        '[|-]', '', '\n'.join([
            re.sub('\s*\[\s*\(\s*id=([0-9]+).*$', '\g<1>', line)
            for line in ct.get_call_tree_lines(cube_dump_w_text)
        ])))

    calltree_repr = (re.sub('[\-:]', '',
                            ct.calltree_to_string(calltree, 0)).replace(
                                '|', ' ').replace('   ', '  '))
Example #7
0
#!/usr/bin/env python3
'''
This script runs only a convenient function that returns all the info in 
a pandas dataframe.
'''

if __name__ == '__main__':
    from sys import argv
    from calltree import get_call_tree, calltree_to_df
    from cube_file_utils import get_cube_dump_w_text

    call_tree = get_call_tree(argv[1])
    call_tree_df = calltree_to_df(call_tree, full_path=True)

    print("Calltree:")
    print(call_tree)
    print("Dataframe representation of calltree:")
    print(call_tree_df)