Commit 1ecd4453 authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf tools: Add name field into perf_hpp_fmt

It makes the code a bit simpler and easier to debug IMHO.

I guess it can also remove similar code in perf diff, but let's keep
it for a future work. :)
Signed-off-by: default avatarNamhyung 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-7-git-send-email-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent cf59002f
...@@ -207,10 +207,8 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists, ...@@ -207,10 +207,8 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists,
if (perf_hpp__is_sort_entry(fmt)) if (perf_hpp__is_sort_entry(fmt))
sym_col = col_idx; sym_col = col_idx;
fmt->header(fmt, &hpp, hists_to_evsel(hists));
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
-1, ltrim(s), -1, fmt->name,
renderer, "markup", renderer, "markup",
col_idx++, NULL); col_idx++, NULL);
} }
......
...@@ -209,29 +209,26 @@ static int __hpp__sort_acc(struct hist_entry *a, struct hist_entry *b, ...@@ -209,29 +209,26 @@ static int __hpp__sort_acc(struct hist_entry *a, struct hist_entry *b,
return ret; return ret;
} }
#define __HPP_WIDTH_FN(_type, _str) \ static int hpp__width_fn(struct perf_hpp_fmt *fmt,
static int hpp__width_##_type(struct perf_hpp_fmt *fmt, \ struct perf_hpp *hpp __maybe_unused,
struct perf_hpp *hpp __maybe_unused, \ struct perf_evsel *evsel)
struct perf_evsel *evsel) \ {
{ \ int len = fmt->user_len ?: fmt->len;
int len = fmt->user_len ?: fmt->len; \
\ if (symbol_conf.event_group)
if (symbol_conf.event_group) \ len = max(len, evsel->nr_members * fmt->len);
len = max(len, evsel->nr_members * fmt->len); \
\ if (len < (int)strlen(fmt->name))
if (len < (int)strlen(_str)) \ len = strlen(fmt->name);
len = strlen(_str); \
\ return len;
return len; \ }
}
static int hpp__header_fn(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
#define __HPP_HEADER_FN(_type, _str) \ struct perf_evsel *evsel)
static int hpp__header_##_type(struct perf_hpp_fmt *fmt, \ {
struct perf_hpp *hpp, \ int len = hpp__width_fn(fmt, hpp, evsel);
struct perf_evsel *evsel) \ return scnprintf(hpp->buf, hpp->size, "%*s", len, fmt->name);
{ \
int len = hpp__width_##_type(fmt, hpp, evsel); \
return scnprintf(hpp->buf, hpp->size, "%*s", len, _str); \
} }
static int hpp_color_scnprintf(struct perf_hpp *hpp, const char *fmt, ...) static int hpp_color_scnprintf(struct perf_hpp *hpp, const char *fmt, ...)
...@@ -337,38 +334,29 @@ static int64_t hpp__sort_##_type(struct hist_entry *a, struct hist_entry *b) \ ...@@ -337,38 +334,29 @@ static int64_t hpp__sort_##_type(struct hist_entry *a, struct hist_entry *b) \
} }
#define HPP_PERCENT_FNS(_type, _str, _field) \ #define HPP_PERCENT_FNS(_type, _field) \
__HPP_WIDTH_FN(_type, _str) \
__HPP_HEADER_FN(_type, _str) \
__HPP_COLOR_PERCENT_FN(_type, _field) \ __HPP_COLOR_PERCENT_FN(_type, _field) \
__HPP_ENTRY_PERCENT_FN(_type, _field) \ __HPP_ENTRY_PERCENT_FN(_type, _field) \
__HPP_SORT_FN(_type, _field) __HPP_SORT_FN(_type, _field)
#define HPP_PERCENT_ACC_FNS(_type, _str, _field) \ #define HPP_PERCENT_ACC_FNS(_type, _field) \
__HPP_WIDTH_FN(_type, _str) \
__HPP_HEADER_FN(_type, _str) \
__HPP_COLOR_ACC_PERCENT_FN(_type, _field) \ __HPP_COLOR_ACC_PERCENT_FN(_type, _field) \
__HPP_ENTRY_ACC_PERCENT_FN(_type, _field) \ __HPP_ENTRY_ACC_PERCENT_FN(_type, _field) \
__HPP_SORT_ACC_FN(_type, _field) __HPP_SORT_ACC_FN(_type, _field)
#define HPP_RAW_FNS(_type, _str, _field) \ #define HPP_RAW_FNS(_type, _field) \
__HPP_WIDTH_FN(_type, _str) \
__HPP_HEADER_FN(_type, _str) \
__HPP_ENTRY_RAW_FN(_type, _field) \ __HPP_ENTRY_RAW_FN(_type, _field) \
__HPP_SORT_RAW_FN(_type, _field) __HPP_SORT_RAW_FN(_type, _field)
__HPP_WIDTH_FN(overhead_self, "Self") HPP_PERCENT_FNS(overhead, period)
__HPP_HEADER_FN(overhead_self, "Self") HPP_PERCENT_FNS(overhead_sys, period_sys)
HPP_PERCENT_FNS(overhead_us, period_us)
HPP_PERCENT_FNS(overhead_guest_sys, period_guest_sys)
HPP_PERCENT_FNS(overhead_guest_us, period_guest_us)
HPP_PERCENT_ACC_FNS(overhead_acc, period)
HPP_PERCENT_FNS(overhead, "Overhead", period) HPP_RAW_FNS(samples, nr_events)
HPP_PERCENT_FNS(overhead_sys, "sys", period_sys) HPP_RAW_FNS(period, period)
HPP_PERCENT_FNS(overhead_us, "usr", period_us)
HPP_PERCENT_FNS(overhead_guest_sys, "guest sys", period_guest_sys)
HPP_PERCENT_FNS(overhead_guest_us, "guest usr", period_guest_us)
HPP_PERCENT_ACC_FNS(overhead_acc, "Children", period)
HPP_RAW_FNS(samples, "Samples", nr_events)
HPP_RAW_FNS(period, "Period", period)
static int64_t hpp__nop_cmp(struct hist_entry *a __maybe_unused, static int64_t hpp__nop_cmp(struct hist_entry *a __maybe_unused,
struct hist_entry *b __maybe_unused) struct hist_entry *b __maybe_unused)
...@@ -376,47 +364,50 @@ static int64_t hpp__nop_cmp(struct hist_entry *a __maybe_unused, ...@@ -376,47 +364,50 @@ static int64_t hpp__nop_cmp(struct hist_entry *a __maybe_unused,
return 0; return 0;
} }
#define HPP__COLOR_PRINT_FNS(_name) \ #define HPP__COLOR_PRINT_FNS(_name, _fn) \
{ \ { \
.header = hpp__header_ ## _name, \ .name = _name, \
.width = hpp__width_ ## _name, \ .header = hpp__header_fn, \
.color = hpp__color_ ## _name, \ .width = hpp__width_fn, \
.entry = hpp__entry_ ## _name, \ .color = hpp__color_ ## _fn, \
.entry = hpp__entry_ ## _fn, \
.cmp = hpp__nop_cmp, \ .cmp = hpp__nop_cmp, \
.collapse = hpp__nop_cmp, \ .collapse = hpp__nop_cmp, \
.sort = hpp__sort_ ## _name, \ .sort = hpp__sort_ ## _fn, \
} }
#define HPP__COLOR_ACC_PRINT_FNS(_name) \ #define HPP__COLOR_ACC_PRINT_FNS(_name, _fn) \
{ \ { \
.header = hpp__header_ ## _name, \ .name = _name, \
.width = hpp__width_ ## _name, \ .header = hpp__header_fn, \
.color = hpp__color_ ## _name, \ .width = hpp__width_fn, \
.entry = hpp__entry_ ## _name, \ .color = hpp__color_ ## _fn, \
.entry = hpp__entry_ ## _fn, \
.cmp = hpp__nop_cmp, \ .cmp = hpp__nop_cmp, \
.collapse = hpp__nop_cmp, \ .collapse = hpp__nop_cmp, \
.sort = hpp__sort_ ## _name, \ .sort = hpp__sort_ ## _fn, \
} }
#define HPP__PRINT_FNS(_name) \ #define HPP__PRINT_FNS(_name, _fn) \
{ \ { \
.header = hpp__header_ ## _name, \ .name = _name, \
.width = hpp__width_ ## _name, \ .header = hpp__header_fn, \
.entry = hpp__entry_ ## _name, \ .width = hpp__width_fn, \
.entry = hpp__entry_ ## _fn, \
.cmp = hpp__nop_cmp, \ .cmp = hpp__nop_cmp, \
.collapse = hpp__nop_cmp, \ .collapse = hpp__nop_cmp, \
.sort = hpp__sort_ ## _name, \ .sort = hpp__sort_ ## _fn, \
} }
struct perf_hpp_fmt perf_hpp__format[] = { struct perf_hpp_fmt perf_hpp__format[] = {
HPP__COLOR_PRINT_FNS(overhead), HPP__COLOR_PRINT_FNS("Overhead", overhead),
HPP__COLOR_PRINT_FNS(overhead_sys), HPP__COLOR_PRINT_FNS("sys", overhead_sys),
HPP__COLOR_PRINT_FNS(overhead_us), HPP__COLOR_PRINT_FNS("usr", overhead_us),
HPP__COLOR_PRINT_FNS(overhead_guest_sys), HPP__COLOR_PRINT_FNS("guest sys", overhead_guest_sys),
HPP__COLOR_PRINT_FNS(overhead_guest_us), HPP__COLOR_PRINT_FNS("guest usr", overhead_guest_us),
HPP__COLOR_ACC_PRINT_FNS(overhead_acc), HPP__COLOR_ACC_PRINT_FNS("Children", overhead_acc),
HPP__PRINT_FNS(samples), HPP__PRINT_FNS("Samples", samples),
HPP__PRINT_FNS(period) HPP__PRINT_FNS("Period", period)
}; };
LIST_HEAD(perf_hpp__list); LIST_HEAD(perf_hpp__list);
...@@ -466,11 +457,7 @@ void perf_hpp__init(void) ...@@ -466,11 +457,7 @@ void perf_hpp__init(void)
if (symbol_conf.cumulate_callchain) { if (symbol_conf.cumulate_callchain) {
perf_hpp__column_enable(PERF_HPP__OVERHEAD_ACC); perf_hpp__column_enable(PERF_HPP__OVERHEAD_ACC);
perf_hpp__format[PERF_HPP__OVERHEAD].name = "Self";
perf_hpp__format[PERF_HPP__OVERHEAD].header =
hpp__header_overhead_self;
perf_hpp__format[PERF_HPP__OVERHEAD].width =
hpp__width_overhead_self;
} }
perf_hpp__column_enable(PERF_HPP__OVERHEAD); perf_hpp__column_enable(PERF_HPP__OVERHEAD);
...@@ -536,8 +523,7 @@ void perf_hpp__cancel_cumulate(void) ...@@ -536,8 +523,7 @@ void perf_hpp__cancel_cumulate(void)
return; return;
perf_hpp__column_disable(PERF_HPP__OVERHEAD_ACC); perf_hpp__column_disable(PERF_HPP__OVERHEAD_ACC);
perf_hpp__format[PERF_HPP__OVERHEAD].header = hpp__header_overhead; perf_hpp__format[PERF_HPP__OVERHEAD].name = "Overhead";
perf_hpp__format[PERF_HPP__OVERHEAD].width = hpp__width_overhead;
} }
void perf_hpp__setup_output_field(void) void perf_hpp__setup_output_field(void)
......
...@@ -192,6 +192,7 @@ struct perf_hpp { ...@@ -192,6 +192,7 @@ struct perf_hpp {
}; };
struct perf_hpp_fmt { struct perf_hpp_fmt {
const char *name;
int (*header)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, int (*header)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
struct perf_evsel *evsel); struct perf_evsel *evsel);
int (*width)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, int (*width)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
......
...@@ -1206,8 +1206,7 @@ void perf_hpp__reset_sort_width(struct perf_hpp_fmt *fmt, struct hists *hists) ...@@ -1206,8 +1206,7 @@ void perf_hpp__reset_sort_width(struct perf_hpp_fmt *fmt, struct hists *hists)
return; return;
hse = container_of(fmt, struct hpp_sort_entry, hpp); hse = container_of(fmt, struct hpp_sort_entry, hpp);
hists__new_col_len(hists, hse->se->se_width_idx, hists__new_col_len(hists, hse->se->se_width_idx, strlen(fmt->name));
strlen(hse->se->se_header));
} }
static int __sort__hpp_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, static int __sort__hpp_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
...@@ -1221,7 +1220,7 @@ static int __sort__hpp_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, ...@@ -1221,7 +1220,7 @@ static int __sort__hpp_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
if (!len) if (!len)
len = hists__col_len(&evsel->hists, hse->se->se_width_idx); len = hists__col_len(&evsel->hists, hse->se->se_width_idx);
return scnprintf(hpp->buf, hpp->size, "%-*.*s", len, len, hse->se->se_header); return scnprintf(hpp->buf, hpp->size, "%-*.*s", len, len, fmt->name);
} }
static int __sort__hpp_width(struct perf_hpp_fmt *fmt, static int __sort__hpp_width(struct perf_hpp_fmt *fmt,
...@@ -1265,6 +1264,7 @@ __sort_dimension__alloc_hpp(struct sort_dimension *sd) ...@@ -1265,6 +1264,7 @@ __sort_dimension__alloc_hpp(struct sort_dimension *sd)
} }
hse->se = sd->entry; hse->se = sd->entry;
hse->hpp.name = sd->entry->se_header;
hse->hpp.header = __sort__hpp_header; hse->hpp.header = __sort__hpp_header;
hse->hpp.width = __sort__hpp_width; hse->hpp.width = __sort__hpp_width;
hse->hpp.entry = __sort__hpp_entry; hse->hpp.entry = __sort__hpp_entry;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment