diff options
author | Namhyung Kim <namhyung@kernel.org> | 2014-07-31 01:47:38 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-08-12 11:03:06 -0400 |
commit | 5b5916696051b88e63f3726cc3db44bf9561bad9 (patch) | |
tree | 432d11af8cf78cf56bbda7f8ffa33085fc1101e1 /tools/perf | |
parent | e0d66c74b09f5103eef441a98b68056c4dae4cac (diff) |
perf report: Honor column width setting
Set column width and do not change it if user gives -w/--column-widths
option. It'll truncate longer symbols than the width if exists.
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-5-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/ui/browsers/hists.c | 18 | ||||
-rw-r--r-- | tools/perf/ui/gtk/hists.c | 10 | ||||
-rw-r--r-- | tools/perf/ui/hist.c | 84 | ||||
-rw-r--r-- | tools/perf/ui/stdio/hist.c | 4 | ||||
-rw-r--r-- | tools/perf/util/hist.h | 14 | ||||
-rw-r--r-- | tools/perf/util/sort.c | 49 |
6 files changed, 116 insertions, 63 deletions
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index c1d8d3925fe1..e07d4e848d5c 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c | |||
@@ -678,12 +678,12 @@ static u64 __hpp_get_##_field(struct hist_entry *he) \ | |||
678 | } \ | 678 | } \ |
679 | \ | 679 | \ |
680 | static int \ | 680 | static int \ |
681 | hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,\ | 681 | hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt, \ |
682 | struct perf_hpp *hpp, \ | 682 | struct perf_hpp *hpp, \ |
683 | struct hist_entry *he) \ | 683 | struct hist_entry *he) \ |
684 | { \ | 684 | { \ |
685 | return __hpp__fmt(hpp, he, __hpp_get_##_field, " %*.2f%%", 6, \ | 685 | return hpp__fmt(fmt, hpp, he, __hpp_get_##_field, " %*.2f%%", \ |
686 | __hpp__slsmg_color_printf, true); \ | 686 | __hpp__slsmg_color_printf, true); \ |
687 | } | 687 | } |
688 | 688 | ||
689 | #define __HPP_COLOR_ACC_PERCENT_FN(_type, _field) \ | 689 | #define __HPP_COLOR_ACC_PERCENT_FN(_type, _field) \ |
@@ -693,19 +693,20 @@ static u64 __hpp_get_acc_##_field(struct hist_entry *he) \ | |||
693 | } \ | 693 | } \ |
694 | \ | 694 | \ |
695 | static int \ | 695 | static int \ |
696 | hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,\ | 696 | hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt, \ |
697 | struct perf_hpp *hpp, \ | 697 | struct perf_hpp *hpp, \ |
698 | struct hist_entry *he) \ | 698 | struct hist_entry *he) \ |
699 | { \ | 699 | { \ |
700 | if (!symbol_conf.cumulate_callchain) { \ | 700 | if (!symbol_conf.cumulate_callchain) { \ |
701 | int len = fmt->user_len ?: fmt->len; \ | ||
701 | int ret = scnprintf(hpp->buf, hpp->size, \ | 702 | int ret = scnprintf(hpp->buf, hpp->size, \ |
702 | "%*s", 8, "N/A"); \ | 703 | "%*s", len, "N/A"); \ |
703 | slsmg_printf("%s", hpp->buf); \ | 704 | slsmg_printf("%s", hpp->buf); \ |
704 | \ | 705 | \ |
705 | return ret; \ | 706 | return ret; \ |
706 | } \ | 707 | } \ |
707 | return __hpp__fmt(hpp, he, __hpp_get_acc_##_field, " %*.2f%%", \ | 708 | return hpp__fmt(fmt, hpp, he, __hpp_get_acc_##_field, \ |
708 | 6, __hpp__slsmg_color_printf, true); \ | 709 | " %*.2f%%", __hpp__slsmg_color_printf, true); \ |
709 | } | 710 | } |
710 | 711 | ||
711 | __HPP_COLOR_PERCENT_FN(overhead, period) | 712 | __HPP_COLOR_PERCENT_FN(overhead, period) |
@@ -1549,6 +1550,9 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, | |||
1549 | 1550 | ||
1550 | memset(options, 0, sizeof(options)); | 1551 | memset(options, 0, sizeof(options)); |
1551 | 1552 | ||
1553 | if (symbol_conf.col_width_list_str) | ||
1554 | perf_hpp__set_user_width(symbol_conf.col_width_list_str); | ||
1555 | |||
1552 | while (1) { | 1556 | while (1) { |
1553 | const struct thread *thread = NULL; | 1557 | const struct thread *thread = NULL; |
1554 | const struct dso *dso = NULL; | 1558 | const struct dso *dso = NULL; |
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c index 91f6cd7d2312..897b2e140428 100644 --- a/tools/perf/ui/gtk/hists.c +++ b/tools/perf/ui/gtk/hists.c | |||
@@ -41,12 +41,12 @@ static u64 he_get_##_field(struct hist_entry *he) \ | |||
41 | return he->stat._field; \ | 41 | return he->stat._field; \ |
42 | } \ | 42 | } \ |
43 | \ | 43 | \ |
44 | static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ | 44 | static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt, \ |
45 | struct perf_hpp *hpp, \ | 45 | struct perf_hpp *hpp, \ |
46 | struct hist_entry *he) \ | 46 | struct hist_entry *he) \ |
47 | { \ | 47 | { \ |
48 | return __hpp__fmt(hpp, he, he_get_##_field, " %*.2f%%", 6, \ | 48 | return hpp__fmt(fmt, hpp, he, he_get_##_field, " %*.2f%%", \ |
49 | __percent_color_snprintf, true); \ | 49 | __percent_color_snprintf, true); \ |
50 | } | 50 | } |
51 | 51 | ||
52 | #define __HPP_COLOR_ACC_PERCENT_FN(_type, _field) \ | 52 | #define __HPP_COLOR_ACC_PERCENT_FN(_type, _field) \ |
@@ -59,8 +59,8 @@ static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, | |||
59 | struct perf_hpp *hpp, \ | 59 | struct perf_hpp *hpp, \ |
60 | struct hist_entry *he) \ | 60 | struct hist_entry *he) \ |
61 | { \ | 61 | { \ |
62 | return __hpp__fmt_acc(hpp, he, he_get_acc_##_field, " %*.2f%%", 6, \ | 62 | return hpp__fmt_acc(fmt, hpp, he, he_get_acc_##_field, " %*.2f%%", \ |
63 | __percent_color_snprintf, true); \ | 63 | __percent_color_snprintf, true); \ |
64 | } | 64 | } |
65 | 65 | ||
66 | __HPP_COLOR_PERCENT_FN(overhead, period) | 66 | __HPP_COLOR_PERCENT_FN(overhead, period) |
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index e28ca972d046..b2d60a95f01d 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c | |||
@@ -15,9 +15,9 @@ | |||
15 | __ret; \ | 15 | __ret; \ |
16 | }) | 16 | }) |
17 | 17 | ||
18 | int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, | 18 | static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, |
19 | hpp_field_fn get_field, const char *fmt, int len, | 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; |
23 | struct hists *hists = he->hists; | 23 | struct hists *hists = he->hists; |
@@ -104,16 +104,35 @@ int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, | |||
104 | return ret; | 104 | return ret; |
105 | } | 105 | } |
106 | 106 | ||
107 | int __hpp__fmt_acc(struct perf_hpp *hpp, struct hist_entry *he, | 107 | int hpp__fmt(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
108 | hpp_field_fn get_field, const char *fmt, int len, | 108 | struct hist_entry *he, hpp_field_fn get_field, |
109 | hpp_snprint_fn print_fn, bool fmt_percent) | 109 | const char *fmtstr, hpp_snprint_fn print_fn, bool fmt_percent) |
110 | { | ||
111 | int len = fmt->user_len ?: fmt->len; | ||
112 | |||
113 | if (symbol_conf.field_sep) { | ||
114 | return __hpp__fmt(hpp, he, get_field, fmtstr, 1, | ||
115 | print_fn, fmt_percent); | ||
116 | } | ||
117 | |||
118 | if (fmt_percent) | ||
119 | len -= 2; /* 2 for a space and a % sign */ | ||
120 | else | ||
121 | len -= 1; | ||
122 | |||
123 | return __hpp__fmt(hpp, he, get_field, fmtstr, len, print_fn, fmt_percent); | ||
124 | } | ||
125 | |||
126 | int hpp__fmt_acc(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, | ||
127 | struct hist_entry *he, hpp_field_fn get_field, | ||
128 | const char *fmtstr, hpp_snprint_fn print_fn, bool fmt_percent) | ||
110 | { | 129 | { |
111 | if (!symbol_conf.cumulate_callchain) { | 130 | if (!symbol_conf.cumulate_callchain) { |
112 | return snprintf(hpp->buf, hpp->size, "%*s", | 131 | int len = fmt->user_len ?: fmt->len; |
113 | fmt_percent ? len + 2 : len + 1, "N/A"); | 132 | return snprintf(hpp->buf, hpp->size, " %*s", len - 1, "N/A"); |
114 | } | 133 | } |
115 | 134 | ||
116 | return __hpp__fmt(hpp, he, get_field, fmt, len, print_fn, fmt_percent); | 135 | return hpp__fmt(fmt, hpp, he, get_field, fmtstr, print_fn, fmt_percent); |
117 | } | 136 | } |
118 | 137 | ||
119 | static int field_cmp(u64 field_a, u64 field_b) | 138 | static int field_cmp(u64 field_a, u64 field_b) |
@@ -195,10 +214,10 @@ static int hpp__width_##_type(struct perf_hpp_fmt *fmt, \ | |||
195 | struct perf_hpp *hpp __maybe_unused, \ | 214 | struct perf_hpp *hpp __maybe_unused, \ |
196 | struct perf_evsel *evsel) \ | 215 | struct perf_evsel *evsel) \ |
197 | { \ | 216 | { \ |
198 | int len = fmt->len; \ | 217 | int len = fmt->user_len ?: fmt->len; \ |
199 | \ | 218 | \ |
200 | if (symbol_conf.event_group) \ | 219 | if (symbol_conf.event_group) \ |
201 | len = max(len, evsel->nr_members * len); \ | 220 | len = max(len, evsel->nr_members * fmt->len); \ |
202 | \ | 221 | \ |
203 | if (len < (int)strlen(_str)) \ | 222 | if (len < (int)strlen(_str)) \ |
204 | len = strlen(_str); \ | 223 | len = strlen(_str); \ |
@@ -253,18 +272,16 @@ static u64 he_get_##_field(struct hist_entry *he) \ | |||
253 | static int hpp__color_##_type(struct perf_hpp_fmt *fmt, \ | 272 | static int hpp__color_##_type(struct perf_hpp_fmt *fmt, \ |
254 | struct perf_hpp *hpp, struct hist_entry *he) \ | 273 | struct perf_hpp *hpp, struct hist_entry *he) \ |
255 | { \ | 274 | { \ |
256 | int len = fmt->len - 2; /* 2 for a space and a % sign */ \ | 275 | return hpp__fmt(fmt, hpp, he, he_get_##_field, " %*.2f%%", \ |
257 | return __hpp__fmt(hpp, he, he_get_##_field, " %*.2f%%", len, \ | 276 | hpp_color_scnprintf, true); \ |
258 | hpp_color_scnprintf, true); \ | ||
259 | } | 277 | } |
260 | 278 | ||
261 | #define __HPP_ENTRY_PERCENT_FN(_type, _field) \ | 279 | #define __HPP_ENTRY_PERCENT_FN(_type, _field) \ |
262 | static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \ | 280 | static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \ |
263 | struct perf_hpp *hpp, struct hist_entry *he) \ | 281 | struct perf_hpp *hpp, struct hist_entry *he) \ |
264 | { \ | 282 | { \ |
265 | int len = symbol_conf.field_sep ? 1 : fmt->len - 2; \ | 283 | return hpp__fmt(fmt, hpp, he, he_get_##_field, " %*.2f%%", \ |
266 | return __hpp__fmt(hpp, he, he_get_##_field, " %*.2f%%", len, \ | 284 | hpp_entry_scnprintf, true); \ |
267 | hpp_entry_scnprintf, true); \ | ||
268 | } | 285 | } |
269 | 286 | ||
270 | #define __HPP_SORT_FN(_type, _field) \ | 287 | #define __HPP_SORT_FN(_type, _field) \ |
@@ -282,18 +299,16 @@ static u64 he_get_acc_##_field(struct hist_entry *he) \ | |||
282 | static int hpp__color_##_type(struct perf_hpp_fmt *fmt, \ | 299 | static int hpp__color_##_type(struct perf_hpp_fmt *fmt, \ |
283 | struct perf_hpp *hpp, struct hist_entry *he) \ | 300 | struct perf_hpp *hpp, struct hist_entry *he) \ |
284 | { \ | 301 | { \ |
285 | int len = fmt->len - 2; /* 2 for a space and a % sign */ \ | 302 | return hpp__fmt_acc(fmt, hpp, he, he_get_acc_##_field, " %*.2f%%", \ |
286 | return __hpp__fmt_acc(hpp, he, he_get_acc_##_field, " %*.2f%%", len, \ | 303 | hpp_color_scnprintf, true); \ |
287 | hpp_color_scnprintf, true); \ | ||
288 | } | 304 | } |
289 | 305 | ||
290 | #define __HPP_ENTRY_ACC_PERCENT_FN(_type, _field) \ | 306 | #define __HPP_ENTRY_ACC_PERCENT_FN(_type, _field) \ |
291 | static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \ | 307 | static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \ |
292 | struct perf_hpp *hpp, struct hist_entry *he) \ | 308 | struct perf_hpp *hpp, struct hist_entry *he) \ |
293 | { \ | 309 | { \ |
294 | int len = symbol_conf.field_sep ? 1 : fmt->len - 2; \ | 310 | return hpp__fmt_acc(fmt, hpp, he, he_get_##_field, " %*.2f%%", \ |
295 | return __hpp__fmt_acc(hpp, he, he_get_##_field, " %*.2f%%", len, \ | 311 | hpp_entry_scnprintf, true); \ |
296 | hpp_entry_scnprintf, true); \ | ||
297 | } | 312 | } |
298 | 313 | ||
299 | #define __HPP_SORT_ACC_FN(_type, _field) \ | 314 | #define __HPP_SORT_ACC_FN(_type, _field) \ |
@@ -311,9 +326,8 @@ static u64 he_get_raw_##_field(struct hist_entry *he) \ | |||
311 | static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \ | 326 | static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \ |
312 | struct perf_hpp *hpp, struct hist_entry *he) \ | 327 | struct perf_hpp *hpp, struct hist_entry *he) \ |
313 | { \ | 328 | { \ |
314 | int len = symbol_conf.field_sep ? 1 : fmt->len - 1; \ | 329 | return hpp__fmt(fmt, hpp, he, he_get_raw_##_field, " %*"PRIu64, \ |
315 | return __hpp__fmt(hpp, he, he_get_raw_##_field, " %*"PRIu64, len, \ | 330 | hpp_entry_scnprintf, false); \ |
316 | hpp_entry_scnprintf, false); \ | ||
317 | } | 331 | } |
318 | 332 | ||
319 | #define __HPP_SORT_RAW_FN(_type, _field) \ | 333 | #define __HPP_SORT_RAW_FN(_type, _field) \ |
@@ -666,3 +680,21 @@ void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists) | |||
666 | break; | 680 | break; |
667 | } | 681 | } |
668 | } | 682 | } |
683 | |||
684 | void perf_hpp__set_user_width(const char *width_list_str) | ||
685 | { | ||
686 | struct perf_hpp_fmt *fmt; | ||
687 | const char *ptr = width_list_str; | ||
688 | |||
689 | perf_hpp__for_each_format(fmt) { | ||
690 | char *p; | ||
691 | |||
692 | int len = strtol(ptr, &p, 10); | ||
693 | fmt->user_len = len; | ||
694 | |||
695 | if (*p == ',') | ||
696 | ptr = p + 1; | ||
697 | else | ||
698 | break; | ||
699 | } | ||
700 | } | ||
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index 40af0acb4fe9..15b451acbde6 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c | |||
@@ -395,10 +395,12 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, | |||
395 | 395 | ||
396 | init_rem_hits(); | 396 | init_rem_hits(); |
397 | 397 | ||
398 | |||
399 | perf_hpp__for_each_format(fmt) | 398 | perf_hpp__for_each_format(fmt) |
400 | perf_hpp__reset_width(fmt, hists); | 399 | perf_hpp__reset_width(fmt, hists); |
401 | 400 | ||
401 | if (symbol_conf.col_width_list_str) | ||
402 | perf_hpp__set_user_width(symbol_conf.col_width_list_str); | ||
403 | |||
402 | if (!show_header) | 404 | if (!show_header) |
403 | goto print_entries; | 405 | goto print_entries; |
404 | 406 | ||
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index a7ae890f4c71..2e70003fcd00 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h | |||
@@ -208,6 +208,7 @@ struct perf_hpp_fmt { | |||
208 | struct list_head sort_list; | 208 | struct list_head sort_list; |
209 | bool elide; | 209 | bool elide; |
210 | int len; | 210 | int len; |
211 | int user_len; | ||
211 | }; | 212 | }; |
212 | 213 | ||
213 | extern struct list_head perf_hpp__list; | 214 | extern struct list_head perf_hpp__list; |
@@ -263,17 +264,18 @@ static inline bool perf_hpp__should_skip(struct perf_hpp_fmt *format) | |||
263 | 264 | ||
264 | void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists); | 265 | void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists); |
265 | void perf_hpp__reset_sort_width(struct perf_hpp_fmt *fmt, struct hists *hists); | 266 | void perf_hpp__reset_sort_width(struct perf_hpp_fmt *fmt, struct hists *hists); |
267 | void perf_hpp__set_user_width(const char *width_list_str); | ||
266 | 268 | ||
267 | typedef u64 (*hpp_field_fn)(struct hist_entry *he); | 269 | typedef u64 (*hpp_field_fn)(struct hist_entry *he); |
268 | typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front); | 270 | typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front); |
269 | typedef int (*hpp_snprint_fn)(struct perf_hpp *hpp, const char *fmt, ...); | 271 | typedef int (*hpp_snprint_fn)(struct perf_hpp *hpp, const char *fmt, ...); |
270 | 272 | ||
271 | int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, | 273 | int hpp__fmt(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
272 | hpp_field_fn get_field, const char *fmt, int len, | 274 | struct hist_entry *he, hpp_field_fn get_field, |
273 | hpp_snprint_fn print_fn, bool fmt_percent); | 275 | const char *fmtstr, hpp_snprint_fn print_fn, bool fmt_percent); |
274 | int __hpp__fmt_acc(struct perf_hpp *hpp, struct hist_entry *he, | 276 | int hpp__fmt_acc(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
275 | hpp_field_fn get_field, const char *fmt, int len, | 277 | struct hist_entry *he, hpp_field_fn get_field, |
276 | hpp_snprint_fn print_fn, bool fmt_percent); | 278 | const char *fmtstr, hpp_snprint_fn print_fn, bool fmt_percent); |
277 | 279 | ||
278 | static inline void advance_hpp(struct perf_hpp *hpp, int inc) | 280 | static inline void advance_hpp(struct perf_hpp *hpp, int inc) |
279 | { | 281 | { |
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index a7f8a7b0eced..153b3803f0b7 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c | |||
@@ -70,8 +70,10 @@ static int hist_entry__thread_snprintf(struct hist_entry *he, char *bf, | |||
70 | size_t size, unsigned int width) | 70 | size_t size, unsigned int width) |
71 | { | 71 | { |
72 | const char *comm = thread__comm_str(he->thread); | 72 | const char *comm = thread__comm_str(he->thread); |
73 | return repsep_snprintf(bf, size, "%5d:%-*s", he->thread->tid, | 73 | |
74 | width - 6, comm ?: ""); | 74 | width = max(7U, width) - 6; |
75 | return repsep_snprintf(bf, size, "%5d:%-*.*s", he->thread->tid, | ||
76 | width, width, comm ?: ""); | ||
75 | } | 77 | } |
76 | 78 | ||
77 | struct sort_entry sort_thread = { | 79 | struct sort_entry sort_thread = { |
@@ -106,7 +108,7 @@ sort__comm_sort(struct hist_entry *left, struct hist_entry *right) | |||
106 | static int hist_entry__comm_snprintf(struct hist_entry *he, char *bf, | 108 | static int hist_entry__comm_snprintf(struct hist_entry *he, char *bf, |
107 | size_t size, unsigned int width) | 109 | size_t size, unsigned int width) |
108 | { | 110 | { |
109 | return repsep_snprintf(bf, size, "%-*s", width, comm__str(he->comm)); | 111 | return repsep_snprintf(bf, size, "%-*.*s", width, width, comm__str(he->comm)); |
110 | } | 112 | } |
111 | 113 | ||
112 | struct sort_entry sort_comm = { | 114 | struct sort_entry sort_comm = { |
@@ -152,10 +154,10 @@ static int _hist_entry__dso_snprintf(struct map *map, char *bf, | |||
152 | if (map && map->dso) { | 154 | if (map && map->dso) { |
153 | const char *dso_name = !verbose ? map->dso->short_name : | 155 | const char *dso_name = !verbose ? map->dso->short_name : |
154 | map->dso->long_name; | 156 | map->dso->long_name; |
155 | return repsep_snprintf(bf, size, "%-*s", width, dso_name); | 157 | return repsep_snprintf(bf, size, "%-*.*s", width, width, dso_name); |
156 | } | 158 | } |
157 | 159 | ||
158 | return repsep_snprintf(bf, size, "%-*s", width, "[unknown]"); | 160 | return repsep_snprintf(bf, size, "%-*.*s", width, width, "[unknown]"); |
159 | } | 161 | } |
160 | 162 | ||
161 | static int hist_entry__dso_snprintf(struct hist_entry *he, char *bf, | 163 | static int hist_entry__dso_snprintf(struct hist_entry *he, char *bf, |
@@ -257,7 +259,10 @@ static int _hist_entry__sym_snprintf(struct map *map, struct symbol *sym, | |||
257 | width - ret, ""); | 259 | width - ret, ""); |
258 | } | 260 | } |
259 | 261 | ||
260 | return ret; | 262 | if (ret > width) |
263 | bf[width] = '\0'; | ||
264 | |||
265 | return width; | ||
261 | } | 266 | } |
262 | 267 | ||
263 | static int hist_entry__sym_snprintf(struct hist_entry *he, char *bf, | 268 | static int hist_entry__sym_snprintf(struct hist_entry *he, char *bf, |
@@ -302,10 +307,9 @@ sort__srcline_cmp(struct hist_entry *left, struct hist_entry *right) | |||
302 | } | 307 | } |
303 | 308 | ||
304 | static int hist_entry__srcline_snprintf(struct hist_entry *he, char *bf, | 309 | static int hist_entry__srcline_snprintf(struct hist_entry *he, char *bf, |
305 | size_t size, | 310 | size_t size, unsigned int width) |
306 | unsigned int width __maybe_unused) | ||
307 | { | 311 | { |
308 | return repsep_snprintf(bf, size, "%-s", he->srcline); | 312 | return repsep_snprintf(bf, size, "%*.*-s", width, width, he->srcline); |
309 | } | 313 | } |
310 | 314 | ||
311 | struct sort_entry sort_srcline = { | 315 | struct sort_entry sort_srcline = { |
@@ -332,7 +336,7 @@ sort__parent_cmp(struct hist_entry *left, struct hist_entry *right) | |||
332 | static int hist_entry__parent_snprintf(struct hist_entry *he, char *bf, | 336 | static int hist_entry__parent_snprintf(struct hist_entry *he, char *bf, |
333 | size_t size, unsigned int width) | 337 | size_t size, unsigned int width) |
334 | { | 338 | { |
335 | return repsep_snprintf(bf, size, "%-*s", width, | 339 | return repsep_snprintf(bf, size, "%-*.*s", width, width, |
336 | he->parent ? he->parent->name : "[other]"); | 340 | he->parent ? he->parent->name : "[other]"); |
337 | } | 341 | } |
338 | 342 | ||
@@ -354,7 +358,7 @@ sort__cpu_cmp(struct hist_entry *left, struct hist_entry *right) | |||
354 | static int hist_entry__cpu_snprintf(struct hist_entry *he, char *bf, | 358 | static int hist_entry__cpu_snprintf(struct hist_entry *he, char *bf, |
355 | size_t size, unsigned int width) | 359 | size_t size, unsigned int width) |
356 | { | 360 | { |
357 | return repsep_snprintf(bf, size, "%*d", width, he->cpu); | 361 | return repsep_snprintf(bf, size, "%*.*d", width, width, he->cpu); |
358 | } | 362 | } |
359 | 363 | ||
360 | struct sort_entry sort_cpu = { | 364 | struct sort_entry sort_cpu = { |
@@ -484,7 +488,7 @@ static int hist_entry__mispredict_snprintf(struct hist_entry *he, char *bf, | |||
484 | else if (he->branch_info->flags.mispred) | 488 | else if (he->branch_info->flags.mispred) |
485 | out = "Y"; | 489 | out = "Y"; |
486 | 490 | ||
487 | return repsep_snprintf(bf, size, "%-*s", width, out); | 491 | return repsep_snprintf(bf, size, "%-*.*s", width, width, out); |
488 | } | 492 | } |
489 | 493 | ||
490 | /* --sort daddr_sym */ | 494 | /* --sort daddr_sym */ |
@@ -1210,12 +1214,14 @@ static int __sort__hpp_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, | |||
1210 | struct perf_evsel *evsel) | 1214 | struct perf_evsel *evsel) |
1211 | { | 1215 | { |
1212 | struct hpp_sort_entry *hse; | 1216 | struct hpp_sort_entry *hse; |
1213 | size_t len; | 1217 | size_t len = fmt->user_len; |
1214 | 1218 | ||
1215 | hse = container_of(fmt, struct hpp_sort_entry, hpp); | 1219 | hse = container_of(fmt, struct hpp_sort_entry, hpp); |
1216 | len = hists__col_len(&evsel->hists, hse->se->se_width_idx); | ||
1217 | 1220 | ||
1218 | return scnprintf(hpp->buf, hpp->size, "%-*s", len, hse->se->se_header); | 1221 | if (!len) |
1222 | len = hists__col_len(&evsel->hists, hse->se->se_width_idx); | ||
1223 | |||
1224 | return scnprintf(hpp->buf, hpp->size, "%-*.*s", len, len, hse->se->se_header); | ||
1219 | } | 1225 | } |
1220 | 1226 | ||
1221 | static int __sort__hpp_width(struct perf_hpp_fmt *fmt, | 1227 | static int __sort__hpp_width(struct perf_hpp_fmt *fmt, |
@@ -1223,20 +1229,26 @@ static int __sort__hpp_width(struct perf_hpp_fmt *fmt, | |||
1223 | struct perf_evsel *evsel) | 1229 | struct perf_evsel *evsel) |
1224 | { | 1230 | { |
1225 | struct hpp_sort_entry *hse; | 1231 | struct hpp_sort_entry *hse; |
1232 | size_t len = fmt->user_len; | ||
1226 | 1233 | ||
1227 | hse = container_of(fmt, struct hpp_sort_entry, hpp); | 1234 | hse = container_of(fmt, struct hpp_sort_entry, hpp); |
1228 | 1235 | ||
1229 | return hists__col_len(&evsel->hists, hse->se->se_width_idx); | 1236 | if (!len) |
1237 | len = hists__col_len(&evsel->hists, hse->se->se_width_idx); | ||
1238 | |||
1239 | return len; | ||
1230 | } | 1240 | } |
1231 | 1241 | ||
1232 | static int __sort__hpp_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, | 1242 | static int __sort__hpp_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
1233 | struct hist_entry *he) | 1243 | struct hist_entry *he) |
1234 | { | 1244 | { |
1235 | struct hpp_sort_entry *hse; | 1245 | struct hpp_sort_entry *hse; |
1236 | size_t len; | 1246 | size_t len = fmt->user_len; |
1237 | 1247 | ||
1238 | hse = container_of(fmt, struct hpp_sort_entry, hpp); | 1248 | hse = container_of(fmt, struct hpp_sort_entry, hpp); |
1239 | len = hists__col_len(he->hists, hse->se->se_width_idx); | 1249 | |
1250 | if (!len) | ||
1251 | len = hists__col_len(he->hists, hse->se->se_width_idx); | ||
1240 | 1252 | ||
1241 | return hse->se->se_snprintf(he, hpp->buf, hpp->size, len); | 1253 | return hse->se->se_snprintf(he, hpp->buf, hpp->size, len); |
1242 | } | 1254 | } |
@@ -1266,6 +1278,7 @@ __sort_dimension__alloc_hpp(struct sort_dimension *sd) | |||
1266 | INIT_LIST_HEAD(&hse->hpp.sort_list); | 1278 | INIT_LIST_HEAD(&hse->hpp.sort_list); |
1267 | hse->hpp.elide = false; | 1279 | hse->hpp.elide = false; |
1268 | hse->hpp.len = 0; | 1280 | hse->hpp.len = 0; |
1281 | hse->hpp.user_len = 0; | ||
1269 | 1282 | ||
1270 | return hse; | 1283 | return hse; |
1271 | } | 1284 | } |