aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/ui/browsers/hists.c
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung.kim@lge.com>2013-01-22 04:09:38 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-01-31 11:07:47 -0500
commit897014603c4786ef33450e675e02a5e74dc63785 (patch)
tree3f79f59a53f340f86044f8b5cd66ff6921a7228a /tools/perf/ui/browsers/hists.c
parent5b9e2146ec4f8c6d436f9f7043a0409a4296a705 (diff)
perf hists browser: Move coloring logic to hpp functions
Move coloring logic into the hpp functions so that each value can be colored independently. It'd required for event group view. For overhead column, add a callback for printing 'folded_sign' of callchains of a hist entry. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Ingo Molnar <mingo@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1358845787-1350-11-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/ui/browsers/hists.c')
-rw-r--r--tools/perf/ui/browsers/hists.c72
1 files changed, 42 insertions, 30 deletions
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 46242deee8d2..852e4e10c7c4 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -567,23 +567,48 @@ static int hist_browser__show_callchain(struct hist_browser *browser,
567 return row - first_row; 567 return row - first_row;
568} 568}
569 569
570struct hpp_arg {
571 struct ui_browser *b;
572 char folded_sign;
573 bool current_entry;
574};
575
576static int __hpp__color_callchain(struct hpp_arg *arg)
577{
578 if (!symbol_conf.use_callchain)
579 return 0;
580
581 slsmg_printf("%c ", arg->folded_sign);
582 return 2;
583}
584
570static int __hpp__color_fmt(struct perf_hpp *hpp, struct hist_entry *he, 585static int __hpp__color_fmt(struct perf_hpp *hpp, struct hist_entry *he,
571 u64 (*get_field)(struct hist_entry *)) 586 u64 (*get_field)(struct hist_entry *),
587 int (*callchain_cb)(struct hpp_arg *))
572{ 588{
573 int ret; 589 int ret = 0;
574 double percent = 0.0; 590 double percent = 0.0;
575 struct hists *hists = he->hists; 591 struct hists *hists = he->hists;
592 struct hpp_arg *arg = hpp->ptr;
576 593
577 if (hists->stats.total_period) 594 if (hists->stats.total_period)
578 percent = 100.0 * get_field(he) / hists->stats.total_period; 595 percent = 100.0 * get_field(he) / hists->stats.total_period;
579 596
580 *(double *)hpp->ptr = percent; 597 ui_browser__set_percent_color(arg->b, percent, arg->current_entry);
598
599 if (callchain_cb)
600 ret += callchain_cb(arg);
601
602 ret += scnprintf(hpp->buf, hpp->size, "%6.2f%%", percent);
603 slsmg_printf("%s", hpp->buf);
604
605 if (!arg->current_entry || !arg->b->navkeypressed)
606 ui_browser__set_color(arg->b, HE_COLORSET_NORMAL);
581 607
582 ret = scnprintf(hpp->buf, hpp->size, "%6.2f%%", percent);
583 return ret; 608 return ret;
584} 609}
585 610
586#define __HPP_COLOR_PERCENT_FN(_type, _field) \ 611#define __HPP_COLOR_PERCENT_FN(_type, _field, _cb) \
587static u64 __hpp_get_##_field(struct hist_entry *he) \ 612static u64 __hpp_get_##_field(struct hist_entry *he) \
588{ \ 613{ \
589 return he->stat._field; \ 614 return he->stat._field; \
@@ -592,14 +617,14 @@ static u64 __hpp_get_##_field(struct hist_entry *he) \
592static int hist_browser__hpp_color_##_type(struct perf_hpp *hpp, \ 617static int hist_browser__hpp_color_##_type(struct perf_hpp *hpp, \
593 struct hist_entry *he) \ 618 struct hist_entry *he) \
594{ \ 619{ \
595 return __hpp__color_fmt(hpp, he, __hpp_get_##_field); \ 620 return __hpp__color_fmt(hpp, he, __hpp_get_##_field, _cb); \
596} 621}
597 622
598__HPP_COLOR_PERCENT_FN(overhead, period) 623__HPP_COLOR_PERCENT_FN(overhead, period, __hpp__color_callchain)
599__HPP_COLOR_PERCENT_FN(overhead_sys, period_sys) 624__HPP_COLOR_PERCENT_FN(overhead_sys, period_sys, NULL)
600__HPP_COLOR_PERCENT_FN(overhead_us, period_us) 625__HPP_COLOR_PERCENT_FN(overhead_us, period_us, NULL)
601__HPP_COLOR_PERCENT_FN(overhead_guest_sys, period_guest_sys) 626__HPP_COLOR_PERCENT_FN(overhead_guest_sys, period_guest_sys, NULL)
602__HPP_COLOR_PERCENT_FN(overhead_guest_us, period_guest_us) 627__HPP_COLOR_PERCENT_FN(overhead_guest_us, period_guest_us, NULL)
603 628
604#undef __HPP_COLOR_PERCENT_FN 629#undef __HPP_COLOR_PERCENT_FN
605 630
@@ -626,7 +651,6 @@ static int hist_browser__show_entry(struct hist_browser *browser,
626 unsigned short row) 651 unsigned short row)
627{ 652{
628 char s[256]; 653 char s[256];
629 double percent;
630 int printed = 0; 654 int printed = 0;
631 int width = browser->b.width; 655 int width = browser->b.width;
632 char folded_sign = ' '; 656 char folded_sign = ' ';
@@ -646,16 +670,20 @@ static int hist_browser__show_entry(struct hist_browser *browser,
646 } 670 }
647 671
648 if (row_offset == 0) { 672 if (row_offset == 0) {
673 struct hpp_arg arg = {
674 .b = &browser->b,
675 .folded_sign = folded_sign,
676 .current_entry = current_entry,
677 };
649 struct perf_hpp hpp = { 678 struct perf_hpp hpp = {
650 .buf = s, 679 .buf = s,
651 .size = sizeof(s), 680 .size = sizeof(s),
681 .ptr = &arg,
652 }; 682 };
653 int i = 0;
654 683
655 ui_browser__gotorc(&browser->b, row, 0); 684 ui_browser__gotorc(&browser->b, row, 0);
656 685
657 perf_hpp__for_each_format(fmt) { 686 perf_hpp__for_each_format(fmt) {
658
659 if (!first) { 687 if (!first) {
660 slsmg_printf(" "); 688 slsmg_printf(" ");
661 width -= 2; 689 width -= 2;
@@ -663,27 +691,11 @@ static int hist_browser__show_entry(struct hist_browser *browser,
663 first = false; 691 first = false;
664 692
665 if (fmt->color) { 693 if (fmt->color) {
666 hpp.ptr = &percent;
667 /* It will set percent for us. See __hpp__color_fmt above. */
668 width -= fmt->color(&hpp, entry); 694 width -= fmt->color(&hpp, entry);
669
670 ui_browser__set_percent_color(&browser->b, percent, current_entry);
671
672 if (!i && symbol_conf.use_callchain) {
673 slsmg_printf("%c ", folded_sign);
674 width -= 2;
675 }
676
677 slsmg_printf("%s", s);
678
679 if (!current_entry || !browser->b.navkeypressed)
680 ui_browser__set_color(&browser->b, HE_COLORSET_NORMAL);
681 } else { 695 } else {
682 width -= fmt->entry(&hpp, entry); 696 width -= fmt->entry(&hpp, entry);
683 slsmg_printf("%s", s); 697 slsmg_printf("%s", s);
684 } 698 }
685
686 i++;
687 } 699 }
688 700
689 /* The scroll bar isn't being used */ 701 /* The scroll bar isn't being used */