From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Jiri Olsa <jolsa@redhat.com>, LKML <linux-kernel@vger.kernel.org>,
David Ahern <dsahern@gmail.com>, Andi Kleen <andi@firstfloor.org>
Subject: [PATCH] perf hists browser: Support horizontal scrolling with '<' and '>' key
Date: Sun, 9 Aug 2015 14:28:18 +0900 [thread overview]
Message-ID: <1439098098-24504-1-git-send-email-namhyung@kernel.org> (raw)
Currently perf TUI report browser doesn't support horizontal scrolling.
So if terminal width is smaller than the actual contents, there's no way
to see them. This patch adds support horizontal movement by '<' and '>'
keys.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/ui/browsers/hists.c | 64 +++++++++++++++++++++++++++++++++---------
1 file changed, 51 insertions(+), 13 deletions(-)
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index fa67613976a8..b7dc6eef668e 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -20,6 +20,8 @@
#include "map.h"
#include "annotate.h"
+#define SKIP_COLS_STEP 10
+
struct hist_browser {
struct ui_browser b;
struct hists *hists;
@@ -29,6 +31,7 @@ struct hist_browser {
struct pstack *pstack;
struct perf_session_env *env;
int print_seq;
+ int skip_cols;
bool show_dso;
bool show_headers;
float min_pcnt;
@@ -491,6 +494,15 @@ static int hist_browser__run(struct hist_browser *browser, const char *help)
browser->show_headers = !browser->show_headers;
hist_browser__update_rows(browser);
break;
+ case '>':
+ browser->skip_cols += SKIP_COLS_STEP;
+ break;
+ case '<':
+ if (browser->skip_cols > SKIP_COLS_STEP)
+ browser->skip_cols -= SKIP_COLS_STEP;
+ else
+ browser->skip_cols = 0;
+ break;
case K_ENTER:
if (hist_browser__toggle_fold(browser))
break;
@@ -663,8 +675,27 @@ struct hpp_arg {
struct ui_browser *b;
char folded_sign;
bool current_entry;
+ int skip_cols;
};
+/* returns actual printed length (not skipped) */
+static int hpp_print_skip(struct perf_hpp *hpp, char *buf, size_t size)
+{
+ struct hpp_arg *arg = hpp->ptr;
+ int ret = size;
+
+ if (ret > arg->skip_cols) {
+ slsmg_printf("%s", buf + arg->skip_cols);
+ ret -= arg->skip_cols;
+ arg->skip_cols = 0;
+ } else {
+ arg->skip_cols -= ret;
+ ret = 0;
+ }
+
+ return ret;
+}
+
static int __hpp__slsmg_color_printf(struct perf_hpp *hpp, const char *fmt, ...)
{
struct hpp_arg *arg = hpp->ptr;
@@ -680,7 +711,7 @@ static int __hpp__slsmg_color_printf(struct perf_hpp *hpp, const char *fmt, ...)
ui_browser__set_percent_color(arg->b, percent, arg->current_entry);
ret = scnprintf(hpp->buf, hpp->size, fmt, len, percent);
- slsmg_printf("%s", hpp->buf);
+ ret = hpp_print_skip(hpp, hpp->buf, ret);
advance_hpp(hpp, ret);
return ret;
@@ -716,9 +747,8 @@ hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt, \
int len = fmt->user_len ?: fmt->len; \
int ret = scnprintf(hpp->buf, hpp->size, \
"%*s", len, "N/A"); \
- slsmg_printf("%s", hpp->buf); \
\
- return ret; \
+ return hpp_print_skip(hpp, hpp->buf, ret); \
} \
return hpp__fmt(fmt, hpp, he, __hpp_get_acc_##_field, \
" %*.2f%%", __hpp__slsmg_color_printf, true); \
@@ -778,6 +808,7 @@ static int hist_browser__show_entry(struct hist_browser *browser,
.b = &browser->b,
.folded_sign = folded_sign,
.current_entry = current_entry,
+ .skip_cols = browser->skip_cols,
};
struct perf_hpp hpp = {
.buf = s,
@@ -801,20 +832,20 @@ static int hist_browser__show_entry(struct hist_browser *browser,
if (first) {
if (symbol_conf.use_callchain) {
- slsmg_printf("%c ", folded_sign);
- width -= 2;
+ snprintf(s, sizeof(s), "%c ", folded_sign);
+ width -= hpp_print_skip(&hpp, s, 2);
}
first = false;
} else {
- slsmg_printf(" ");
- width -= 2;
+ strcpy(s, " ");
+ width -= hpp_print_skip(&hpp, s, 2);
}
if (fmt->color) {
width -= fmt->color(fmt, &hpp, entry);
} else {
- width -= fmt->entry(fmt, &hpp, entry);
- slsmg_printf("%s", s);
+ int ret = fmt->entry(fmt, &hpp, entry);
+ width -= hpp_print_skip(&hpp, s, ret);
}
}
@@ -873,7 +904,7 @@ static int hists__scnprintf_headers(char *buf, size_t size, struct hists *hists)
if (symbol_conf.use_callchain) {
ret = scnprintf(buf, size, " ");
if (advance_hpp_check(&dummy_hpp, ret))
- return ret;
+ goto out;
}
perf_hpp__for_each_format(fmt) {
@@ -889,17 +920,23 @@ static int hists__scnprintf_headers(char *buf, size_t size, struct hists *hists)
break;
}
- return ret;
+out:
+ return dummy_hpp.buf - buf;
}
static void hist_browser__show_headers(struct hist_browser *browser)
{
char headers[1024];
+ int width = browser->b.width + 1;
+ int ret;
- hists__scnprintf_headers(headers, sizeof(headers), browser->hists);
+ ret = hists__scnprintf_headers(headers, sizeof(headers), browser->hists);
ui_browser__gotorc(&browser->b, 0, 0);
ui_browser__set_color(&browser->b, HE_COLORSET_ROOT);
- slsmg_write_nstring(headers, browser->b.width + 1);
+ if (browser->skip_cols < ret)
+ slsmg_write_nstring(headers + browser->skip_cols, width);
+ else
+ slsmg_write_nstring("", width);
}
static void ui_browser__hists_init_top(struct ui_browser *browser)
@@ -1707,6 +1744,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
#define HIST_BROWSER_HELP_COMMON \
"h/?/F1 Show this window\n" \
"UP/DOWN/PGUP\n" \
+ "</> (angle brackets)\n" \
"PGDN/SPACE Navigate\n" \
"q/ESC/CTRL+C Exit browser\n\n" \
"For multiple event sessions:\n\n" \
--
2.5.0
reply other threads:[~2015-08-09 5:31 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1439098098-24504-1-git-send-email-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=andi@firstfloor.org \
--cc=dsahern@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®