diff options
author | Ingo Molnar <mingo@elte.hu> | 2009-06-04 09:19:47 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-06-04 09:28:11 -0400 |
commit | 8fc0321f1ad0ffef969056dda91b453bbd7a494d (patch) | |
tree | 8931ad2c6582a2f59930301c3c099aa1532bb14c /Documentation/perf_counter/builtin-top.c | |
parent | 71dd8945d8d827ab101cd287f9480ef22fc7c1b6 (diff) |
perf_counter tools: Add color terminal output support
Add Git's color printing library to util/color.[ch].
Add it to perf report, with a trivial example to print high-overhead
entries in red, low-overhead entries in green.
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'Documentation/perf_counter/builtin-top.c')
-rw-r--r-- | Documentation/perf_counter/builtin-top.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/Documentation/perf_counter/builtin-top.c b/Documentation/perf_counter/builtin-top.c index 548a8da4b15b..20e5b1200959 100644 --- a/Documentation/perf_counter/builtin-top.c +++ b/Documentation/perf_counter/builtin-top.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include "perf.h" | 21 | #include "perf.h" |
22 | 22 | ||
23 | #include "util/symbol.h" | 23 | #include "util/symbol.h" |
24 | #include "util/color.h" | ||
24 | #include "util/util.h" | 25 | #include "util/util.h" |
25 | #include "util/rbtree.h" | 26 | #include "util/rbtree.h" |
26 | #include "util/parse-options.h" | 27 | #include "util/parse-options.h" |
@@ -253,7 +254,8 @@ static void print_sym_table(void) | |||
253 | for (nd = rb_first(&tmp); nd; nd = rb_next(nd)) { | 254 | for (nd = rb_first(&tmp); nd; nd = rb_next(nd)) { |
254 | struct sym_entry *syme = rb_entry(nd, struct sym_entry, rb_node); | 255 | struct sym_entry *syme = rb_entry(nd, struct sym_entry, rb_node); |
255 | struct symbol *sym = (struct symbol *)(syme + 1); | 256 | struct symbol *sym = (struct symbol *)(syme + 1); |
256 | float pcnt; | 257 | char *color = PERF_COLOR_NORMAL; |
258 | double pcnt; | ||
257 | 259 | ||
258 | if (++printed > print_entries || syme->snap_count < count_filter) | 260 | if (++printed > print_entries || syme->snap_count < count_filter) |
259 | continue; | 261 | continue; |
@@ -261,13 +263,22 @@ static void print_sym_table(void) | |||
261 | pcnt = 100.0 - (100.0 * ((sum_kevents - syme->snap_count) / | 263 | pcnt = 100.0 - (100.0 * ((sum_kevents - syme->snap_count) / |
262 | sum_kevents)); | 264 | sum_kevents)); |
263 | 265 | ||
266 | /* | ||
267 | * We color high-overhead entries in red, low-overhead | ||
268 | * entries in green - and keep the middle ground normal: | ||
269 | */ | ||
270 | if (pcnt >= 5.0) | ||
271 | color = PERF_COLOR_RED; | ||
272 | if (pcnt < 0.5) | ||
273 | color = PERF_COLOR_GREEN; | ||
274 | |||
264 | if (nr_counters == 1) | 275 | if (nr_counters == 1) |
265 | printf("%19.2f - %4.1f%% - %016llx : %s\n", | 276 | printf("%19.2f - ", syme->weight); |
266 | syme->weight, pcnt, sym->start, sym->name); | ||
267 | else | 277 | else |
268 | printf("%8.1f %10ld - %4.1f%% - %016llx : %s\n", | 278 | printf("%8.1f %10ld - ", syme->weight, syme->snap_count); |
269 | syme->weight, syme->snap_count, | 279 | |
270 | pcnt, sym->start, sym->name); | 280 | color_fprintf(stdout, color, "%4.1f%%", pcnt); |
281 | printf(" - %016llx : %s\n", sym->start, sym->name); | ||
271 | } | 282 | } |
272 | 283 | ||
273 | { | 284 | { |