[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1342712558-8185-5-git-send-email-namhyung@kernel.org>
Date: Fri, 20 Jul 2012 00:42:37 +0900
From: Namhyung Kim <namhyung@...nel.org>
To: Arnaldo Carvalho de Melo <acme@...stprotocols.net>
Cc: Peter Zijlstra <a.p.zijlstra@...llo.nl>,
Ingo Molnar <mingo@...hat.com>,
David Ahern <dsahern@...il.com>, Jiri Olsa <jolsa@...hat.com>,
Frederic Weisbecker <fweisbec@...il.com>,
Stephane Eranian <eranian@...gle.com>,
LKML <linux-kernel@...r.kernel.org>
Subject: [PATCH 4/5] perf ui/browser: Use hist_period_print functions
Signed-off-by: Namhyung Kim <namhyung@...nel.org>
---
tools/perf/ui/browsers/hists.c | 100 +++++++++++++++++++++++++++++++---------
tools/perf/ui/hist.c | 22 ++++-----
2 files changed, 86 insertions(+), 36 deletions(-)
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index c58f9bb15038..b3c0da410cb5 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -553,14 +553,53 @@ static int hist_browser__show_callchain(struct hist_browser *browser,
return row - first_row;
}
+#define HPP_COLOR_FN(_name, _field) \
+static int hist_browser__hpp_color_ ## _name(struct hist_print_context *ctx, \
+ struct hist_entry *he) \
+{ \
+ double percent = 100.0 * he->_field / ctx->total_period; \
+ *(double *)ctx->ptr = percent; \
+ return scnprintf(ctx->s, ctx->size, "%5.2f%%", percent); \
+}
+
+HPP_COLOR_FN(overhead, period)
+HPP_COLOR_FN(overhead_sys, period_sys)
+HPP_COLOR_FN(overhead_us, period_us)
+HPP_COLOR_FN(overhead_guest_sys, period_guest_sys)
+HPP_COLOR_FN(overhead_guest_us, period_guest_us)
+
+#undef HPP_COLOR_FN
+
+static void hist_browser__init_hpp_functions(void)
+{
+ static bool init_done = false;
+
+ if (init_done)
+ return;
+
+ init_hpp_functions(NULL, false);
+
+ hpp_functions[PERF_HPP__OVERHEAD].color =
+ hist_browser__hpp_color_overhead;
+ hpp_functions[PERF_HPP__OVERHEAD_SYS].color =
+ hist_browser__hpp_color_overhead_sys;
+ hpp_functions[PERF_HPP__OVERHEAD_US].color =
+ hist_browser__hpp_color_overhead_us;
+ hpp_functions[PERF_HPP__OVERHEAD_GUEST_SYS].color =
+ hist_browser__hpp_color_overhead_guest_sys;
+ hpp_functions[PERF_HPP__OVERHEAD_GUEST_US].color =
+ hist_browser__hpp_color_overhead_guest_us;
+ init_done = true;
+}
+
static int hist_browser__show_entry(struct hist_browser *browser,
struct hist_entry *entry,
unsigned short row)
{
char s[256];
double percent;
- int printed = 0;
- int width = browser->b.width - 6; /* The percentage */
+ int i, printed = 0;
+ int width = browser->b.width;
char folded_sign = ' ';
bool current_entry = ui_browser__is_current_entry(&browser->b, row);
off_t row_offset = entry->row_offset;
@@ -576,35 +615,50 @@ static int hist_browser__show_entry(struct hist_browser *browser,
}
if (row_offset == 0) {
- hist_entry__sort_snprintf(entry, s, sizeof(s), browser->hists);
- percent = (entry->period * 100.0) / browser->hists->stats.total_period;
+ struct hist_print_context ctx = {
+ .s = s,
+ .size = sizeof(s),
+ .total_period = browser->hists->stats.total_period,
+ };
- ui_browser__set_percent_color(&browser->b, percent, current_entry);
ui_browser__gotorc(&browser->b, row, 0);
- if (symbol_conf.use_callchain) {
- slsmg_printf("%c ", folded_sign);
- width -= 2;
- }
- slsmg_printf(" %5.2f%%", percent);
+ for (i = 0; i < PERF_HPP__MAX_INDEX; i++) {
+ if (!hpp_functions[i].cond)
+ continue;
- /* The scroll bar isn't being used */
- if (!browser->b.navkeypressed)
- width += 1;
+ if (i) {
+ slsmg_printf(" ");
+ width -= 2;
+ }
- if (!current_entry || !browser->b.navkeypressed)
- ui_browser__set_color(&browser->b, HE_COLORSET_NORMAL);
+ if (hpp_functions[i].color) {
+ ctx.ptr = &percent;
+ /* It will set percent for us. See HPP_COLOR_FN above. */
+ width -= hpp_functions[i].color(&ctx, entry);
- if (symbol_conf.show_nr_samples) {
- slsmg_printf(" %11u", entry->nr_events);
- width -= 12;
- }
+ ui_browser__set_percent_color(&browser->b, percent, current_entry);
- if (symbol_conf.show_total_period) {
- slsmg_printf(" %12" PRIu64, entry->period);
- width -= 13;
+ if (i == 0 && symbol_conf.use_callchain) {
+ slsmg_printf("%c ", folded_sign);
+ width -= 2;
+ }
+
+ slsmg_printf("%s", s);
+
+ if (!current_entry || !browser->b.navkeypressed)
+ ui_browser__set_color(&browser->b, HE_COLORSET_NORMAL);
+ } else {
+ width -= hpp_functions[i].entry(&ctx, entry);
+ slsmg_printf("%s", s);
+ }
}
+ /* The scroll bar isn't being used */
+ if (!browser->b.navkeypressed)
+ width += 1;
+
+ hist_entry__sort_snprintf(entry, s, sizeof(s), browser->hists);
slsmg_write_nstring(s, width);
++row;
++printed;
@@ -1088,6 +1142,8 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
ui_helpline__push(helpline);
+ hist_browser__init_hpp_functions();
+
memset(options, 0, sizeof(options));
while (1) {
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index 1e7ea7e684e3..7c8aab3619eb 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -798,22 +798,16 @@ out:
unsigned int hists__sort_list_width(struct hists *hists)
{
struct sort_entry *se;
- int ret = 9; /* total % */
+ int i, ret = 0;
- if (symbol_conf.show_cpu_utilization) {
- ret += 7; /* count_sys % */
- ret += 6; /* count_us % */
- if (perf_guest) {
- ret += 13; /* count_guest_sys % */
- ret += 12; /* count_guest_us % */
- }
- }
-
- if (symbol_conf.show_nr_samples)
- ret += 11;
+ for (i = 0; i < PERF_HPP__MAX_INDEX; i++) {
+ if (!hpp_functions[i].cond)
+ continue;
+ if (i)
+ ret += 2;
- if (symbol_conf.show_total_period)
- ret += 13;
+ ret += hpp_functions[i].width(NULL);
+ }
list_for_each_entry(se, &hist_entry__sort_list, list)
if (!se->elide)
--
1.7.9.2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists