aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-diff.c
diff options
context:
space:
mode:
authorRamkumar Ramachandra <artagnon@gmail.com>2013-12-30 02:34:19 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-01-13 09:36:46 -0500
commit01f10bc85f538cd681d0a3338b97a33f308d944b (patch)
treec21da91aae7f0b9c91a12bfdab4a2c6c4f4e79ec /tools/perf/builtin-diff.c
parentf77c6e9c8f9c444cd44423df0c2708e86a06a696 (diff)
perf diff: Color the Delta column
Color the numbers in the Delta column using percent_color_snprintf(). Generalize the coloring function so that we can accommodate all three comparison methods in future patches: delta, ratio, and wdiff. Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Acked-by: Jiri Olsa <jolsa@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Link: http://lkml.kernel.org/r/1388388861-7931-3-git-send-email-artagnon@gmail.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-diff.c')
-rw-r--r--tools/perf/builtin-diff.c49
1 files changed, 48 insertions, 1 deletions
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 987cac3b4bba..6c3f220115ac 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -770,6 +770,45 @@ static int hpp__entry_baseline(struct hist_entry *he, char *buf, size_t size)
770 return ret; 770 return ret;
771} 771}
772 772
773static int __hpp__color_compare(struct perf_hpp_fmt *fmt,
774 struct perf_hpp *hpp, struct hist_entry *he,
775 int comparison_method)
776{
777 struct diff_hpp_fmt *dfmt =
778 container_of(fmt, struct diff_hpp_fmt, fmt);
779 struct hist_entry *pair = get_pair_fmt(he, dfmt);
780 double diff;
781 char pfmt[20] = " ";
782
783 if (!pair)
784 goto dummy_print;
785
786 switch (comparison_method) {
787 case COMPUTE_DELTA:
788 if (pair->diff.computed)
789 diff = pair->diff.period_ratio_delta;
790 else
791 diff = compute_delta(he, pair);
792
793 if (fabs(diff) < 0.01)
794 goto dummy_print;
795 scnprintf(pfmt, 20, "%%%+d.2f%%%%", dfmt->header_width - 1);
796 return percent_color_snprintf(hpp->buf, hpp->size,
797 pfmt, diff);
798 default:
799 BUG_ON(1);
800 }
801dummy_print:
802 return scnprintf(hpp->buf, hpp->size, "%*s",
803 dfmt->header_width, pfmt);
804}
805
806static int hpp__color_delta(struct perf_hpp_fmt *fmt,
807 struct perf_hpp *hpp, struct hist_entry *he)
808{
809 return __hpp__color_compare(fmt, hpp, he, COMPUTE_DELTA);
810}
811
773static void 812static void
774hpp__entry_unpair(struct hist_entry *he, int idx, char *buf, size_t size) 813hpp__entry_unpair(struct hist_entry *he, int idx, char *buf, size_t size)
775{ 814{
@@ -941,8 +980,16 @@ static void data__hpp_register(struct data__file *d, int idx)
941 fmt->entry = hpp__entry_global; 980 fmt->entry = hpp__entry_global;
942 981
943 /* TODO more colors */ 982 /* TODO more colors */
944 if (idx == PERF_HPP_DIFF__BASELINE) 983 switch (idx) {
984 case PERF_HPP_DIFF__BASELINE:
945 fmt->color = hpp__color_baseline; 985 fmt->color = hpp__color_baseline;
986 break;
987 case PERF_HPP_DIFF__DELTA:
988 fmt->color = hpp__color_delta;
989 break;
990 default:
991 break;
992 }
946 993
947 init_header(d, dfmt); 994 init_header(d, dfmt);
948 perf_hpp__column_register(fmt); 995 perf_hpp__column_register(fmt);