aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/perf_counter/builtin-report.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2009-06-04 09:19:47 -0400
committerIngo Molnar <mingo@elte.hu>2009-06-04 09:28:11 -0400
commit8fc0321f1ad0ffef969056dda91b453bbd7a494d (patch)
tree8931ad2c6582a2f59930301c3c099aa1532bb14c /Documentation/perf_counter/builtin-report.c
parent71dd8945d8d827ab101cd287f9480ef22fc7c1b6 (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-report.c')
-rw-r--r--Documentation/perf_counter/builtin-report.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/Documentation/perf_counter/builtin-report.c b/Documentation/perf_counter/builtin-report.c
index e930b4e02335..7beedc6effa4 100644
--- a/Documentation/perf_counter/builtin-report.c
+++ b/Documentation/perf_counter/builtin-report.c
@@ -9,6 +9,7 @@
9 9
10#include "util/util.h" 10#include "util/util.h"
11 11
12#include "util/color.h"
12#include "util/list.h" 13#include "util/list.h"
13#include "util/cache.h" 14#include "util/cache.h"
14#include "util/rbtree.h" 15#include "util/rbtree.h"
@@ -548,7 +549,19 @@ hist_entry__fprintf(FILE *fp, struct hist_entry *self, uint64_t total_samples)
548 size_t ret; 549 size_t ret;
549 550
550 if (total_samples) { 551 if (total_samples) {
551 ret = fprintf(fp, " %6.2f%%", 552 double percent = self->count * 100.0 / total_samples;
553 char *color = PERF_COLOR_NORMAL;
554
555 /*
556 * We color high-overhead entries in red, low-overhead
557 * entries in green - and keep the middle ground normal:
558 */
559 if (percent >= 5.0)
560 color = PERF_COLOR_RED;
561 if (percent < 0.5)
562 color = PERF_COLOR_GREEN;
563
564 ret = color_fprintf(fp, color, " %6.2f%%",
552 (self->count * 100.0) / total_samples); 565 (self->count * 100.0) / total_samples);
553 } else 566 } else
554 ret = fprintf(fp, "%12d ", self->count); 567 ret = fprintf(fp, "%12d ", self->count);