def get_metric_by_function(inpfilename): ''' get depth level for each function in the call tree ''' print(f"Processing {inpfilename}...") call_tree = ct.get_call_tree(inpfilename) func_node = next(node for node in ct.iterate_on_call_tree(call_tree) if node.fname == funcname) children_info = [ node.fname + "," + str(node.cnode_id) for node in ct.iterate_on_call_tree(func_node, 1) ] ##### # output_i = mg.process_cubex(inpfilename, exclusive=exclincl) # We convert the Cnode IDs to short callpaths in the dataframe. df_i = ic.convert_index(output_i.df, output_i.ctree_df, target='Short Callpath') res_df = df_i.loc[children_info] res = res_df.reset_index()[[ 'Short Callpath', 'Thread ID', metric ]].groupby('Short Callpath').sum().sort_values([metric], ascending=False)[metric] res = res.head(11 if len(res) > 11 else len(res)) return res
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
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)
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 })
def test_convert_df_to_inclusive(input_file): ''' This test checks that the function to compute the inclusive data from the exclusive data yields the same values as the ones obtained from `cube_dump` using the 'incl' flag. ''' convertible_metrics = mt.get_inclusive_convertible_metrics(input_file) def get_df(exclusive): return (cfu.get_dump(profile_file=input_file, exclusive=exclusive) .set_index([ 'Cnode ID', 'Thread ID' ]) .rename_axis(mapper=['metric'], axis='columns') .sort_index()) dump_excl = get_df(exclusive = True) dump_incl = get_df(exclusive = False) calltree = ct.get_call_tree(input_file) # dataframe conversion dump_excl = cc.select_metrics( dump_excl, convertible_metrics) dump_incl_comp = cc.convert_df_to_inclusive(dump_excl, calltree).sort_index() dump_incl = cc.select_metrics(dump_incl, convertible_metrics) assert (dump_excl.values != dump_incl.values).any() print("Inclusive and exclusive results partially differ as expected.") assert (dump_excl.values == dump_incl.values).any() print("Inclusive and exclusive results are partially equal as expected.") tu.check_float_equality(dump_incl_comp,dump_incl) print( "Results from convert_df_to_inclusive coincide with the ones coming from cube_dump." ) # series conversion def transform(df): return df.unstack( [ name for name in df.index.names if name != 'Cnode ID' ] ) dump_excl = transform(dump_excl) dump_incl = transform(dump_incl) for col in dump_excl: print(f"Processing column {col}...") series_excl = dump_excl[col] series_incl = dump_incl[col] series_incl_comp = cc.convert_series_to_inclusive(series_excl, calltree).sort_index() assert any(series_excl != series_incl) print("Inclusive and exclusive results partially differ as expected.") assert any(series_excl == series_incl) print("Inclusive and exclusive results are partially equal as expected.") tu.check_float_equality(series_incl_comp,series_incl) print( "Results from conversion coincide with the ones coming from cube_dump." )
input_file = argv[1] convertible_metrics = mt.get_inclusive_convertible_metrics(input_file) def get_df(exclusive): return (cfu.get_dump(profile_file=input_file, exclusive=exclusive) .set_index([ 'Cnode ID', 'Thread ID' ]) .rename_axis(mapper=['metric'], axis='columns') .sort_index()) dump_excl = get_df(exclusive = True) dump_incl = get_df(exclusive = False) calltree = ct.get_call_tree(input_file) # dataframe conversion dump_excl = cc.select_metrics( dump_excl, convertible_metrics) dump_incl_comp = cc.convert_df_to_inclusive(dump_excl, calltree).sort_index() dump_incl = cc.select_metrics(dump_incl, convertible_metrics) assert (dump_excl.values != dump_incl.values).any() print("Inclusive and exclusive results partially differ as expected.") assert (dump_excl.values == dump_incl.values).any() print("Inclusive and exclusive results are partially equal as expected.") tu.check_float_equality(dump_incl_comp,dump_incl)
#!/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)