diff options
author | Frederic Weisbecker <fweisbec@gmail.com> | 2009-07-02 14:14:34 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-07-02 15:38:37 -0400 |
commit | 1e11fd82d247e4e48a1d6c49402214434538d3fd (patch) | |
tree | 7ac435b0be559c113987a64126559ea9b41627dc /tools/perf/util | |
parent | c20ab37ef30f4a874cf27e84c12c73e584e6f5cc (diff) |
perf_counter tools: Provide helper to print percents color
Among perf annotate, perf report and perf top, we can find the
common colored printing of percents according to the following
rules:
High overhead = > 5%, colored in red
Mid overhead = > 0.5%, colored in green
Low overhead = < 0.5%, default color
Factorize these multiple checks in a single function named
percent_color_fprintf() and also provide a get_percent_color()
for sites which print percentages and other things at the same
time.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Anton Blanchard <anton@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1246558475-10624-2-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/color.c | 27 | ||||
-rw-r--r-- | tools/perf/util/color.h | 5 |
2 files changed, 32 insertions, 0 deletions
diff --git a/tools/perf/util/color.c b/tools/perf/util/color.c index 26f82318b86b..90a044d1fe7d 100644 --- a/tools/perf/util/color.c +++ b/tools/perf/util/color.c | |||
@@ -242,4 +242,31 @@ int color_fwrite_lines(FILE *fp, const char *color, | |||
242 | return 0; | 242 | return 0; |
243 | } | 243 | } |
244 | 244 | ||
245 | char *get_percent_color(double percent) | ||
246 | { | ||
247 | char *color = PERF_COLOR_NORMAL; | ||
248 | |||
249 | /* | ||
250 | * We color high-overhead entries in red, mid-overhead | ||
251 | * entries in green - and keep the low overhead places | ||
252 | * normal: | ||
253 | */ | ||
254 | if (percent >= MIN_RED) | ||
255 | color = PERF_COLOR_RED; | ||
256 | else { | ||
257 | if (percent > MIN_GREEN) | ||
258 | color = PERF_COLOR_GREEN; | ||
259 | } | ||
260 | return color; | ||
261 | } | ||
245 | 262 | ||
263 | int percent_color_fprintf(FILE *fp, const char *fmt, double percent) | ||
264 | { | ||
265 | int r; | ||
266 | char *color; | ||
267 | |||
268 | color = get_percent_color(percent); | ||
269 | r = color_fprintf(fp, color, fmt, percent); | ||
270 | |||
271 | return r; | ||
272 | } | ||
diff --git a/tools/perf/util/color.h b/tools/perf/util/color.h index 5abfd379582b..706cec50bd25 100644 --- a/tools/perf/util/color.h +++ b/tools/perf/util/color.h | |||
@@ -15,6 +15,9 @@ | |||
15 | #define PERF_COLOR_CYAN "\033[36m" | 15 | #define PERF_COLOR_CYAN "\033[36m" |
16 | #define PERF_COLOR_BG_RED "\033[41m" | 16 | #define PERF_COLOR_BG_RED "\033[41m" |
17 | 17 | ||
18 | #define MIN_GREEN 0.5 | ||
19 | #define MIN_RED 5.0 | ||
20 | |||
18 | /* | 21 | /* |
19 | * This variable stores the value of color.ui | 22 | * This variable stores the value of color.ui |
20 | */ | 23 | */ |
@@ -32,5 +35,7 @@ void color_parse_mem(const char *value, int len, const char *var, char *dst); | |||
32 | int color_fprintf(FILE *fp, const char *color, const char *fmt, ...); | 35 | int color_fprintf(FILE *fp, const char *color, const char *fmt, ...); |
33 | int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...); | 36 | int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...); |
34 | int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf); | 37 | int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf); |
38 | int percent_color_fprintf(FILE *fp, const char *fmt, double percent); | ||
39 | char *get_percent_color(double percent); | ||
35 | 40 | ||
36 | #endif /* COLOR_H */ | 41 | #endif /* COLOR_H */ |