def clean_line_profile_text(text): """ Sorts the output from line profile by execution time Removes entries which were not run """ # Use a regluar expression to find profile delimeters list_ = regex_split('^File: ', text) for ix in xrange(1, len(list_)): list_[ix] = 'File: ' + list_[ix] # Build a map from times to line_profile blocks prefix_list = [] timemap = defaultdict(list) for ix in xrange(len(list_)): block = list_[ix] total_time = get_block_totaltime(block) # Blocks without time go at the front of sorted output if total_time is None: prefix_list.append(block) # Blocks that are not run are not appended to output elif total_time != 0: timemap[total_time].append(block) # Sort the blocks by time sorted_lists = sorted(six.iteritems(timemap), key=operator.itemgetter(0)) newlist = prefix_list[:] for key, val in sorted_lists: newlist.extend(val) # Rejoin output text output_text = '\n'.join(newlist) return output_text
def clean_line_profile_text(text): """ Sorts the output from line profile by execution time Removes entries which were not run """ # # Split the file into blocks along delimters and and put delimeters back in the list delim = 'Total time: ' #delim = 'File: ' list_ = utool.regex_split('^' + delim, text) for ix in range(1, len(list_)): list_[ix] = delim + list_[ix] # # Build a map from times to line_profile blocks prefix_list = [] timemap = utool.ddict(list) for ix in range(len(list_)): block = list_[ix] total_time = get_block_totaltime(block) # Blocks without time go at the front of sorted output if total_time is None: prefix_list.append(block) # Blocks that are not run are not appended to output elif total_time != 0: timemap[total_time].append(block) # Sort the blocks by time sorted_lists = sorted(six.iteritems(timemap), key=operator.itemgetter(0)) newlist = prefix_list[:] for key, val in sorted_lists: newlist.extend(val) # Rejoin output text output_text = '\n'.join(newlist) return output_text
def parse_rawprofile_blocks(text): """ Split the file into blocks along delimters and and put delimeters back in the list """ # The total time reported in the raw output is from pystone not kernprof # The pystone total time is actually the average time spent in the function delim = 'Total time: ' delim2 = 'Pystone time: ' #delim = 'File: ' profile_block_list = ut.regex_split('^' + delim, text) for ix in range(1, len(profile_block_list)): profile_block_list[ix] = delim2 + profile_block_list[ix] return profile_block_list