def _reformat_tree(self, node, total_samples): """Reformats call tree for the UI.""" stack_params = self._extract_stack_params(node, total_samples) func_name = '%s @ %s' % (stack_params[0], stack_params[1]) return { 'stack': stack_params, 'children': [ self._reformat_tree(child, total_samples) for child in node['children'] ], 'sampleCount': node['sampleCount'], 'colorHash': base_profiler.hash_name(func_name) }
def _format_tree(self, node, total_samples): """Reformats call tree for the UI.""" funcname, filename, _ = node['stack'] funcname = funcname.replace('<', '[').replace('>', ']') filename = filename.replace('<', '[').replace('>', ']') sample_percent = self._get_percentage( node['sampleCount'], total_samples) color_hash = base_profiler.hash_name('%s @ %s' % (funcname, filename)) return { 'stack': node['stack'], 'children': [self._format_tree(child, total_samples) for child in node['children']], 'sampleCount': node['sampleCount'], 'samplePercentage': sample_percent, 'colorHash': color_hash }
def _transform_stats(prof): """Post-processes obtained stats for UI.""" records = [] for info, params in prof.stats.items(): filename, lineno, funcname = info cum_calls, num_calls, time_per_call, cum_time, _ = params if prof.total_tt == 0: percentage = 0 else: percentage = round(100 * (cum_time / prof.total_tt), 4) cum_time = round(cum_time, 4) func_name = '%s @ %s' % (funcname, filename) color_hash = base_profiler.hash_name(func_name) records.append( (filename, lineno, funcname, cum_time, percentage, num_calls, cum_calls, time_per_call, filename, color_hash)) return sorted(records, key=operator.itemgetter(4), reverse=True)
def _transform_stats(self, prof): """Post-processes obtained stats for UI.""" records = [] for info, params in prof.stats.items(): filename, lineno, funcname = info cum_calls, num_calls, time_per_call, cum_time, _ = params if prof.total_tt == 0: percentage = 0 else: percentage = round(100 * (cum_time / prof.total_tt), 4) cum_time = round(cum_time, 4) funcname = funcname.replace('<', '[').replace('>', ']') filename = filename.replace('<', '[').replace('>', ']') func_name = '%s @ %s' % (funcname, filename) color_hash = base_profiler.hash_name(func_name) records.append( (filename, lineno, funcname, cum_time, percentage, num_calls, cum_calls, time_per_call, filename, color_hash)) return sorted(records, key=operator.itemgetter(4), reverse=True)