aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2014-07-31 01:47:36 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-08-12 11:03:05 -0400
commitd675107ce6fa988102851e0b0ef06e46c8aa7ac6 (patch)
tree202b4df2114ddd4ca6d6f796f4a523996d2e71d7
parent8246de88e95ddef7508f5601d7af85c3ab9e476b (diff)
perf tools: Make __hpp__fmt() receive an additional len argument
So that it can properly handle alignment requirements later. To do that, add percent_color_len_snprintf() fucntion to help coloring of overhead columns. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung.kim@lge.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1406785662-5534-3-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/ui/browsers/hists.c14
-rw-r--r--tools/perf/ui/gtk/hists.c8
-rw-r--r--tools/perf/ui/hist.c43
-rw-r--r--tools/perf/util/color.c16
-rw-r--r--tools/perf/util/color.h1
-rw-r--r--tools/perf/util/hist.h4
6 files changed, 54 insertions, 32 deletions
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index a94b11fc5e00..02507ba944e3 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -653,17 +653,18 @@ struct hpp_arg {
653static int __hpp__slsmg_color_printf(struct perf_hpp *hpp, const char *fmt, ...) 653static int __hpp__slsmg_color_printf(struct perf_hpp *hpp, const char *fmt, ...)
654{ 654{
655 struct hpp_arg *arg = hpp->ptr; 655 struct hpp_arg *arg = hpp->ptr;
656 int ret; 656 int ret, len;
657 va_list args; 657 va_list args;
658 double percent; 658 double percent;
659 659
660 va_start(args, fmt); 660 va_start(args, fmt);
661 len = va_arg(args, int);
661 percent = va_arg(args, double); 662 percent = va_arg(args, double);
662 va_end(args); 663 va_end(args);
663 664
664 ui_browser__set_percent_color(arg->b, percent, arg->current_entry); 665 ui_browser__set_percent_color(arg->b, percent, arg->current_entry);
665 666
666 ret = scnprintf(hpp->buf, hpp->size, fmt, percent); 667 ret = scnprintf(hpp->buf, hpp->size, fmt, len, percent);
667 slsmg_printf("%s", hpp->buf); 668 slsmg_printf("%s", hpp->buf);
668 669
669 advance_hpp(hpp, ret); 670 advance_hpp(hpp, ret);
@@ -681,7 +682,7 @@ hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,\
681 struct perf_hpp *hpp, \ 682 struct perf_hpp *hpp, \
682 struct hist_entry *he) \ 683 struct hist_entry *he) \
683{ \ 684{ \
684 return __hpp__fmt(hpp, he, __hpp_get_##_field, " %6.2f%%", \ 685 return __hpp__fmt(hpp, he, __hpp_get_##_field, " %*.2f%%", 6, \
685 __hpp__slsmg_color_printf, true); \ 686 __hpp__slsmg_color_printf, true); \
686} 687}
687 688
@@ -697,13 +698,14 @@ hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,\
697 struct hist_entry *he) \ 698 struct hist_entry *he) \
698{ \ 699{ \
699 if (!symbol_conf.cumulate_callchain) { \ 700 if (!symbol_conf.cumulate_callchain) { \
700 int ret = scnprintf(hpp->buf, hpp->size, "%8s", "N/A"); \ 701 int ret = scnprintf(hpp->buf, hpp->size, \
702 "%*s", 8, "N/A"); \
701 slsmg_printf("%s", hpp->buf); \ 703 slsmg_printf("%s", hpp->buf); \
702 \ 704 \
703 return ret; \ 705 return ret; \
704 } \ 706 } \
705 return __hpp__fmt(hpp, he, __hpp_get_acc_##_field, " %6.2f%%", \ 707 return __hpp__fmt(hpp, he, __hpp_get_acc_##_field, " %*.2f%%", \
706 __hpp__slsmg_color_printf, true); \ 708 6, __hpp__slsmg_color_printf, true); \
707} 709}
708 710
709__HPP_COLOR_PERCENT_FN(overhead, period) 711__HPP_COLOR_PERCENT_FN(overhead, period)
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index 6ca60e482cdc..91f6cd7d2312 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -11,6 +11,7 @@
11static int __percent_color_snprintf(struct perf_hpp *hpp, const char *fmt, ...) 11static int __percent_color_snprintf(struct perf_hpp *hpp, const char *fmt, ...)
12{ 12{
13 int ret = 0; 13 int ret = 0;
14 int len;
14 va_list args; 15 va_list args;
15 double percent; 16 double percent;
16 const char *markup; 17 const char *markup;
@@ -18,6 +19,7 @@ static int __percent_color_snprintf(struct perf_hpp *hpp, const char *fmt, ...)
18 size_t size = hpp->size; 19 size_t size = hpp->size;
19 20
20 va_start(args, fmt); 21 va_start(args, fmt);
22 len = va_arg(args, int);
21 percent = va_arg(args, double); 23 percent = va_arg(args, double);
22 va_end(args); 24 va_end(args);
23 25
@@ -25,7 +27,7 @@ static int __percent_color_snprintf(struct perf_hpp *hpp, const char *fmt, ...)
25 if (markup) 27 if (markup)
26 ret += scnprintf(buf, size, markup); 28 ret += scnprintf(buf, size, markup);
27 29
28 ret += scnprintf(buf + ret, size - ret, fmt, percent); 30 ret += scnprintf(buf + ret, size - ret, fmt, len, percent);
29 31
30 if (markup) 32 if (markup)
31 ret += scnprintf(buf + ret, size - ret, "</span>"); 33 ret += scnprintf(buf + ret, size - ret, "</span>");
@@ -43,7 +45,7 @@ static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,
43 struct perf_hpp *hpp, \ 45 struct perf_hpp *hpp, \
44 struct hist_entry *he) \ 46 struct hist_entry *he) \
45{ \ 47{ \
46 return __hpp__fmt(hpp, he, he_get_##_field, " %6.2f%%", \ 48 return __hpp__fmt(hpp, he, he_get_##_field, " %*.2f%%", 6, \
47 __percent_color_snprintf, true); \ 49 __percent_color_snprintf, true); \
48} 50}
49 51
@@ -57,7 +59,7 @@ static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,
57 struct perf_hpp *hpp, \ 59 struct perf_hpp *hpp, \
58 struct hist_entry *he) \ 60 struct hist_entry *he) \
59{ \ 61{ \
60 return __hpp__fmt_acc(hpp, he, he_get_acc_##_field, " %6.2f%%", \ 62 return __hpp__fmt_acc(hpp, he, he_get_acc_##_field, " %*.2f%%", 6, \
61 __percent_color_snprintf, true); \ 63 __percent_color_snprintf, true); \
62} 64}
63 65
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index 498adb23c02e..c6cffbd0b0e1 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -16,7 +16,7 @@
16}) 16})
17 17
18int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, 18int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
19 hpp_field_fn get_field, const char *fmt, 19 hpp_field_fn get_field, const char *fmt, int len,
20 hpp_snprint_fn print_fn, bool fmt_percent) 20 hpp_snprint_fn print_fn, bool fmt_percent)
21{ 21{
22 int ret; 22 int ret;
@@ -32,9 +32,9 @@ int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
32 if (total) 32 if (total)
33 percent = 100.0 * get_field(he) / total; 33 percent = 100.0 * get_field(he) / total;
34 34
35 ret = hpp__call_print_fn(hpp, print_fn, fmt, percent); 35 ret = hpp__call_print_fn(hpp, print_fn, fmt, len, percent);
36 } else 36 } else
37 ret = hpp__call_print_fn(hpp, print_fn, fmt, get_field(he)); 37 ret = hpp__call_print_fn(hpp, print_fn, fmt, len, get_field(he));
38 38
39 if (perf_evsel__is_group_event(evsel)) { 39 if (perf_evsel__is_group_event(evsel)) {
40 int prev_idx, idx_delta; 40 int prev_idx, idx_delta;
@@ -60,19 +60,19 @@ int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
60 */ 60 */
61 if (fmt_percent) { 61 if (fmt_percent) {
62 ret += hpp__call_print_fn(hpp, print_fn, 62 ret += hpp__call_print_fn(hpp, print_fn,
63 fmt, 0.0); 63 fmt, len, 0.0);
64 } else { 64 } else {
65 ret += hpp__call_print_fn(hpp, print_fn, 65 ret += hpp__call_print_fn(hpp, print_fn,
66 fmt, 0ULL); 66 fmt, len, 0ULL);
67 } 67 }
68 } 68 }
69 69
70 if (fmt_percent) { 70 if (fmt_percent) {
71 ret += hpp__call_print_fn(hpp, print_fn, fmt, 71 ret += hpp__call_print_fn(hpp, print_fn, fmt, len,
72 100.0 * period / total); 72 100.0 * period / total);
73 } else { 73 } else {
74 ret += hpp__call_print_fn(hpp, print_fn, fmt, 74 ret += hpp__call_print_fn(hpp, print_fn, fmt,
75 period); 75 len, period);
76 } 76 }
77 77
78 prev_idx = perf_evsel__group_idx(evsel); 78 prev_idx = perf_evsel__group_idx(evsel);
@@ -86,10 +86,10 @@ int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
86 */ 86 */
87 if (fmt_percent) { 87 if (fmt_percent) {
88 ret += hpp__call_print_fn(hpp, print_fn, 88 ret += hpp__call_print_fn(hpp, print_fn,
89 fmt, 0.0); 89 fmt, len, 0.0);
90 } else { 90 } else {
91 ret += hpp__call_print_fn(hpp, print_fn, 91 ret += hpp__call_print_fn(hpp, print_fn,
92 fmt, 0ULL); 92 fmt, len, 0ULL);
93 } 93 }
94 } 94 }
95 } 95 }
@@ -105,7 +105,7 @@ int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
105} 105}
106 106
107int __hpp__fmt_acc(struct perf_hpp *hpp, struct hist_entry *he, 107int __hpp__fmt_acc(struct perf_hpp *hpp, struct hist_entry *he,
108 hpp_field_fn get_field, const char *fmt, 108 hpp_field_fn get_field, const char *fmt, int len,
109 hpp_snprint_fn print_fn, bool fmt_percent) 109 hpp_snprint_fn print_fn, bool fmt_percent)
110{ 110{
111 if (!symbol_conf.cumulate_callchain) { 111 if (!symbol_conf.cumulate_callchain) {
@@ -113,7 +113,7 @@ int __hpp__fmt_acc(struct perf_hpp *hpp, struct hist_entry *he,
113 fmt_percent ? 8 : 12, "N/A"); 113 fmt_percent ? 8 : 12, "N/A");
114 } 114 }
115 115
116 return __hpp__fmt(hpp, he, get_field, fmt, print_fn, fmt_percent); 116 return __hpp__fmt(hpp, he, get_field, fmt, len, print_fn, fmt_percent);
117} 117}
118 118
119static int field_cmp(u64 field_a, u64 field_b) 119static int field_cmp(u64 field_a, u64 field_b)
@@ -221,11 +221,12 @@ static int hpp_color_scnprintf(struct perf_hpp *hpp, const char *fmt, ...)
221 va_list args; 221 va_list args;
222 ssize_t ssize = hpp->size; 222 ssize_t ssize = hpp->size;
223 double percent; 223 double percent;
224 int ret; 224 int ret, len;
225 225
226 va_start(args, fmt); 226 va_start(args, fmt);
227 len = va_arg(args, int);
227 percent = va_arg(args, double); 228 percent = va_arg(args, double);
228 ret = value_color_snprintf(hpp->buf, hpp->size, fmt, percent); 229 ret = percent_color_len_snprintf(hpp->buf, hpp->size, fmt, len, percent);
229 va_end(args); 230 va_end(args);
230 231
231 return (ret >= ssize) ? (ssize - 1) : ret; 232 return (ret >= ssize) ? (ssize - 1) : ret;
@@ -253,7 +254,7 @@ static u64 he_get_##_field(struct hist_entry *he) \
253static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ 254static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
254 struct perf_hpp *hpp, struct hist_entry *he) \ 255 struct perf_hpp *hpp, struct hist_entry *he) \
255{ \ 256{ \
256 return __hpp__fmt(hpp, he, he_get_##_field, " %6.2f%%", \ 257 return __hpp__fmt(hpp, he, he_get_##_field, " %*.2f%%", 6, \
257 hpp_color_scnprintf, true); \ 258 hpp_color_scnprintf, true); \
258} 259}
259 260
@@ -261,8 +262,8 @@ static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
261static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \ 262static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \
262 struct perf_hpp *hpp, struct hist_entry *he) \ 263 struct perf_hpp *hpp, struct hist_entry *he) \
263{ \ 264{ \
264 const char *fmt = symbol_conf.field_sep ? " %.2f" : " %6.2f%%"; \ 265 int len = symbol_conf.field_sep ? 1 : 6; \
265 return __hpp__fmt(hpp, he, he_get_##_field, fmt, \ 266 return __hpp__fmt(hpp, he, he_get_##_field, " %*.2f%%", len, \
266 hpp_entry_scnprintf, true); \ 267 hpp_entry_scnprintf, true); \
267} 268}
268 269
@@ -281,7 +282,7 @@ static u64 he_get_acc_##_field(struct hist_entry *he) \
281static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ 282static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
282 struct perf_hpp *hpp, struct hist_entry *he) \ 283 struct perf_hpp *hpp, struct hist_entry *he) \
283{ \ 284{ \
284 return __hpp__fmt_acc(hpp, he, he_get_acc_##_field, " %6.2f%%", \ 285 return __hpp__fmt_acc(hpp, he, he_get_acc_##_field, " %*.2f%%", 6, \
285 hpp_color_scnprintf, true); \ 286 hpp_color_scnprintf, true); \
286} 287}
287 288
@@ -289,8 +290,8 @@ static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
289static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \ 290static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \
290 struct perf_hpp *hpp, struct hist_entry *he) \ 291 struct perf_hpp *hpp, struct hist_entry *he) \
291{ \ 292{ \
292 const char *fmt = symbol_conf.field_sep ? " %.2f" : " %6.2f%%"; \ 293 int len = symbol_conf.field_sep ? 1 : 6; \
293 return __hpp__fmt_acc(hpp, he, he_get_acc_##_field, fmt, \ 294 return __hpp__fmt_acc(hpp, he, he_get_##_field, " %*.2f%%", len, \
294 hpp_entry_scnprintf, true); \ 295 hpp_entry_scnprintf, true); \
295} 296}
296 297
@@ -309,8 +310,8 @@ static u64 he_get_raw_##_field(struct hist_entry *he) \
309static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \ 310static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \
310 struct perf_hpp *hpp, struct hist_entry *he) \ 311 struct perf_hpp *hpp, struct hist_entry *he) \
311{ \ 312{ \
312 const char *fmt = symbol_conf.field_sep ? " %"PRIu64 : " %11"PRIu64; \ 313 int len = symbol_conf.field_sep ? 1 : 11; \
313 return __hpp__fmt(hpp, he, he_get_raw_##_field, fmt, \ 314 return __hpp__fmt(hpp, he, he_get_raw_##_field, " %*"PRIu64, len, \
314 hpp_entry_scnprintf, false); \ 315 hpp_entry_scnprintf, false); \
315} 316}
316 317
diff --git a/tools/perf/util/color.c b/tools/perf/util/color.c
index 87b8672eb413..f4654183d391 100644
--- a/tools/perf/util/color.c
+++ b/tools/perf/util/color.c
@@ -335,3 +335,19 @@ int percent_color_snprintf(char *bf, size_t size, const char *fmt, ...)
335 va_end(args); 335 va_end(args);
336 return value_color_snprintf(bf, size, fmt, percent); 336 return value_color_snprintf(bf, size, fmt, percent);
337} 337}
338
339int percent_color_len_snprintf(char *bf, size_t size, const char *fmt, ...)
340{
341 va_list args;
342 int len;
343 double percent;
344 const char *color;
345
346 va_start(args, fmt);
347 len = va_arg(args, int);
348 percent = va_arg(args, double);
349 va_end(args);
350
351 color = get_percent_color(percent);
352 return color_snprintf(bf, size, color, fmt, len, percent);
353}
diff --git a/tools/perf/util/color.h b/tools/perf/util/color.h
index 7ff30a62a132..0a594b8a0c26 100644
--- a/tools/perf/util/color.h
+++ b/tools/perf/util/color.h
@@ -41,6 +41,7 @@ int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...);
41int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf); 41int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf);
42int value_color_snprintf(char *bf, size_t size, const char *fmt, double value); 42int value_color_snprintf(char *bf, size_t size, const char *fmt, double value);
43int percent_color_snprintf(char *bf, size_t size, const char *fmt, ...); 43int percent_color_snprintf(char *bf, size_t size, const char *fmt, ...);
44int percent_color_len_snprintf(char *bf, size_t size, const char *fmt, ...);
44int percent_color_fprintf(FILE *fp, const char *fmt, double percent); 45int percent_color_fprintf(FILE *fp, const char *fmt, double percent);
45const char *get_percent_color(double percent); 46const char *get_percent_color(double percent);
46 47
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 742f49a85725..13d074db9ef1 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -267,10 +267,10 @@ typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front);
267typedef int (*hpp_snprint_fn)(struct perf_hpp *hpp, const char *fmt, ...); 267typedef int (*hpp_snprint_fn)(struct perf_hpp *hpp, const char *fmt, ...);
268 268
269int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, 269int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
270 hpp_field_fn get_field, const char *fmt, 270 hpp_field_fn get_field, const char *fmt, int len,
271 hpp_snprint_fn print_fn, bool fmt_percent); 271 hpp_snprint_fn print_fn, bool fmt_percent);
272int __hpp__fmt_acc(struct perf_hpp *hpp, struct hist_entry *he, 272int __hpp__fmt_acc(struct perf_hpp *hpp, struct hist_entry *he,
273 hpp_field_fn get_field, const char *fmt, 273 hpp_field_fn get_field, const char *fmt, int len,
274 hpp_snprint_fn print_fn, bool fmt_percent); 274 hpp_snprint_fn print_fn, bool fmt_percent);
275 275
276static inline void advance_hpp(struct perf_hpp *hpp, int inc) 276static inline void advance_hpp(struct perf_hpp *hpp, int inc)