From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
Ingo Molnar <mingo@kernel.org>, Paul Mackerras <paulus@samba.org>,
Namhyung Kim <namhyung.kim@lge.com>,
Namhyung Kim <namhyung@kernel.org>,
LKML <linux-kernel@vger.kernel.org>, Jiri Olsa <jolsa@redhat.com>
Subject: [PATCH 6/6] perf tools: Add name field into perf_hpp_fmt
Date: Wed, 9 Jul 2014 14:28:14 +0900 [thread overview]
Message-ID: <1404883694-5342-7-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1404883694-5342-1-git-send-email-namhyung@kernel.org>
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: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/ui/gtk/hists.c | 4 +-
tools/perf/ui/hist.c | 109 ++++++++++++++++++++++------------------------
tools/perf/util/hist.h | 1 +
tools/perf/util/sort.c | 6 +--
4 files changed, 57 insertions(+), 63 deletions(-)
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index 897b2e140428..f3fa4258b256 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -207,10 +207,8 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists,
if (perf_hpp__is_sort_entry(fmt))
sym_col = col_idx;
- fmt->header(fmt, &hpp, hists_to_evsel(hists));
-
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
- -1, ltrim(s),
+ -1, fmt->name,
renderer, "markup",
col_idx++, NULL);
}
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index b2d60a95f01d..93285df06164 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -209,7 +209,7 @@ static int __hpp__sort_acc(struct hist_entry *a, struct hist_entry *b,
return ret;
}
-#define __HPP_WIDTH_FN(_type, _str) \
+#define __HPP_WIDTH_FN(_type) \
static int hpp__width_##_type(struct perf_hpp_fmt *fmt, \
struct perf_hpp *hpp __maybe_unused, \
struct perf_evsel *evsel) \
@@ -219,19 +219,19 @@ static int hpp__width_##_type(struct perf_hpp_fmt *fmt, \
if (symbol_conf.event_group) \
len = max(len, evsel->nr_members * fmt->len); \
\
- if (len < (int)strlen(_str)) \
- len = strlen(_str); \
+ if (len < (int)strlen(fmt->name)) \
+ len = strlen(fmt->name); \
\
return len; \
}
-#define __HPP_HEADER_FN(_type, _str) \
+#define __HPP_HEADER_FN(_type) \
static int hpp__header_##_type(struct perf_hpp_fmt *fmt, \
struct perf_hpp *hpp, \
struct perf_evsel *evsel) \
{ \
int len = hpp__width_##_type(fmt, hpp, evsel); \
- return scnprintf(hpp->buf, hpp->size, "%*s", len, _str); \
+ return scnprintf(hpp->buf, hpp->size, "%*s", len, fmt->name); \
}
static int hpp_color_scnprintf(struct perf_hpp *hpp, const char *fmt, ...)
@@ -337,38 +337,35 @@ static int64_t hpp__sort_##_type(struct hist_entry *a, struct hist_entry *b) \
}
-#define HPP_PERCENT_FNS(_type, _str, _field) \
-__HPP_WIDTH_FN(_type, _str) \
-__HPP_HEADER_FN(_type, _str) \
+#define HPP_PERCENT_FNS(_type, _field) \
+__HPP_WIDTH_FN(_type) \
+__HPP_HEADER_FN(_type) \
__HPP_COLOR_PERCENT_FN(_type, _field) \
__HPP_ENTRY_PERCENT_FN(_type, _field) \
__HPP_SORT_FN(_type, _field)
-#define HPP_PERCENT_ACC_FNS(_type, _str, _field) \
-__HPP_WIDTH_FN(_type, _str) \
-__HPP_HEADER_FN(_type, _str) \
+#define HPP_PERCENT_ACC_FNS(_type, _field) \
+__HPP_WIDTH_FN(_type) \
+__HPP_HEADER_FN(_type) \
__HPP_COLOR_ACC_PERCENT_FN(_type, _field) \
__HPP_ENTRY_ACC_PERCENT_FN(_type, _field) \
__HPP_SORT_ACC_FN(_type, _field)
-#define HPP_RAW_FNS(_type, _str, _field) \
-__HPP_WIDTH_FN(_type, _str) \
-__HPP_HEADER_FN(_type, _str) \
+#define HPP_RAW_FNS(_type, _field) \
+__HPP_WIDTH_FN(_type) \
+__HPP_HEADER_FN(_type) \
__HPP_ENTRY_RAW_FN(_type, _field) \
__HPP_SORT_RAW_FN(_type, _field)
-__HPP_WIDTH_FN(overhead_self, "Self")
-__HPP_HEADER_FN(overhead_self, "Self")
+HPP_PERCENT_FNS(overhead, period)
+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_PERCENT_FNS(overhead_sys, "sys", period_sys)
-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)
+HPP_RAW_FNS(samples, nr_events)
+HPP_RAW_FNS(period, period)
static int64_t hpp__nop_cmp(struct hist_entry *a __maybe_unused,
struct hist_entry *b __maybe_unused)
@@ -376,47 +373,50 @@ static int64_t hpp__nop_cmp(struct hist_entry *a __maybe_unused,
return 0;
}
-#define HPP__COLOR_PRINT_FNS(_name) \
+#define HPP__COLOR_PRINT_FNS(_name, _fn) \
{ \
- .header = hpp__header_ ## _name, \
- .width = hpp__width_ ## _name, \
- .color = hpp__color_ ## _name, \
- .entry = hpp__entry_ ## _name, \
+ .name = _name, \
+ .header = hpp__header_ ## _fn, \
+ .width = hpp__width_ ## _fn, \
+ .color = hpp__color_ ## _fn, \
+ .entry = hpp__entry_ ## _fn, \
.cmp = 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, \
- .width = hpp__width_ ## _name, \
- .color = hpp__color_ ## _name, \
- .entry = hpp__entry_ ## _name, \
+ .name = _name, \
+ .header = hpp__header_ ## _fn, \
+ .width = hpp__width_ ## _fn, \
+ .color = hpp__color_ ## _fn, \
+ .entry = hpp__entry_ ## _fn, \
.cmp = 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, \
- .width = hpp__width_ ## _name, \
- .entry = hpp__entry_ ## _name, \
+ .name = _name, \
+ .header = hpp__header_ ## _fn, \
+ .width = hpp__width_ ## _fn, \
+ .entry = hpp__entry_ ## _fn, \
.cmp = hpp__nop_cmp, \
.collapse = hpp__nop_cmp, \
- .sort = hpp__sort_ ## _name, \
+ .sort = hpp__sort_ ## _fn, \
}
struct perf_hpp_fmt perf_hpp__format[] = {
- HPP__COLOR_PRINT_FNS(overhead),
- HPP__COLOR_PRINT_FNS(overhead_sys),
- HPP__COLOR_PRINT_FNS(overhead_us),
- HPP__COLOR_PRINT_FNS(overhead_guest_sys),
- HPP__COLOR_PRINT_FNS(overhead_guest_us),
- HPP__COLOR_ACC_PRINT_FNS(overhead_acc),
- HPP__PRINT_FNS(samples),
- HPP__PRINT_FNS(period)
+ HPP__COLOR_PRINT_FNS("Overhead", overhead),
+ HPP__COLOR_PRINT_FNS("sys", overhead_sys),
+ HPP__COLOR_PRINT_FNS("usr", overhead_us),
+ HPP__COLOR_PRINT_FNS("guest sys", overhead_guest_sys),
+ HPP__COLOR_PRINT_FNS("guest usr", overhead_guest_us),
+ HPP__COLOR_ACC_PRINT_FNS("Children", overhead_acc),
+ HPP__PRINT_FNS("Samples", samples),
+ HPP__PRINT_FNS("Period", period)
};
LIST_HEAD(perf_hpp__list);
@@ -466,11 +466,7 @@ void perf_hpp__init(void)
if (symbol_conf.cumulate_callchain) {
perf_hpp__column_enable(PERF_HPP__OVERHEAD_ACC);
-
- perf_hpp__format[PERF_HPP__OVERHEAD].header =
- hpp__header_overhead_self;
- perf_hpp__format[PERF_HPP__OVERHEAD].width =
- hpp__width_overhead_self;
+ perf_hpp__format[PERF_HPP__OVERHEAD].name = "Self";
}
perf_hpp__column_enable(PERF_HPP__OVERHEAD);
@@ -536,8 +532,7 @@ void perf_hpp__cancel_cumulate(void)
return;
perf_hpp__column_disable(PERF_HPP__OVERHEAD_ACC);
- perf_hpp__format[PERF_HPP__OVERHEAD].header = hpp__header_overhead;
- perf_hpp__format[PERF_HPP__OVERHEAD].width = hpp__width_overhead;
+ perf_hpp__format[PERF_HPP__OVERHEAD].name = "Overhead";
}
void perf_hpp__setup_output_field(void)
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 2e70003fcd00..95405a8fbd95 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -192,6 +192,7 @@ struct perf_hpp {
};
struct perf_hpp_fmt {
+ const char *name;
int (*header)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
struct perf_evsel *evsel);
int (*width)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index f89714329c0f..7a1944f8d001 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -1203,8 +1203,7 @@ void perf_hpp__reset_sort_width(struct perf_hpp_fmt *fmt, struct hists *hists)
return;
hse = container_of(fmt, struct hpp_sort_entry, hpp);
- hists__new_col_len(hists, hse->se->se_width_idx,
- strlen(hse->se->se_header));
+ hists__new_col_len(hists, hse->se->se_width_idx, strlen(fmt->name));
}
static int __sort__hpp_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
@@ -1218,7 +1217,7 @@ static int __sort__hpp_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
if (!len)
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,
@@ -1262,6 +1261,7 @@ __sort_dimension__alloc_hpp(struct sort_dimension *sd)
}
hse->se = sd->entry;
+ hse->hpp.name = sd->entry->se_header;
hse->hpp.header = __sort__hpp_header;
hse->hpp.width = __sort__hpp_width;
hse->hpp.entry = __sort__hpp_entry;
--
2.0.0
next prev parent reply other threads:[~2014-07-09 5:28 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-09 5:28 [PATCHSET 0/6] perf tools: Honor column width setting Namhyung Kim
2014-07-09 5:28 ` [PATCH 1/6] perf tools: Left-align output contents Namhyung Kim
2014-07-09 5:28 ` [PATCH 2/6] perf tools: Make __hpp__fmt() receive an additional len argument Namhyung Kim
2014-07-09 5:28 ` [PATCH 3/6] perf tools: Save column length in perf_hpp_fmt Namhyung Kim
2014-07-24 12:10 ` Jiri Olsa
2014-07-24 15:46 ` Namhyung Kim
2014-07-24 15:58 ` Jiri Olsa
2014-07-09 5:28 ` [PATCH 4/6] perf report: Honor column width setting Namhyung Kim
2014-07-24 12:47 ` Jiri Olsa
2014-07-24 15:51 ` Namhyung Kim
2014-07-24 12:57 ` Jiri Olsa
2014-07-24 13:57 ` Arnaldo Carvalho de Melo
2014-07-24 14:49 ` Jiri Olsa
2014-07-24 15:41 ` Namhyung Kim
2014-07-24 15:58 ` Jiri Olsa
2014-07-24 19:14 ` Arnaldo Carvalho de Melo
2014-07-09 5:28 ` [PATCH 5/6] perf top: Add -w option for setting column width Namhyung Kim
2014-07-09 5:28 ` Namhyung Kim [this message]
2014-07-21 9:07 ` [PATCHSET 0/6] perf tools: Honor column width setting Jiri Olsa
2014-07-23 7:40 ` Namhyung Kim
2014-07-24 13:11 ` Jiri Olsa
2014-07-24 13:59 ` Arnaldo Carvalho de Melo
2014-07-24 15:42 ` Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1404883694-5342-7-git-send-email-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung.kim@lge.com \
--cc=paulus@samba.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox