aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2014-03-03 00:18:00 -0500
committerJiri Olsa <jolsa@kernel.org>2014-05-21 05:45:34 -0400
commit043ca389a3181565b5c19d43a55eae111977d13d (patch)
treeecba0c7e69814f42dae9b208414574b765b3a1e2 /tools/perf
parentf156d84e427c9e1a855a4bb41156c7d82d87fb47 (diff)
perf tools: Use hpp formats to sort final output
Convert output sorting function to use ->sort hpp functions. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Acked-by: Ingo Molnar <mingo@kernel.org> Link: http://lkml.kernel.org/r/1400480762-22852-6-git-send-email-namhyung@kernel.org Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/util/hist.c62
1 files changed, 8 insertions, 54 deletions
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 38373c986e97..c99ae4dd973e 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -564,64 +564,18 @@ void hists__collapse_resort(struct hists *hists, struct ui_progress *prog)
564 } 564 }
565} 565}
566 566
567/* 567static int hist_entry__sort(struct hist_entry *a, struct hist_entry *b)
568 * reverse the map, sort on period.
569 */
570
571static int period_cmp(u64 period_a, u64 period_b)
572{ 568{
573 if (period_a > period_b) 569 struct perf_hpp_fmt *fmt;
574 return 1; 570 int64_t cmp = 0;
575 if (period_a < period_b)
576 return -1;
577 return 0;
578}
579
580static int hist_entry__sort_on_period(struct hist_entry *a,
581 struct hist_entry *b)
582{
583 int ret;
584 int i, nr_members;
585 struct perf_evsel *evsel;
586 struct hist_entry *pair;
587 u64 *periods_a, *periods_b;
588
589 ret = period_cmp(a->stat.period, b->stat.period);
590 if (ret || !symbol_conf.event_group)
591 return ret;
592
593 evsel = hists_to_evsel(a->hists);
594 nr_members = evsel->nr_members;
595 if (nr_members <= 1)
596 return ret;
597
598 periods_a = zalloc(sizeof(periods_a) * nr_members);
599 periods_b = zalloc(sizeof(periods_b) * nr_members);
600
601 if (!periods_a || !periods_b)
602 goto out;
603
604 list_for_each_entry(pair, &a->pairs.head, pairs.node) {
605 evsel = hists_to_evsel(pair->hists);
606 periods_a[perf_evsel__group_idx(evsel)] = pair->stat.period;
607 }
608
609 list_for_each_entry(pair, &b->pairs.head, pairs.node) {
610 evsel = hists_to_evsel(pair->hists);
611 periods_b[perf_evsel__group_idx(evsel)] = pair->stat.period;
612 }
613 571
614 for (i = 1; i < nr_members; i++) { 572 perf_hpp__for_each_format(fmt) {
615 ret = period_cmp(periods_a[i], periods_b[i]); 573 cmp = fmt->sort(a, b);
616 if (ret) 574 if (cmp)
617 break; 575 break;
618 } 576 }
619 577
620out: 578 return cmp;
621 free(periods_a);
622 free(periods_b);
623
624 return ret;
625} 579}
626 580
627static void hists__reset_filter_stats(struct hists *hists) 581static void hists__reset_filter_stats(struct hists *hists)
@@ -669,7 +623,7 @@ static void __hists__insert_output_entry(struct rb_root *entries,
669 parent = *p; 623 parent = *p;
670 iter = rb_entry(parent, struct hist_entry, rb_node); 624 iter = rb_entry(parent, struct hist_entry, rb_node);
671 625
672 if (hist_entry__sort_on_period(he, iter) > 0) 626 if (hist_entry__sort(he, iter) > 0)
673 p = &(*p)->rb_left; 627 p = &(*p)->rb_left;
674 else 628 else
675 p = &(*p)->rb_right; 629 p = &(*p)->rb_right;