Skip to content

Commit e0d66c7

Browse files
namhyungacmel
authored andcommitted
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>
1 parent d675107 commit e0d66c7

4 files changed

Lines changed: 94 additions & 48 deletions

File tree

‎tools/perf/ui/browsers/hists.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ static int hists__scnprintf_headers(char *buf, size_t size, struct hists *hists)
849849
if (perf_hpp__should_skip(fmt))
850850
continue;
851851

852-
/* We need to add the length of the columns header. */
852+
/* We need to ensure length of the columns header. */
853853
perf_hpp__reset_width(fmt, hists);
854854

855855
ret = fmt->header(fmt, &dummy_hpp, hists_to_evsel(hists));

‎tools/perf/ui/hist.c‎

Lines changed: 89 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ int __hpp__fmt_acc(struct perf_hpp *hpp, struct hist_entry *he,
110110
{
111111
if (!symbol_conf.cumulate_callchain) {
112112
return snprintf(hpp->buf, hpp->size, "%*s",
113-
fmt_percent ? 8 : 12, "N/A");
113+
fmt_percent ? len + 2 : len + 1, "N/A");
114114
}
115115

116116
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,
190190
return ret;
191191
}
192192

193-
#define __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \
194-
static int hpp__header_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
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) \
207-
static int hpp__width_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
193+
#define __HPP_WIDTH_FN(_type, _str) \
194+
static int hpp__width_##_type(struct perf_hpp_fmt *fmt, \
208195
struct perf_hpp *hpp __maybe_unused, \
209196
struct perf_evsel *evsel) \
210197
{ \
211-
int len = _min_width; \
198+
int len = fmt->len; \
212199
\
213200
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); \
215205
\
216206
return len; \
217207
}
218208

209+
#define __HPP_HEADER_FN(_type, _str) \
210+
static 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+
219218
static int hpp_color_scnprintf(struct perf_hpp *hpp, const char *fmt, ...)
220219
{
221220
va_list args;
@@ -251,18 +250,19 @@ static u64 he_get_##_field(struct hist_entry *he) \
251250
return he->stat._field; \
252251
} \
253252
\
254-
static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
253+
static int hpp__color_##_type(struct perf_hpp_fmt *fmt, \
255254
struct perf_hpp *hpp, struct hist_entry *he) \
256255
{ \
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, \
258258
hpp_color_scnprintf, true); \
259259
}
260260

261261
#define __HPP_ENTRY_PERCENT_FN(_type, _field) \
262-
static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \
262+
static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \
263263
struct perf_hpp *hpp, struct hist_entry *he) \
264264
{ \
265-
int len = symbol_conf.field_sep ? 1 : 6; \
265+
int len = symbol_conf.field_sep ? 1 : fmt->len - 2; \
266266
return __hpp__fmt(hpp, he, he_get_##_field, " %*.2f%%", len, \
267267
hpp_entry_scnprintf, true); \
268268
}
@@ -279,18 +279,19 @@ static u64 he_get_acc_##_field(struct hist_entry *he) \
279279
return he->stat_acc->_field; \
280280
} \
281281
\
282-
static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
282+
static int hpp__color_##_type(struct perf_hpp_fmt *fmt, \
283283
struct perf_hpp *hpp, struct hist_entry *he) \
284284
{ \
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, \
286287
hpp_color_scnprintf, true); \
287288
}
288289

289290
#define __HPP_ENTRY_ACC_PERCENT_FN(_type, _field) \
290-
static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \
291+
static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \
291292
struct perf_hpp *hpp, struct hist_entry *he) \
292293
{ \
293-
int len = symbol_conf.field_sep ? 1 : 6; \
294+
int len = symbol_conf.field_sep ? 1 : fmt->len - 2; \
294295
return __hpp__fmt_acc(hpp, he, he_get_##_field, " %*.2f%%", len, \
295296
hpp_entry_scnprintf, true); \
296297
}
@@ -307,10 +308,10 @@ static u64 he_get_raw_##_field(struct hist_entry *he) \
307308
return he->stat._field; \
308309
} \
309310
\
310-
static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \
311+
static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \
311312
struct perf_hpp *hpp, struct hist_entry *he) \
312313
{ \
313-
int len = symbol_conf.field_sep ? 1 : 11; \
314+
int len = symbol_conf.field_sep ? 1 : fmt->len - 1; \
314315
return __hpp__fmt(hpp, he, he_get_raw_##_field, " %*"PRIu64, len, \
315316
hpp_entry_scnprintf, false); \
316317
}
@@ -322,37 +323,38 @@ static int64_t hpp__sort_##_type(struct hist_entry *a, struct hist_entry *b) \
322323
}
323324

324325

325-
#define HPP_PERCENT_FNS(_type, _str, _field, _min_width, _unit_width) \
326-
__HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \
327-
__HPP_WIDTH_FN(_type, _min_width, _unit_width) \
326+
#define HPP_PERCENT_FNS(_type, _str, _field) \
327+
__HPP_WIDTH_FN(_type, _str) \
328+
__HPP_HEADER_FN(_type, _str) \
328329
__HPP_COLOR_PERCENT_FN(_type, _field) \
329330
__HPP_ENTRY_PERCENT_FN(_type, _field) \
330331
__HPP_SORT_FN(_type, _field)
331332

332-
#define HPP_PERCENT_ACC_FNS(_type, _str, _field, _min_width, _unit_width)\
333-
__HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \
334-
__HPP_WIDTH_FN(_type, _min_width, _unit_width) \
333+
#define HPP_PERCENT_ACC_FNS(_type, _str, _field) \
334+
__HPP_WIDTH_FN(_type, _str) \
335+
__HPP_HEADER_FN(_type, _str) \
335336
__HPP_COLOR_ACC_PERCENT_FN(_type, _field) \
336337
__HPP_ENTRY_ACC_PERCENT_FN(_type, _field) \
337338
__HPP_SORT_ACC_FN(_type, _field)
338339

339-
#define HPP_RAW_FNS(_type, _str, _field, _min_width, _unit_width) \
340-
__HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \
341-
__HPP_WIDTH_FN(_type, _min_width, _unit_width) \
340+
#define HPP_RAW_FNS(_type, _str, _field) \
341+
__HPP_WIDTH_FN(_type, _str) \
342+
__HPP_HEADER_FN(_type, _str) \
342343
__HPP_ENTRY_RAW_FN(_type, _field) \
343344
__HPP_SORT_RAW_FN(_type, _field)
344345

345-
__HPP_HEADER_FN(overhead_self, "Self", 8, 8)
346+
__HPP_WIDTH_FN(overhead_self, "Self")
347+
__HPP_HEADER_FN(overhead_self, "Self")
346348

347-
HPP_PERCENT_FNS(overhead, "Overhead", period, 8, 8)
348-
HPP_PERCENT_FNS(overhead_sys, "sys", period_sys, 8, 8)
349-
HPP_PERCENT_FNS(overhead_us, "usr", period_us, 8, 8)
350-
HPP_PERCENT_FNS(overhead_guest_sys, "guest sys", period_guest_sys, 9, 8)
351-
HPP_PERCENT_FNS(overhead_guest_us, "guest usr", period_guest_us, 9, 8)
352-
HPP_PERCENT_ACC_FNS(overhead_acc, "Children", period, 8, 8)
349+
HPP_PERCENT_FNS(overhead, "Overhead", period)
350+
HPP_PERCENT_FNS(overhead_sys, "sys", period_sys)
351+
HPP_PERCENT_FNS(overhead_us, "usr", period_us)
352+
HPP_PERCENT_FNS(overhead_guest_sys, "guest sys", period_guest_sys)
353+
HPP_PERCENT_FNS(overhead_guest_us, "guest usr", period_guest_us)
354+
HPP_PERCENT_ACC_FNS(overhead_acc, "Children", period)
353355

354-
HPP_RAW_FNS(samples, "Samples", nr_events, 12, 12)
355-
HPP_RAW_FNS(period, "Period", period, 12, 12)
356+
HPP_RAW_FNS(samples, "Samples", nr_events)
357+
HPP_RAW_FNS(period, "Period", period)
356358

357359
static int64_t hpp__nop_cmp(struct hist_entry *a __maybe_unused,
358360
struct hist_entry *b __maybe_unused)
@@ -453,6 +455,8 @@ void perf_hpp__init(void)
453455

454456
perf_hpp__format[PERF_HPP__OVERHEAD].header =
455457
hpp__header_overhead_self;
458+
perf_hpp__format[PERF_HPP__OVERHEAD].width =
459+
hpp__width_overhead_self;
456460
}
457461

458462
perf_hpp__column_enable(PERF_HPP__OVERHEAD);
@@ -519,6 +523,7 @@ void perf_hpp__cancel_cumulate(void)
519523

520524
perf_hpp__column_disable(PERF_HPP__OVERHEAD_ACC);
521525
perf_hpp__format[PERF_HPP__OVERHEAD].header = hpp__header_overhead;
526+
perf_hpp__format[PERF_HPP__OVERHEAD].width = hpp__width_overhead;
522527
}
523528

524529
void perf_hpp__setup_output_field(void)
@@ -623,3 +628,41 @@ unsigned int hists__sort_list_width(struct hists *hists)
623628

624629
return ret;
625630
}
631+
632+
void 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+
}

‎tools/perf/util/hist.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ struct perf_hpp_fmt {
207207
struct list_head list;
208208
struct list_head sort_list;
209209
bool elide;
210+
int len;
210211
};
211212

212213
extern struct list_head perf_hpp__list;
@@ -261,6 +262,7 @@ static inline bool perf_hpp__should_skip(struct perf_hpp_fmt *format)
261262
}
262263

263264
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);
264266

265267
typedef u64 (*hpp_field_fn)(struct hist_entry *he);
266268
typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front);

‎tools/perf/util/sort.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ bool perf_hpp__same_sort_entry(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b)
11941194
return hse_a->se == hse_b->se;
11951195
}
11961196

1197-
void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists)
1197+
void perf_hpp__reset_sort_width(struct perf_hpp_fmt *fmt, struct hists *hists)
11981198
{
11991199
struct hpp_sort_entry *hse;
12001200

@@ -1265,6 +1265,7 @@ __sort_dimension__alloc_hpp(struct sort_dimension *sd)
12651265
INIT_LIST_HEAD(&hse->hpp.list);
12661266
INIT_LIST_HEAD(&hse->hpp.sort_list);
12671267
hse->hpp.elide = false;
1268+
hse->hpp.len = 0;
12681269

12691270
return hse;
12701271
}

0 commit comments

Comments
 (0)