summaryrefslogtreecommitdiff
path: root/Documentation/perf_counter/builtin-report.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2009-06-04 15:19:47 +0200
committerIngo Molnar <mingo@elte.hu>2009-06-04 15:28:11 +0200
commit8fc0321f1ad0ffef969056dda91b453bbd7a494d (patch)
tree8931ad2c6582a2f59930301c3c099aa1532bb14c /Documentation/perf_counter/builtin-report.c
parent71dd8945d8d827ab101cd287f9480ef22fc7c1b6 (diff)
downloadlwn-8fc0321f1ad0ffef969056dda91b453bbd7a494d.tar.gz
lwn-8fc0321f1ad0ffef969056dda91b453bbd7a494d.zip
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 @@
#include "util/util.h"
+#include "util/color.h"
#include "util/list.h"
#include "util/cache.h"
#include "util/rbtree.h"
@@ -548,7 +549,19 @@ hist_entry__fprintf(FILE *fp, struct hist_entry *self, uint64_t total_samples)
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);