aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2009-06-04 09:40:25 -0400
committerIngo Molnar <mingo@elte.hu>2009-06-04 09:40:25 -0400
commit13d0ab5ec29852a6925f612830fa9e822669ece6 (patch)
tree614ac0463dd3648bc8079e2ea795752af9cb1272
parent8fc0321f1ad0ffef969056dda91b453bbd7a494d (diff)
perf_counter tools: Dont output in color on !tty
Dont emit ASCII color characters if the terminal is not a tty, such as when perf report gets redirected into a file. 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>
-rw-r--r--Documentation/perf_counter/util/color.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/Documentation/perf_counter/util/color.c b/Documentation/perf_counter/util/color.c
index a77975d66774..9a8c20ccc53e 100644
--- a/Documentation/perf_counter/util/color.c
+++ b/Documentation/perf_counter/util/color.c
@@ -1,7 +1,7 @@
1#include "cache.h" 1#include "cache.h"
2#include "color.h" 2#include "color.h"
3 3
4int perf_use_color_default = 0; 4int perf_use_color_default = -1;
5 5
6static int parse_color(const char *name, int len) 6static int parse_color(const char *name, int len)
7{ 7{
@@ -169,10 +169,20 @@ static int color_vfprintf(FILE *fp, const char *color, const char *fmt,
169{ 169{
170 int r = 0; 170 int r = 0;
171 171
172 if (*color) 172 /*
173 * Auto-detect:
174 */
175 if (perf_use_color_default < 0) {
176 if (isatty(1) || pager_in_use())
177 perf_use_color_default = 1;
178 else
179 perf_use_color_default = 0;
180 }
181
182 if (perf_use_color_default && *color)
173 r += fprintf(fp, "%s", color); 183 r += fprintf(fp, "%s", color);
174 r += vfprintf(fp, fmt, args); 184 r += vfprintf(fp, fmt, args);
175 if (*color) 185 if (perf_use_color_default && *color)
176 r += fprintf(fp, "%s", PERF_COLOR_RESET); 186 r += fprintf(fp, "%s", PERF_COLOR_RESET);
177 if (trail) 187 if (trail)
178 r += fprintf(fp, "%s", trail); 188 r += fprintf(fp, "%s", trail);
@@ -185,6 +195,7 @@ int color_fprintf(FILE *fp, const char *color, const char *fmt, ...)
185{ 195{
186 va_list args; 196 va_list args;
187 int r; 197 int r;
198
188 va_start(args, fmt); 199 va_start(args, fmt);
189 r = color_vfprintf(fp, color, fmt, args, NULL); 200 r = color_vfprintf(fp, color, fmt, args, NULL);
190 va_end(args); 201 va_end(args);