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>
diff --git a/Documentation/perf_counter/builtin-report.c b/Documentation/perf_counter/builtin-report.c
index e930b4e..7beedc6 100644
--- a/Documentation/perf_counter/builtin-report.c
+++ b/Documentation/perf_counter/builtin-report.c
@@ -9,6 +9,7 @@
#include "util/util.h"
+#include "util/color.h"
#include "util/list.h"
#include "util/cache.h"
#include "util/rbtree.h"
@@ -548,7 +549,19 @@
size_t ret;
if (total_samples) {
- ret = fprintf(fp, " %6.2f%%",
+ double percent = self->count * 100.0 / total_samples;
+ char *color = PERF_COLOR_NORMAL;
+
+ /*
+ * We color high-overhead entries in red, low-overhead
+ * entries in green - and keep the middle ground normal:
+ */
+ if (percent >= 5.0)
+ color = PERF_COLOR_RED;
+ if (percent < 0.5)
+ color = PERF_COLOR_GREEN;
+
+ ret = color_fprintf(fp, color, " %6.2f%%",
(self->count * 100.0) / total_samples);
} else
ret = fprintf(fp, "%12d ", self->count);