Skip to content
Snippets Groups Projects
Commit 1d7b6125 authored by Tomasz Grabiec's avatar Tomasz Grabiec Committed by Pekka Enberg
Browse files

trace: introduce --group-by option


This option will allow to introduce more grouping criterias than just
by thread. It replaces -m|--merge-threads option. Now by default there
is no grouping. Samples can be grouped by thread by passing '-g
thread'.

Signed-off-by: default avatarTomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
parent 80fabe7e
No related branches found
No related tags found
No related merge requests found
......@@ -142,14 +142,17 @@ def find_frame_index(frames, name):
return i
return None
def print_profile(samples, symbol_resolver, caller_oriented=False, merge_threads=True,
printer=sys.stdout.write, time_range=None, src_addr_formatter=debug.SourceAddress.__str__,
node_filter=None, order=None, root_function=None, max_levels=None):
thread_profiles = {}
class GroupByThread:
def get_group(self, sample):
return sample.thread
def format(self, group):
return 'Thread 0x%x' % group
if merge_threads:
root = ProfNode('All')
thread_profiles['All'] = root
def print_profile(samples, symbol_resolver, caller_oriented=False,
printer=sys.stdout.write, time_range=None, src_addr_formatter=debug.SourceAddress.__str__,
node_filter=None, order=None, root_function=None, max_levels=None, grouping=None):
groups = {}
for sample in samples:
if time_range:
......@@ -170,13 +173,11 @@ def print_profile(samples, symbol_resolver, caller_oriented=False, merge_threads
frames = None
if frames:
if merge_threads:
node = root
else:
node = thread_profiles.get(sample.thread, None)
if not node:
node = ProfNode('All')
thread_profiles[sample.thread] = node
key = grouping.get_group(sample) if grouping else None
node = groups.get(key, None)
if not node:
node = ProfNode('All')
groups[key] = node
node.hit(sample.resident_time)
for src_addr in frames:
......@@ -204,14 +205,14 @@ def print_profile(samples, symbol_resolver, caller_oriented=False, merge_threads
if not order:
order = lambda node: (-node.resident_time, -node.hit_count)
for thread, tree_root in sorted(thread_profiles.iteritems(), key=lambda (thread, node): order(node)):
for group, tree_root in sorted(groups.iteritems(), key=lambda (thread, node): order(node)):
collapse_similar(tree_root)
if max_levels:
strip_level(tree_root, max_levels)
if not merge_threads:
printer("\n=== Thread 0x%x ===\n\n" % thread)
if grouping:
printer('\n=== ' + grouping.format(group) + ' ===\n\n')
tree.print_tree(tree_root,
formatter=lambda node: format_node(node, tree_root),
......
......@@ -108,11 +108,16 @@ def add_time_slicing_options(parser):
the amount of time passed in this option will be used to calculate the other. The value is interpreted
as nanoseconds unless unit is specified, eg: 500us""")
groupers = {
'thread': prof.GroupByThread,
'none': lambda: None,
}
def add_profile_options(parser):
add_time_slicing_options(parser)
group = parser.add_argument_group('profile options')
group.add_argument("-r", "--caller-oriented", action='store_true', help="change orientation to caller-based; reverses order of frames")
group.add_argument("-m", "--merge-threads", action='store_true', help="show one merged tree for all threads")
group.add_argument("-g", "--group-by", choices=groupers.keys(), default='none', help="show one merged tree for all threads")
group.add_argument("--function", action='store', help="use given function as tree root")
group.add_argument("--min-duration", action='store', help="show only nodes with resident time not shorter than this, eg: 200ms")
group.add_argument("--max-levels", type=int, action='store', help="maximum number of tree levels to show")
......@@ -152,7 +157,7 @@ def show_profile(args, sample_producer):
prof.print_profile(sample_producer(reader.get_traces()),
symbol_resolver=resolver,
caller_oriented=args.caller_oriented,
merge_threads=args.merge_threads,
grouping=groupers[args.group_by](),
src_addr_formatter=src_addr_formatter(args),
root_function=args.function,
node_filter=node_filter,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment