aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/ui/hist.c
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2014-07-31 01:47:38 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-08-12 11:03:06 -0400
commit5b5916696051b88e63f3726cc3db44bf9561bad9 (patch)
tree432d11af8cf78cf56bbda7f8ffa33085fc1101e1 /tools/perf/ui/hist.c
parente0d66c74b09f5103eef441a98b68056c4dae4cac (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/ui/hist.c')
-rw-r--r--tools/perf/ui/hist.c84
1 files changed, 58 insertions, 26 deletions
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
18int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, 18static 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
107int __hpp__fmt_acc(struct perf_hpp *hpp, struct hist_entry *he, 107int 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
126int 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
119static int field_cmp(u64 field_a, u64 field_b) 138static 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) \
253static int hpp__color_##_type(struct perf_hpp_fmt *fmt, \ 272static 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) \
262static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \ 280static 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) \
282static int hpp__color_##_type(struct perf_hpp_fmt *fmt, \ 299static 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) \
291static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \ 307static 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) \
311static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \ 326static 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
684void 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}