Skip to content

Commit

Permalink
perf report: Honor column width setting
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Namhyung Kim authored and Arnaldo Carvalho de Melo committed Aug 12, 2014
1 parent e0d66c7 commit 5b59166
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 63 deletions.
18 changes: 11 additions & 7 deletions tools/perf/ui/browsers/hists.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,12 +678,12 @@ static u64 __hpp_get_##_field(struct hist_entry *he) \
} \
\
static int \
hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,\
hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt, \
struct perf_hpp *hpp, \
struct hist_entry *he) \
{ \
return __hpp__fmt(hpp, he, __hpp_get_##_field, " %*.2f%%", 6, \
__hpp__slsmg_color_printf, true); \
return hpp__fmt(fmt, hpp, he, __hpp_get_##_field, " %*.2f%%", \
__hpp__slsmg_color_printf, true); \
}

#define __HPP_COLOR_ACC_PERCENT_FN(_type, _field) \
Expand All @@ -693,19 +693,20 @@ static u64 __hpp_get_acc_##_field(struct hist_entry *he) \
} \
\
static int \
hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,\
hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt, \
struct perf_hpp *hpp, \
struct hist_entry *he) \
{ \
if (!symbol_conf.cumulate_callchain) { \
int len = fmt->user_len ?: fmt->len; \
int ret = scnprintf(hpp->buf, hpp->size, \
"%*s", 8, "N/A"); \
"%*s", len, "N/A"); \
slsmg_printf("%s", hpp->buf); \
\
return ret; \
} \
return __hpp__fmt(hpp, he, __hpp_get_acc_##_field, " %*.2f%%", \
6, __hpp__slsmg_color_printf, true); \
return hpp__fmt(fmt, hpp, he, __hpp_get_acc_##_field, \
" %*.2f%%", __hpp__slsmg_color_printf, true); \
}

__HPP_COLOR_PERCENT_FN(overhead, period)
Expand Down Expand Up @@ -1549,6 +1550,9 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,

memset(options, 0, sizeof(options));

if (symbol_conf.col_width_list_str)
perf_hpp__set_user_width(symbol_conf.col_width_list_str);

while (1) {
const struct thread *thread = NULL;
const struct dso *dso = NULL;
Expand Down
10 changes: 5 additions & 5 deletions tools/perf/ui/gtk/hists.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ static u64 he_get_##_field(struct hist_entry *he) \
return he->stat._field; \
} \
\
static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt, \
struct perf_hpp *hpp, \
struct hist_entry *he) \
{ \
return __hpp__fmt(hpp, he, he_get_##_field, " %*.2f%%", 6, \
__percent_color_snprintf, true); \
return hpp__fmt(fmt, hpp, he, he_get_##_field, " %*.2f%%", \
__percent_color_snprintf, true); \
}

#define __HPP_COLOR_ACC_PERCENT_FN(_type, _field) \
Expand All @@ -59,8 +59,8 @@ static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,
struct perf_hpp *hpp, \
struct hist_entry *he) \
{ \
return __hpp__fmt_acc(hpp, he, he_get_acc_##_field, " %*.2f%%", 6, \
__percent_color_snprintf, true); \
return hpp__fmt_acc(fmt, hpp, he, he_get_acc_##_field, " %*.2f%%", \
__percent_color_snprintf, true); \
}

__HPP_COLOR_PERCENT_FN(overhead, period)
Expand Down
84 changes: 58 additions & 26 deletions tools/perf/ui/hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
__ret; \
})

int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
hpp_field_fn get_field, const char *fmt, int len,
hpp_snprint_fn print_fn, bool fmt_percent)
static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
hpp_field_fn get_field, const char *fmt, int len,
hpp_snprint_fn print_fn, bool fmt_percent)
{
int ret;
struct hists *hists = he->hists;
Expand Down Expand Up @@ -104,16 +104,35 @@ int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
return ret;
}

int __hpp__fmt_acc(struct perf_hpp *hpp, struct hist_entry *he,
hpp_field_fn get_field, const char *fmt, int len,
hpp_snprint_fn print_fn, bool fmt_percent)
int hpp__fmt(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
struct hist_entry *he, hpp_field_fn get_field,
const char *fmtstr, hpp_snprint_fn print_fn, bool fmt_percent)
{
int len = fmt->user_len ?: fmt->len;

if (symbol_conf.field_sep) {
return __hpp__fmt(hpp, he, get_field, fmtstr, 1,
print_fn, fmt_percent);
}

if (fmt_percent)
len -= 2; /* 2 for a space and a % sign */
else
len -= 1;

return __hpp__fmt(hpp, he, get_field, fmtstr, len, print_fn, fmt_percent);
}

int hpp__fmt_acc(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
struct hist_entry *he, hpp_field_fn get_field,
const char *fmtstr, hpp_snprint_fn print_fn, bool fmt_percent)
{
if (!symbol_conf.cumulate_callchain) {
return snprintf(hpp->buf, hpp->size, "%*s",
fmt_percent ? len + 2 : len + 1, "N/A");
int len = fmt->user_len ?: fmt->len;
return snprintf(hpp->buf, hpp->size, " %*s", len - 1, "N/A");
}

return __hpp__fmt(hpp, he, get_field, fmt, len, print_fn, fmt_percent);
return hpp__fmt(fmt, hpp, he, get_field, fmtstr, print_fn, fmt_percent);
}

static int field_cmp(u64 field_a, u64 field_b)
Expand Down Expand Up @@ -195,10 +214,10 @@ static int hpp__width_##_type(struct perf_hpp_fmt *fmt, \
struct perf_hpp *hpp __maybe_unused, \
struct perf_evsel *evsel) \
{ \
int len = fmt->len; \
int len = fmt->user_len ?: fmt->len; \
\
if (symbol_conf.event_group) \
len = max(len, evsel->nr_members * len); \
len = max(len, evsel->nr_members * fmt->len); \
\
if (len < (int)strlen(_str)) \
len = strlen(_str); \
Expand Down Expand Up @@ -253,18 +272,16 @@ static u64 he_get_##_field(struct hist_entry *he) \
static int hpp__color_##_type(struct perf_hpp_fmt *fmt, \
struct perf_hpp *hpp, struct hist_entry *he) \
{ \
int len = fmt->len - 2; /* 2 for a space and a % sign */ \
return __hpp__fmt(hpp, he, he_get_##_field, " %*.2f%%", len, \
hpp_color_scnprintf, true); \
return hpp__fmt(fmt, hpp, he, he_get_##_field, " %*.2f%%", \
hpp_color_scnprintf, true); \
}

#define __HPP_ENTRY_PERCENT_FN(_type, _field) \
static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \
struct perf_hpp *hpp, struct hist_entry *he) \
{ \
int len = symbol_conf.field_sep ? 1 : fmt->len - 2; \
return __hpp__fmt(hpp, he, he_get_##_field, " %*.2f%%", len, \
hpp_entry_scnprintf, true); \
return hpp__fmt(fmt, hpp, he, he_get_##_field, " %*.2f%%", \
hpp_entry_scnprintf, true); \
}

#define __HPP_SORT_FN(_type, _field) \
Expand All @@ -282,18 +299,16 @@ static u64 he_get_acc_##_field(struct hist_entry *he) \
static int hpp__color_##_type(struct perf_hpp_fmt *fmt, \
struct perf_hpp *hpp, struct hist_entry *he) \
{ \
int len = fmt->len - 2; /* 2 for a space and a % sign */ \
return __hpp__fmt_acc(hpp, he, he_get_acc_##_field, " %*.2f%%", len, \
hpp_color_scnprintf, true); \
return hpp__fmt_acc(fmt, hpp, he, he_get_acc_##_field, " %*.2f%%", \
hpp_color_scnprintf, true); \
}

#define __HPP_ENTRY_ACC_PERCENT_FN(_type, _field) \
static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \
struct perf_hpp *hpp, struct hist_entry *he) \
{ \
int len = symbol_conf.field_sep ? 1 : fmt->len - 2; \
return __hpp__fmt_acc(hpp, he, he_get_##_field, " %*.2f%%", len, \
hpp_entry_scnprintf, true); \
return hpp__fmt_acc(fmt, hpp, he, he_get_##_field, " %*.2f%%", \
hpp_entry_scnprintf, true); \
}

#define __HPP_SORT_ACC_FN(_type, _field) \
Expand All @@ -311,9 +326,8 @@ static u64 he_get_raw_##_field(struct hist_entry *he) \
static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \
struct perf_hpp *hpp, struct hist_entry *he) \
{ \
int len = symbol_conf.field_sep ? 1 : fmt->len - 1; \
return __hpp__fmt(hpp, he, he_get_raw_##_field, " %*"PRIu64, len, \
hpp_entry_scnprintf, false); \
return hpp__fmt(fmt, hpp, he, he_get_raw_##_field, " %*"PRIu64, \
hpp_entry_scnprintf, false); \
}

#define __HPP_SORT_RAW_FN(_type, _field) \
Expand Down Expand Up @@ -666,3 +680,21 @@ void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists)
break;
}
}

void perf_hpp__set_user_width(const char *width_list_str)
{
struct perf_hpp_fmt *fmt;
const char *ptr = width_list_str;

perf_hpp__for_each_format(fmt) {
char *p;

int len = strtol(ptr, &p, 10);
fmt->user_len = len;

if (*p == ',')
ptr = p + 1;
else
break;
}
}
4 changes: 3 additions & 1 deletion tools/perf/ui/stdio/hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,12 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,

init_rem_hits();


perf_hpp__for_each_format(fmt)
perf_hpp__reset_width(fmt, hists);

if (symbol_conf.col_width_list_str)
perf_hpp__set_user_width(symbol_conf.col_width_list_str);

if (!show_header)
goto print_entries;

Expand Down
14 changes: 8 additions & 6 deletions tools/perf/util/hist.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ struct perf_hpp_fmt {
struct list_head sort_list;
bool elide;
int len;
int user_len;
};

extern struct list_head perf_hpp__list;
Expand Down Expand Up @@ -263,17 +264,18 @@ static inline bool perf_hpp__should_skip(struct perf_hpp_fmt *format)

void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists);
void perf_hpp__reset_sort_width(struct perf_hpp_fmt *fmt, struct hists *hists);
void perf_hpp__set_user_width(const char *width_list_str);

typedef u64 (*hpp_field_fn)(struct hist_entry *he);
typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front);
typedef int (*hpp_snprint_fn)(struct perf_hpp *hpp, const char *fmt, ...);

int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
hpp_field_fn get_field, const char *fmt, int len,
hpp_snprint_fn print_fn, bool fmt_percent);
int __hpp__fmt_acc(struct perf_hpp *hpp, struct hist_entry *he,
hpp_field_fn get_field, const char *fmt, int len,
hpp_snprint_fn print_fn, bool fmt_percent);
int hpp__fmt(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
struct hist_entry *he, hpp_field_fn get_field,
const char *fmtstr, hpp_snprint_fn print_fn, bool fmt_percent);
int hpp__fmt_acc(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
struct hist_entry *he, hpp_field_fn get_field,
const char *fmtstr, hpp_snprint_fn print_fn, bool fmt_percent);

static inline void advance_hpp(struct perf_hpp *hpp, int inc)
{
Expand Down
Loading

0 comments on commit 5b59166

Please sign in to comment.