aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/builtin-annotate.c26
-rw-r--r--tools/perf/builtin-report.c21
-rw-r--r--tools/perf/builtin-top.c15
-rw-r--r--tools/perf/util/color.c27
-rw-r--r--tools/perf/util/color.h5
5 files changed, 38 insertions, 56 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 08ea6c5329d9..5f9eefecc574 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -25,10 +25,6 @@
25#define SHOW_USER 2 25#define SHOW_USER 2
26#define SHOW_HV 4 26#define SHOW_HV 4
27 27
28#define MIN_GREEN 0.5
29#define MIN_RED 5.0
30
31
32static char const *input_name = "perf.data"; 28static char const *input_name = "perf.data";
33static char *vmlinux = "vmlinux"; 29static char *vmlinux = "vmlinux";
34 30
@@ -1047,24 +1043,6 @@ process_event(event_t *event, unsigned long offset, unsigned long head)
1047 return 0; 1043 return 0;
1048} 1044}
1049 1045
1050static char *get_color(double percent)
1051{
1052 char *color = PERF_COLOR_NORMAL;
1053
1054 /*
1055 * We color high-overhead entries in red, mid-overhead
1056 * entries in green - and keep the low overhead places
1057 * normal:
1058 */
1059 if (percent >= MIN_RED)
1060 color = PERF_COLOR_RED;
1061 else {
1062 if (percent > MIN_GREEN)
1063 color = PERF_COLOR_GREEN;
1064 }
1065 return color;
1066}
1067
1068static int 1046static int
1069parse_line(FILE *file, struct symbol *sym, u64 start, u64 len) 1047parse_line(FILE *file, struct symbol *sym, u64 start, u64 len)
1070{ 1048{
@@ -1126,7 +1104,7 @@ parse_line(FILE *file, struct symbol *sym, u64 start, u64 len)
1126 } else if (sym->hist_sum) 1104 } else if (sym->hist_sum)
1127 percent = 100.0 * hits / sym->hist_sum; 1105 percent = 100.0 * hits / sym->hist_sum;
1128 1106
1129 color = get_color(percent); 1107 color = get_percent_color(percent);
1130 1108
1131 /* 1109 /*
1132 * Also color the filename and line if needed, with 1110 * Also color the filename and line if needed, with
@@ -1262,7 +1240,7 @@ static void print_summary(char *filename)
1262 1240
1263 sym_ext = rb_entry(node, struct sym_ext, node); 1241 sym_ext = rb_entry(node, struct sym_ext, node);
1264 percent = sym_ext->percent; 1242 percent = sym_ext->percent;
1265 color = get_color(percent); 1243 color = get_percent_color(percent);
1266 path = sym_ext->path; 1244 path = sym_ext->path;
1267 1245
1268 color_fprintf(stdout, color, " %7.2f %s", percent, path); 1246 color_fprintf(stdout, color, " %7.2f %s", percent, path);
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index e8c98179fe45..c9dbe3315497 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -947,25 +947,10 @@ hist_entry__fprintf(FILE *fp, struct hist_entry *self, u64 total_samples)
947 if (exclude_other && !self->parent) 947 if (exclude_other && !self->parent)
948 return 0; 948 return 0;
949 949
950 if (total_samples) { 950 if (total_samples)
951 double percent = self->count * 100.0 / total_samples; 951 ret = percent_color_fprintf(fp, " %6.2f%%",
952 char *color = PERF_COLOR_NORMAL;
953
954 /*
955 * We color high-overhead entries in red, mid-overhead
956 * entries in green - and keep the low overhead places
957 * normal:
958 */
959 if (percent >= 5.0) {
960 color = PERF_COLOR_RED;
961 } else {
962 if (percent >= 0.5)
963 color = PERF_COLOR_GREEN;
964 }
965
966 ret = color_fprintf(fp, color, " %6.2f%%",
967 (self->count * 100.0) / total_samples); 952 (self->count * 100.0) / total_samples);
968 } else 953 else
969 ret = fprintf(fp, "%12Ld ", self->count); 954 ret = fprintf(fp, "%12Ld ", self->count);
970 955
971 list_for_each_entry(se, &hist_entry__sort_list, list) { 956 list_for_each_entry(se, &hist_entry__sort_list, list) {
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index aa044ea1482b..95d5c0ae375a 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -239,7 +239,6 @@ static void print_sym_table(void)
239 for (nd = rb_first(&tmp); nd; nd = rb_next(nd)) { 239 for (nd = rb_first(&tmp); nd; nd = rb_next(nd)) {
240 struct sym_entry *syme = rb_entry(nd, struct sym_entry, rb_node); 240 struct sym_entry *syme = rb_entry(nd, struct sym_entry, rb_node);
241 struct symbol *sym = (struct symbol *)(syme + 1); 241 struct symbol *sym = (struct symbol *)(syme + 1);
242 char *color = PERF_COLOR_NORMAL;
243 double pcnt; 242 double pcnt;
244 243
245 if (++printed > print_entries || syme->snap_count < count_filter) 244 if (++printed > print_entries || syme->snap_count < count_filter)
@@ -248,24 +247,12 @@ static void print_sym_table(void)
248 pcnt = 100.0 - (100.0 * ((sum_ksamples - syme->snap_count) / 247 pcnt = 100.0 - (100.0 * ((sum_ksamples - syme->snap_count) /
249 sum_ksamples)); 248 sum_ksamples));
250 249
251 /*
252 * We color high-overhead entries in red, mid-overhead
253 * entries in green - and keep the low overhead places
254 * normal:
255 */
256 if (pcnt >= 5.0) {
257 color = PERF_COLOR_RED;
258 } else {
259 if (pcnt >= 0.5)
260 color = PERF_COLOR_GREEN;
261 }
262
263 if (nr_counters == 1) 250 if (nr_counters == 1)
264 printf("%20.2f - ", syme->weight); 251 printf("%20.2f - ", syme->weight);
265 else 252 else
266 printf("%9.1f %10ld - ", syme->weight, syme->snap_count); 253 printf("%9.1f %10ld - ", syme->weight, syme->snap_count);
267 254
268 color_fprintf(stdout, color, "%4.1f%%", pcnt); 255 percent_color_fprintf(stdout, "%4.1f%%", pcnt);
269 printf(" - %016llx : %s", sym->start, sym->name); 256 printf(" - %016llx : %s", sym->start, sym->name);
270 if (sym->module) 257 if (sym->module)
271 printf("\t[%s]", sym->module->name); 258 printf("\t[%s]", sym->module->name);
diff --git a/tools/perf/util/color.c b/tools/perf/util/color.c
index 26f82318b86b..90a044d1fe7d 100644
--- a/tools/perf/util/color.c
+++ b/tools/perf/util/color.c
@@ -242,4 +242,31 @@ int color_fwrite_lines(FILE *fp, const char *color,
242 return 0; 242 return 0;
243} 243}
244 244
245char *get_percent_color(double percent)
246{
247 char *color = PERF_COLOR_NORMAL;
248
249 /*
250 * We color high-overhead entries in red, mid-overhead
251 * entries in green - and keep the low overhead places
252 * normal:
253 */
254 if (percent >= MIN_RED)
255 color = PERF_COLOR_RED;
256 else {
257 if (percent > MIN_GREEN)
258 color = PERF_COLOR_GREEN;
259 }
260 return color;
261}
245 262
263int percent_color_fprintf(FILE *fp, const char *fmt, double percent)
264{
265 int r;
266 char *color;
267
268 color = get_percent_color(percent);
269 r = color_fprintf(fp, color, fmt, percent);
270
271 return r;
272}
diff --git a/tools/perf/util/color.h b/tools/perf/util/color.h
index 5abfd379582b..706cec50bd25 100644
--- a/tools/perf/util/color.h
+++ b/tools/perf/util/color.h
@@ -15,6 +15,9 @@
15#define PERF_COLOR_CYAN "\033[36m" 15#define PERF_COLOR_CYAN "\033[36m"
16#define PERF_COLOR_BG_RED "\033[41m" 16#define PERF_COLOR_BG_RED "\033[41m"
17 17
18#define MIN_GREEN 0.5
19#define MIN_RED 5.0
20
18/* 21/*
19 * This variable stores the value of color.ui 22 * This variable stores the value of color.ui
20 */ 23 */
@@ -32,5 +35,7 @@ void color_parse_mem(const char *value, int len, const char *var, char *dst);
32int color_fprintf(FILE *fp, const char *color, const char *fmt, ...); 35int color_fprintf(FILE *fp, const char *color, const char *fmt, ...);
33int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...); 36int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...);
34int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf); 37int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf);
38int percent_color_fprintf(FILE *fp, const char *fmt, double percent);
39char *get_percent_color(double percent);
35 40
36#endif /* COLOR_H */ 41#endif /* COLOR_H */