diff options
| -rw-r--r-- | tools/perf/builtin-diff.c | 20 | ||||
| -rw-r--r-- | tools/perf/util/color.c | 10 | ||||
| -rw-r--r-- | tools/perf/util/color.h | 1 |
3 files changed, 28 insertions, 3 deletions
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 6c3f220115ac..73d8bffdd484 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c | |||
| @@ -795,6 +795,17 @@ static int __hpp__color_compare(struct perf_hpp_fmt *fmt, | |||
| 795 | scnprintf(pfmt, 20, "%%%+d.2f%%%%", dfmt->header_width - 1); | 795 | scnprintf(pfmt, 20, "%%%+d.2f%%%%", dfmt->header_width - 1); |
| 796 | return percent_color_snprintf(hpp->buf, hpp->size, | 796 | return percent_color_snprintf(hpp->buf, hpp->size, |
| 797 | pfmt, diff); | 797 | pfmt, diff); |
| 798 | case COMPUTE_RATIO: | ||
| 799 | if (he->dummy) | ||
| 800 | goto dummy_print; | ||
| 801 | if (pair->diff.computed) | ||
| 802 | diff = pair->diff.period_ratio; | ||
| 803 | else | ||
| 804 | diff = compute_ratio(he, pair); | ||
| 805 | |||
| 806 | scnprintf(pfmt, 20, "%%%d.6f", dfmt->header_width); | ||
| 807 | return value_color_snprintf(hpp->buf, hpp->size, | ||
| 808 | pfmt, diff); | ||
| 798 | default: | 809 | default: |
| 799 | BUG_ON(1); | 810 | BUG_ON(1); |
| 800 | } | 811 | } |
| @@ -809,6 +820,12 @@ static int hpp__color_delta(struct perf_hpp_fmt *fmt, | |||
| 809 | return __hpp__color_compare(fmt, hpp, he, COMPUTE_DELTA); | 820 | return __hpp__color_compare(fmt, hpp, he, COMPUTE_DELTA); |
| 810 | } | 821 | } |
| 811 | 822 | ||
| 823 | static int hpp__color_ratio(struct perf_hpp_fmt *fmt, | ||
| 824 | struct perf_hpp *hpp, struct hist_entry *he) | ||
| 825 | { | ||
| 826 | return __hpp__color_compare(fmt, hpp, he, COMPUTE_RATIO); | ||
| 827 | } | ||
| 828 | |||
| 812 | static void | 829 | static void |
| 813 | hpp__entry_unpair(struct hist_entry *he, int idx, char *buf, size_t size) | 830 | hpp__entry_unpair(struct hist_entry *he, int idx, char *buf, size_t size) |
| 814 | { | 831 | { |
| @@ -987,6 +1004,9 @@ static void data__hpp_register(struct data__file *d, int idx) | |||
| 987 | case PERF_HPP_DIFF__DELTA: | 1004 | case PERF_HPP_DIFF__DELTA: |
| 988 | fmt->color = hpp__color_delta; | 1005 | fmt->color = hpp__color_delta; |
| 989 | break; | 1006 | break; |
| 1007 | case PERF_HPP_DIFF__RATIO: | ||
| 1008 | fmt->color = hpp__color_ratio; | ||
| 1009 | break; | ||
| 990 | default: | 1010 | default: |
| 991 | break; | 1011 | break; |
| 992 | } | 1012 | } |
diff --git a/tools/perf/util/color.c b/tools/perf/util/color.c index 8cda46c43e74..87b8672eb413 100644 --- a/tools/perf/util/color.c +++ b/tools/perf/util/color.c | |||
| @@ -319,15 +319,19 @@ int percent_color_fprintf(FILE *fp, const char *fmt, double percent) | |||
| 319 | return r; | 319 | return r; |
| 320 | } | 320 | } |
| 321 | 321 | ||
| 322 | int value_color_snprintf(char *bf, size_t size, const char *fmt, double value) | ||
| 323 | { | ||
| 324 | const char *color = get_percent_color(value); | ||
| 325 | return color_snprintf(bf, size, color, fmt, value); | ||
| 326 | } | ||
| 327 | |||
| 322 | int percent_color_snprintf(char *bf, size_t size, const char *fmt, ...) | 328 | int percent_color_snprintf(char *bf, size_t size, const char *fmt, ...) |
| 323 | { | 329 | { |
| 324 | va_list args; | 330 | va_list args; |
| 325 | double percent; | 331 | double percent; |
| 326 | const char *color; | ||
| 327 | 332 | ||
| 328 | va_start(args, fmt); | 333 | va_start(args, fmt); |
| 329 | percent = va_arg(args, double); | 334 | percent = va_arg(args, double); |
| 330 | va_end(args); | 335 | va_end(args); |
| 331 | color = get_percent_color(percent); | 336 | return value_color_snprintf(bf, size, fmt, percent); |
| 332 | return color_snprintf(bf, size, color, fmt, percent); | ||
| 333 | } | 337 | } |
diff --git a/tools/perf/util/color.h b/tools/perf/util/color.h index fced3840e99c..7ff30a62a132 100644 --- a/tools/perf/util/color.h +++ b/tools/perf/util/color.h | |||
| @@ -39,6 +39,7 @@ int color_fprintf(FILE *fp, const char *color, const char *fmt, ...); | |||
| 39 | int color_snprintf(char *bf, size_t size, const char *color, const char *fmt, ...); | 39 | int color_snprintf(char *bf, size_t size, const char *color, const char *fmt, ...); |
| 40 | int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...); | 40 | int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...); |
| 41 | int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf); | 41 | int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf); |
| 42 | int value_color_snprintf(char *bf, size_t size, const char *fmt, double value); | ||
| 42 | int percent_color_snprintf(char *bf, size_t size, const char *fmt, ...); | 43 | int percent_color_snprintf(char *bf, size_t size, const char *fmt, ...); |
| 43 | int percent_color_fprintf(FILE *fp, const char *fmt, double percent); | 44 | int percent_color_fprintf(FILE *fp, const char *fmt, double percent); |
| 44 | const char *get_percent_color(double percent); | 45 | const char *get_percent_color(double percent); |
