From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Stephane Eranian <eranian@google.com>,
Pekka Enberg <penberg@kernel.org>,
Namhyung Kim <namhyung.kim@lge.com>
Subject: [PATCH 6/7] perf ui/browser: Use hist_period_print functions
Date: Mon, 6 Aug 2012 17:57:41 +0900 [thread overview]
Message-ID: <1344243462-28403-7-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1344243462-28403-1-git-send-email-namhyung@kernel.org>
From: Namhyung Kim <namhyung.kim@lge.com>
Override hpp->color functions for TUI. Because line coloring is done
outside of the function, it just sets the percent value and pass it.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/ui/browsers/hists.c | 94 ++++++++++++++++++++++++++++++++----------
tools/perf/ui/tui/setup.c | 4 ++
2 files changed, 76 insertions(+), 22 deletions(-)
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index a5b5ba6d4e77..67cf297de588 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -27,6 +27,8 @@ struct hist_browser {
bool has_symbols;
};
+extern void hist_browser__init_hpp(void);
+
static int hists__browser_title(struct hists *hists, char *bf, size_t size,
const char *ev_name);
@@ -553,14 +555,47 @@ 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 hpp_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
+
+void hist_browser__init_hpp(void)
+{
+ perf_hpp__init(false, 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;
+}
+
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 +611,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 hpp_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 (i == 0 && symbol_conf.use_callchain) {
+ slsmg_printf("%c ", folded_sign);
+ width -= 2;
+ }
+
+ slsmg_printf("%s", s);
- if (symbol_conf.show_total_period) {
- slsmg_printf(" %12" PRIu64, entry->period);
- width -= 13;
+ 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;
diff --git a/tools/perf/ui/tui/setup.c b/tools/perf/ui/tui/setup.c
index e813c1d17346..2357dbfb7455 100644
--- a/tools/perf/ui/tui/setup.c
+++ b/tools/perf/ui/tui/setup.c
@@ -17,6 +17,8 @@ static volatile int ui__need_resize;
extern struct perf_error_ops perf_tui_eops;
+extern void hist_browser__init_hpp(void);
+
void ui__refresh_dimensions(bool force)
{
if (force || ui__need_resize) {
@@ -126,6 +128,8 @@ int ui__init(void)
signal(SIGTERM, ui__signal);
perf_error__register(&perf_tui_eops);
+
+ hist_browser__init_hpp();
out:
return err;
}
--
1.7.11.2
next prev parent reply other threads:[~2012-08-06 9:03 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-06 8:57 [PATCH 0/7] perf hists: Cleanup hist printing code (v2) Namhyung Kim
2012-08-06 8:57 ` [PATCH 1/7] perf hists: Separate out hist print functions Namhyung Kim
2012-08-09 19:18 ` Arnaldo Carvalho de Melo
2012-08-10 3:08 ` Namhyung Kim
2012-08-06 8:57 ` [PATCH 2/7] perf hists: Refactor some functions Namhyung Kim
2012-08-06 8:57 ` [PATCH 3/7] perf hists: Introduce hist_period_print functions Namhyung Kim
2012-08-06 8:57 ` [PATCH 4/7] perf hists: Handle field separator properly Namhyung Kim
2012-08-06 8:57 ` [PATCH 5/7] perf hists: Use hpp_functions->width to calculate the column widths Namhyung Kim
2012-08-06 8:57 ` Namhyung Kim [this message]
2012-08-06 8:57 ` [PATCH 7/7] perf gtk/browser: Use hist_period_print functions Namhyung Kim
2012-08-15 10:48 ` Pekka Enberg
-- strict thread matches above, loose matches on Subject: below --
2012-08-20 4:52 [PATCHSET 0/7] Cleanup hist printing code (v3) Namhyung Kim
2012-08-20 4:52 ` [PATCH 6/7] perf ui/browser: Use hist_period_print functions 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=1344243462-28403-7-git-send-email-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@ghostprotocols.net \
--cc=eranian@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung.kim@lge.com \
--cc=paulus@samba.org \
--cc=penberg@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.