From: Namhyung Kim <namhyung....@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 <asha...@fb.com> Cc: Frederic Weisbecker <fweis...@gmail.com> Signed-off-by: Namhyung Kim <namhy...@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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/