aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2014-07-31 01:47:37 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-08-12 11:03:05 -0400
commite0d66c74b09f5103eef441a98b68056c4dae4cac (patch)
treea4836c6858102a1cf4e42efb1df2b922f56403da
parentd675107ce6fa988102851e0b0ef06e46c8aa7ac6 (diff)
perf tools: Save column length in perf_hpp_fmt
Save column length in the hpp format and pass it to print functions. This is a preparation for users to control column width in the output. 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-4-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/ui/browsers/hists.c2
-rw-r--r--tools/perf/ui/hist.c135
-rw-r--r--tools/perf/util/hist.h2
-rw-r--r--tools/perf/util/sort.c3
4 files changed, 94 insertions, 48 deletions
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 02507ba944e3..c1d8d3925fe1 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -849,7 +849,7 @@ static int hists__scnprintf_headers(char *buf, size_t size, struct hists *hists)
849 if (perf_hpp__should_skip(fmt)) 849 if (perf_hpp__should_skip(fmt))
850 continue; 850 continue;
851 851
852 /* We need to add the length of the columns header. */ 852 /* We need to ensure length of the columns header. */
853 perf_hpp__reset_width(fmt, hists); 853 perf_hpp__reset_width(fmt, hists);
854 854
855 ret = fmt->header(fmt, &dummy_hpp, hists_to_evsel(hists)); 855 ret = fmt->header(fmt, &dummy_hpp, hists_to_evsel(hists));
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index c6cffbd0b0e1..e28ca972d046 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -110,7 +110,7 @@ int __hpp__fmt_acc(struct perf_hpp *hpp, struct hist_entry *he,
110{ 110{
111 if (!symbol_conf.cumulate_callchain) { 111 if (!symbol_conf.cumulate_callchain) {
112 return snprintf(hpp->buf, hpp->size, "%*s", 112 return snprintf(hpp->buf, hpp->size, "%*s",
113 fmt_percent ? 8 : 12, "N/A"); 113 fmt_percent ? len + 2 : len + 1, "N/A");
114 } 114 }
115 115
116 return __hpp__fmt(hpp, he, get_field, fmt, len, print_fn, fmt_percent); 116 return __hpp__fmt(hpp, he, get_field, fmt, len, print_fn, fmt_percent);
@@ -190,32 +190,31 @@ static int __hpp__sort_acc(struct hist_entry *a, struct hist_entry *b,
190 return ret; 190 return ret;
191} 191}
192 192
193#define __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \ 193#define __HPP_WIDTH_FN(_type, _str) \
194static int hpp__header_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ 194static int hpp__width_##_type(struct perf_hpp_fmt *fmt, \
195 struct perf_hpp *hpp, \
196 struct perf_evsel *evsel) \
197{ \
198 int len = _min_width; \
199 \
200 if (symbol_conf.event_group) \
201 len = max(len, evsel->nr_members * _unit_width); \
202 \
203 return scnprintf(hpp->buf, hpp->size, "%*s", len, _str); \
204}
205
206#define __HPP_WIDTH_FN(_type, _min_width, _unit_width) \
207static int hpp__width_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
208 struct perf_hpp *hpp __maybe_unused, \ 195 struct perf_hpp *hpp __maybe_unused, \
209 struct perf_evsel *evsel) \ 196 struct perf_evsel *evsel) \
210{ \ 197{ \
211 int len = _min_width; \ 198 int len = fmt->len; \
212 \ 199 \
213 if (symbol_conf.event_group) \ 200 if (symbol_conf.event_group) \
214 len = max(len, evsel->nr_members * _unit_width); \ 201 len = max(len, evsel->nr_members * len); \
202 \
203 if (len < (int)strlen(_str)) \
204 len = strlen(_str); \
215 \ 205 \
216 return len; \ 206 return len; \
217} 207}
218 208
209#define __HPP_HEADER_FN(_type, _str) \
210static int hpp__header_##_type(struct perf_hpp_fmt *fmt, \
211 struct perf_hpp *hpp, \
212 struct perf_evsel *evsel) \
213{ \
214 int len = hpp__width_##_type(fmt, hpp, evsel); \
215 return scnprintf(hpp->buf, hpp->size, "%*s", len, _str); \
216}
217
219static int hpp_color_scnprintf(struct perf_hpp *hpp, const char *fmt, ...) 218static int hpp_color_scnprintf(struct perf_hpp *hpp, const char *fmt, ...)
220{ 219{
221 va_list args; 220 va_list args;
@@ -251,18 +250,19 @@ static u64 he_get_##_field(struct hist_entry *he) \
251 return he->stat._field; \ 250 return he->stat._field; \
252} \ 251} \
253 \ 252 \
254static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ 253static int hpp__color_##_type(struct perf_hpp_fmt *fmt, \
255 struct perf_hpp *hpp, struct hist_entry *he) \ 254 struct perf_hpp *hpp, struct hist_entry *he) \
256{ \ 255{ \
257 return __hpp__fmt(hpp, he, he_get_##_field, " %*.2f%%", 6, \ 256 int len = fmt->len - 2; /* 2 for a space and a % sign */ \
257 return __hpp__fmt(hpp, he, he_get_##_field, " %*.2f%%", len, \
258 hpp_color_scnprintf, true); \ 258 hpp_color_scnprintf, true); \
259} 259}
260 260
261#define __HPP_ENTRY_PERCENT_FN(_type, _field) \ 261#define __HPP_ENTRY_PERCENT_FN(_type, _field) \
262static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \ 262static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \
263 struct perf_hpp *hpp, struct hist_entry *he) \ 263 struct perf_hpp *hpp, struct hist_entry *he) \
264{ \ 264{ \
265 int len = symbol_conf.field_sep ? 1 : 6; \ 265 int len = symbol_conf.field_sep ? 1 : fmt->len - 2; \
266 return __hpp__fmt(hpp, he, he_get_##_field, " %*.2f%%", len, \ 266 return __hpp__fmt(hpp, he, he_get_##_field, " %*.2f%%", len, \
267 hpp_entry_scnprintf, true); \ 267 hpp_entry_scnprintf, true); \
268} 268}
@@ -279,18 +279,19 @@ static u64 he_get_acc_##_field(struct hist_entry *he) \
279 return he->stat_acc->_field; \ 279 return he->stat_acc->_field; \
280} \ 280} \
281 \ 281 \
282static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ 282static int hpp__color_##_type(struct perf_hpp_fmt *fmt, \
283 struct perf_hpp *hpp, struct hist_entry *he) \ 283 struct perf_hpp *hpp, struct hist_entry *he) \
284{ \ 284{ \
285 return __hpp__fmt_acc(hpp, he, he_get_acc_##_field, " %*.2f%%", 6, \ 285 int len = fmt->len - 2; /* 2 for a space and a % sign */ \
286 return __hpp__fmt_acc(hpp, he, he_get_acc_##_field, " %*.2f%%", len, \
286 hpp_color_scnprintf, true); \ 287 hpp_color_scnprintf, true); \
287} 288}
288 289
289#define __HPP_ENTRY_ACC_PERCENT_FN(_type, _field) \ 290#define __HPP_ENTRY_ACC_PERCENT_FN(_type, _field) \
290static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \ 291static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \
291 struct perf_hpp *hpp, struct hist_entry *he) \ 292 struct perf_hpp *hpp, struct hist_entry *he) \
292{ \ 293{ \
293 int len = symbol_conf.field_sep ? 1 : 6; \ 294 int len = symbol_conf.field_sep ? 1 : fmt->len - 2; \
294 return __hpp__fmt_acc(hpp, he, he_get_##_field, " %*.2f%%", len, \ 295 return __hpp__fmt_acc(hpp, he, he_get_##_field, " %*.2f%%", len, \
295 hpp_entry_scnprintf, true); \ 296 hpp_entry_scnprintf, true); \
296} 297}
@@ -307,10 +308,10 @@ static u64 he_get_raw_##_field(struct hist_entry *he) \
307 return he->stat._field; \ 308 return he->stat._field; \
308} \ 309} \
309 \ 310 \
310static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \ 311static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \
311 struct perf_hpp *hpp, struct hist_entry *he) \ 312 struct perf_hpp *hpp, struct hist_entry *he) \
312{ \ 313{ \
313 int len = symbol_conf.field_sep ? 1 : 11; \ 314 int len = symbol_conf.field_sep ? 1 : fmt->len - 1; \
314 return __hpp__fmt(hpp, he, he_get_raw_##_field, " %*"PRIu64, len, \ 315 return __hpp__fmt(hpp, he, he_get_raw_##_field, " %*"PRIu64, len, \
315 hpp_entry_scnprintf, false); \ 316 hpp_entry_scnprintf, false); \
316} 317}
@@ -322,37 +323,38 @@ static int64_t hpp__sort_##_type(struct hist_entry *a, struct hist_entry *b) \
322} 323}
323 324
324 325
325#define HPP_PERCENT_FNS(_type, _str, _field, _min_width, _unit_width) \ 326#define HPP_PERCENT_FNS(_type, _str, _field) \
326__HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \ 327__HPP_WIDTH_FN(_type, _str) \
327__HPP_WIDTH_FN(_type, _min_width, _unit_width) \ 328__HPP_HEADER_FN(_type, _str) \
328__HPP_COLOR_PERCENT_FN(_type, _field) \ 329__HPP_COLOR_PERCENT_FN(_type, _field) \
329__HPP_ENTRY_PERCENT_FN(_type, _field) \ 330__HPP_ENTRY_PERCENT_FN(_type, _field) \
330__HPP_SORT_FN(_type, _field) 331__HPP_SORT_FN(_type, _field)
331 332
332#define HPP_PERCENT_ACC_FNS(_type, _str, _field, _min_width, _unit_width)\ 333#define HPP_PERCENT_ACC_FNS(_type, _str, _field) \
333__HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \ 334__HPP_WIDTH_FN(_type, _str) \
334__HPP_WIDTH_FN(_type, _min_width, _unit_width) \ 335__HPP_HEADER_FN(_type, _str) \
335__HPP_COLOR_ACC_PERCENT_FN(_type, _field) \ 336__HPP_COLOR_ACC_PERCENT_FN(_type, _field) \
336__HPP_ENTRY_ACC_PERCENT_FN(_type, _field) \ 337__HPP_ENTRY_ACC_PERCENT_FN(_type, _field) \
337__HPP_SORT_ACC_FN(_type, _field) 338__HPP_SORT_ACC_FN(_type, _field)
338 339
339#define HPP_RAW_FNS(_type, _str, _field, _min_width, _unit_width) \ 340#define HPP_RAW_FNS(_type, _str, _field) \
340__HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \ 341__HPP_WIDTH_FN(_type, _str) \
341__HPP_WIDTH_FN(_type, _min_width, _unit_width) \ 342__HPP_HEADER_FN(_type, _str) \
342__HPP_ENTRY_RAW_FN(_type, _field) \ 343__HPP_ENTRY_RAW_FN(_type, _field) \
343__HPP_SORT_RAW_FN(_type, _field) 344__HPP_SORT_RAW_FN(_type, _field)
344 345
345__HPP_HEADER_FN(overhead_self, "Self", 8, 8) 346__HPP_WIDTH_FN(overhead_self, "Self")
347__HPP_HEADER_FN(overhead_self, "Self")
346 348
347HPP_PERCENT_FNS(overhead, "Overhead", period, 8, 8) 349HPP_PERCENT_FNS(overhead, "Overhead", period)
348HPP_PERCENT_FNS(overhead_sys, "sys", period_sys, 8, 8) 350HPP_PERCENT_FNS(overhead_sys, "sys", period_sys)
349HPP_PERCENT_FNS(overhead_us, "usr", period_us, 8, 8) 351HPP_PERCENT_FNS(overhead_us, "usr", period_us)
350HPP_PERCENT_FNS(overhead_guest_sys, "guest sys", period_guest_sys, 9, 8) 352HPP_PERCENT_FNS(overhead_guest_sys, "guest sys", period_guest_sys)
351HPP_PERCENT_FNS(overhead_guest_us, "guest usr", period_guest_us, 9, 8) 353HPP_PERCENT_FNS(overhead_guest_us, "guest usr", period_guest_us)
352HPP_PERCENT_ACC_FNS(overhead_acc, "Children", period, 8, 8) 354HPP_PERCENT_ACC_FNS(overhead_acc, "Children", period)
353 355
354HPP_RAW_FNS(samples, "Samples", nr_events, 12, 12) 356HPP_RAW_FNS(samples, "Samples", nr_events)
355HPP_RAW_FNS(period, "Period", period, 12, 12) 357HPP_RAW_FNS(period, "Period", period)
356 358
357static int64_t hpp__nop_cmp(struct hist_entry *a __maybe_unused, 359static int64_t hpp__nop_cmp(struct hist_entry *a __maybe_unused,
358 struct hist_entry *b __maybe_unused) 360 struct hist_entry *b __maybe_unused)
@@ -453,6 +455,8 @@ void perf_hpp__init(void)
453 455
454 perf_hpp__format[PERF_HPP__OVERHEAD].header = 456 perf_hpp__format[PERF_HPP__OVERHEAD].header =
455 hpp__header_overhead_self; 457 hpp__header_overhead_self;
458 perf_hpp__format[PERF_HPP__OVERHEAD].width =
459 hpp__width_overhead_self;
456 } 460 }
457 461
458 perf_hpp__column_enable(PERF_HPP__OVERHEAD); 462 perf_hpp__column_enable(PERF_HPP__OVERHEAD);
@@ -519,6 +523,7 @@ void perf_hpp__cancel_cumulate(void)
519 523
520 perf_hpp__column_disable(PERF_HPP__OVERHEAD_ACC); 524 perf_hpp__column_disable(PERF_HPP__OVERHEAD_ACC);
521 perf_hpp__format[PERF_HPP__OVERHEAD].header = hpp__header_overhead; 525 perf_hpp__format[PERF_HPP__OVERHEAD].header = hpp__header_overhead;
526 perf_hpp__format[PERF_HPP__OVERHEAD].width = hpp__width_overhead;
522} 527}
523 528
524void perf_hpp__setup_output_field(void) 529void perf_hpp__setup_output_field(void)
@@ -623,3 +628,41 @@ unsigned int hists__sort_list_width(struct hists *hists)
623 628
624 return ret; 629 return ret;
625} 630}
631
632void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists)
633{
634 int idx;
635
636 if (perf_hpp__is_sort_entry(fmt))
637 return perf_hpp__reset_sort_width(fmt, hists);
638
639 for (idx = 0; idx < PERF_HPP__MAX_INDEX; idx++) {
640 if (fmt == &perf_hpp__format[idx])
641 break;
642 }
643
644 if (idx == PERF_HPP__MAX_INDEX)
645 return;
646
647 switch (idx) {
648 case PERF_HPP__OVERHEAD:
649 case PERF_HPP__OVERHEAD_SYS:
650 case PERF_HPP__OVERHEAD_US:
651 case PERF_HPP__OVERHEAD_ACC:
652 fmt->len = 8;
653 break;
654
655 case PERF_HPP__OVERHEAD_GUEST_SYS:
656 case PERF_HPP__OVERHEAD_GUEST_US:
657 fmt->len = 9;
658 break;
659
660 case PERF_HPP__SAMPLES:
661 case PERF_HPP__PERIOD:
662 fmt->len = 12;
663 break;
664
665 default:
666 break;
667 }
668}
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 13d074db9ef1..a7ae890f4c71 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -207,6 +207,7 @@ struct perf_hpp_fmt {
207 struct list_head list; 207 struct list_head list;
208 struct list_head sort_list; 208 struct list_head sort_list;
209 bool elide; 209 bool elide;
210 int len;
210}; 211};
211 212
212extern struct list_head perf_hpp__list; 213extern struct list_head perf_hpp__list;
@@ -261,6 +262,7 @@ static inline bool perf_hpp__should_skip(struct perf_hpp_fmt *format)
261} 262}
262 263
263void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists); 264void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists);
265void perf_hpp__reset_sort_width(struct perf_hpp_fmt *fmt, struct hists *hists);
264 266
265typedef u64 (*hpp_field_fn)(struct hist_entry *he); 267typedef u64 (*hpp_field_fn)(struct hist_entry *he);
266typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front); 268typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front);
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index eda9ee836cee..a7f8a7b0eced 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -1194,7 +1194,7 @@ bool perf_hpp__same_sort_entry(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b)
1194 return hse_a->se == hse_b->se; 1194 return hse_a->se == hse_b->se;
1195} 1195}
1196 1196
1197void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists) 1197void perf_hpp__reset_sort_width(struct perf_hpp_fmt *fmt, struct hists *hists)
1198{ 1198{
1199 struct hpp_sort_entry *hse; 1199 struct hpp_sort_entry *hse;
1200 1200
@@ -1265,6 +1265,7 @@ __sort_dimension__alloc_hpp(struct sort_dimension *sd)
1265 INIT_LIST_HEAD(&hse->hpp.list); 1265 INIT_LIST_HEAD(&hse->hpp.list);
1266 INIT_LIST_HEAD(&hse->hpp.sort_list); 1266 INIT_LIST_HEAD(&hse->hpp.sort_list);
1267 hse->hpp.elide = false; 1267 hse->hpp.elide = false;
1268 hse->hpp.len = 0;
1268 1269
1269 return hse; 1270 return hse;
1270} 1271}