Messages in this thread Patch in this message | | | From | Namhyung Kim <> | Subject | [PATCH 11/15] perf hists: Sort hist entries by accumulated period | Date | Thu, 13 Sep 2012 16:20:07 +0900 |
| |
From: Namhyung Kim <namhyung.kim@lge.com>
When symbol_conf.cumulate_callchain is requested, we need to sort the entries by accumulated period value. To do this, separate out the compare routine to hists__output_cmp().
In addition, if accumulated periods of two entries are same (i.e. single path callchain) put the caller above since accumulation tends to put callers on higher position for obvious reason.
Cc: Arun Sharma <asharma@fb.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org> --- tools/perf/util/hist.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 2b629f460889..53ca74f1979a 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -628,6 +628,23 @@ void hists__collapse_resort_threaded(struct hists *hists) * reverse the map, sort on period. */ +static int hists__output_cmp(struct hist_entry *left, struct hist_entry *right) +{ + int cmp = left->stat.period > right->stat.period; + + if (symbol_conf.cumulate_callchain) { + /* + * Put caller above callee when they have equal period. + */ + if (left->stat_acc->period == right->stat_acc->period) + cmp = left->callchain->max_depth < right->callchain->max_depth; + else + cmp = left->stat_acc->period > right->stat_acc->period; + } + + return cmp; +} + static void __hists__insert_output_entry(struct rb_root *entries, struct hist_entry *he, u64 min_callchain_hits) @@ -644,7 +661,7 @@ static void __hists__insert_output_entry(struct rb_root *entries, parent = *p; iter = rb_entry(parent, struct hist_entry, rb_node); - if (he->stat.period > iter->stat.period) + if (hists__output_cmp(he, iter)) p = &(*p)->rb_left; else p = &(*p)->rb_right; -- 1.7.11.4
| |