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-top.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-top.c')
-rw-r--r-- | tools/perf/builtin-top.c | 15 |
1 files changed, 1 insertions, 14 deletions
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index aa044ea1482b..95d5c0ae375a 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c | |||
@@ -239,7 +239,6 @@ static void print_sym_table(void) | |||
239 | for (nd = rb_first(&tmp); nd; nd = rb_next(nd)) { | 239 | for (nd = rb_first(&tmp); nd; nd = rb_next(nd)) { |
240 | struct sym_entry *syme = rb_entry(nd, struct sym_entry, rb_node); | 240 | struct sym_entry *syme = rb_entry(nd, struct sym_entry, rb_node); |
241 | struct symbol *sym = (struct symbol *)(syme + 1); | 241 | struct symbol *sym = (struct symbol *)(syme + 1); |
242 | char *color = PERF_COLOR_NORMAL; | ||
243 | double pcnt; | 242 | double pcnt; |
244 | 243 | ||
245 | if (++printed > print_entries || syme->snap_count < count_filter) | 244 | if (++printed > print_entries || syme->snap_count < count_filter) |
@@ -248,24 +247,12 @@ static void print_sym_table(void) | |||
248 | pcnt = 100.0 - (100.0 * ((sum_ksamples - syme->snap_count) / | 247 | pcnt = 100.0 - (100.0 * ((sum_ksamples - syme->snap_count) / |
249 | sum_ksamples)); | 248 | sum_ksamples)); |
250 | 249 | ||
251 | /* | ||
252 | * We color high-overhead entries in red, mid-overhead | ||
253 | * entries in green - and keep the low overhead places | ||
254 | * normal: | ||
255 | */ | ||
256 | if (pcnt >= 5.0) { | ||
257 | color = PERF_COLOR_RED; | ||
258 | } else { | ||
259 | if (pcnt >= 0.5) | ||
260 | color = PERF_COLOR_GREEN; | ||
261 | } | ||
262 | |||
263 | if (nr_counters == 1) | 250 | if (nr_counters == 1) |
264 | printf("%20.2f - ", syme->weight); | 251 | printf("%20.2f - ", syme->weight); |
265 | else | 252 | else |
266 | printf("%9.1f %10ld - ", syme->weight, syme->snap_count); | 253 | printf("%9.1f %10ld - ", syme->weight, syme->snap_count); |
267 | 254 | ||
268 | color_fprintf(stdout, color, "%4.1f%%", pcnt); | 255 | percent_color_fprintf(stdout, "%4.1f%%", pcnt); |
269 | printf(" - %016llx : %s", sym->start, sym->name); | 256 | printf(" - %016llx : %s", sym->start, sym->name); |
270 | if (sym->module) | 257 | if (sym->module) |
271 | printf("\t[%s]", sym->module->name); | 258 | printf("\t[%s]", sym->module->name); |