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/builtin-annotate.c | |
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/builtin-annotate.c')
-rw-r--r-- | tools/perf/builtin-annotate.c | 26 |
1 files changed, 2 insertions, 24 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 08ea6c5329d9..5f9eefecc574 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
@@ -25,10 +25,6 @@ | |||
25 | #define SHOW_USER 2 | 25 | #define SHOW_USER 2 |
26 | #define SHOW_HV 4 | 26 | #define SHOW_HV 4 |
27 | 27 | ||
28 | #define MIN_GREEN 0.5 | ||
29 | #define MIN_RED 5.0 | ||
30 | |||
31 | |||
32 | static char const *input_name = "perf.data"; | 28 | static char const *input_name = "perf.data"; |
33 | static char *vmlinux = "vmlinux"; | 29 | static char *vmlinux = "vmlinux"; |
34 | 30 | ||
@@ -1047,24 +1043,6 @@ process_event(event_t *event, unsigned long offset, unsigned long head) | |||
1047 | return 0; | 1043 | return 0; |
1048 | } | 1044 | } |
1049 | 1045 | ||
1050 | static char *get_color(double percent) | ||
1051 | { | ||
1052 | char *color = PERF_COLOR_NORMAL; | ||
1053 | |||
1054 | /* | ||
1055 | * We color high-overhead entries in red, mid-overhead | ||
1056 | * entries in green - and keep the low overhead places | ||
1057 | * normal: | ||
1058 | */ | ||
1059 | if (percent >= MIN_RED) | ||
1060 | color = PERF_COLOR_RED; | ||
1061 | else { | ||
1062 | if (percent > MIN_GREEN) | ||
1063 | color = PERF_COLOR_GREEN; | ||
1064 | } | ||
1065 | return color; | ||
1066 | } | ||
1067 | |||
1068 | static int | 1046 | static int |
1069 | parse_line(FILE *file, struct symbol *sym, u64 start, u64 len) | 1047 | parse_line(FILE *file, struct symbol *sym, u64 start, u64 len) |
1070 | { | 1048 | { |
@@ -1126,7 +1104,7 @@ parse_line(FILE *file, struct symbol *sym, u64 start, u64 len) | |||
1126 | } else if (sym->hist_sum) | 1104 | } else if (sym->hist_sum) |
1127 | percent = 100.0 * hits / sym->hist_sum; | 1105 | percent = 100.0 * hits / sym->hist_sum; |
1128 | 1106 | ||
1129 | color = get_color(percent); | 1107 | color = get_percent_color(percent); |
1130 | 1108 | ||
1131 | /* | 1109 | /* |
1132 | * Also color the filename and line if needed, with | 1110 | * Also color the filename and line if needed, with |
@@ -1262,7 +1240,7 @@ static void print_summary(char *filename) | |||
1262 | 1240 | ||
1263 | sym_ext = rb_entry(node, struct sym_ext, node); | 1241 | sym_ext = rb_entry(node, struct sym_ext, node); |
1264 | percent = sym_ext->percent; | 1242 | percent = sym_ext->percent; |
1265 | color = get_color(percent); | 1243 | color = get_percent_color(percent); |
1266 | path = sym_ext->path; | 1244 | path = sym_ext->path; |
1267 | 1245 | ||
1268 | color_fprintf(stdout, color, " %7.2f %s", percent, path); | 1246 | color_fprintf(stdout, color, " %7.2f %s", percent, path); |