[PATCH v2 2/2] perf hists browser: Support horizontal scrolling for callchains

From: Namhyung Kim
Date: Sun Aug 09 2015 - 04:24:11 EST


In the previous patch, horizontal scrolling was added to TUI browser.
However it lacks support for callchains. This patch adds it.

Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/ui/browsers/hists.c | 46 +++++++++++++++++++++++++++++++++++++-----
1 file changed, 41 insertions(+), 5 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 9f6e960be3a6..10af42f5283e 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -526,6 +526,7 @@ struct callchain_print_arg {
/* for file dump */
FILE *fp;
int printed;
+ int skip_cols;
};

typedef void (*print_callchain_entry_fn)(struct hist_browser *browser,
@@ -534,6 +535,30 @@ typedef void (*print_callchain_entry_fn)(struct hist_browser *browser,
unsigned short row,
struct callchain_print_arg *arg);

+static int callchain_print_skip(struct callchain_print_arg *arg,
+ const char *str, int width)
+{
+ if (arg->skip_cols) {
+ int len = strlen(str);
+
+ if (width <= arg->skip_cols) {
+ arg->skip_cols -= width;
+ return 0;
+ }
+
+ if (arg->skip_cols < len)
+ str += arg->skip_cols;
+ else
+ str = " ";
+
+ width -= arg->skip_cols;
+ arg->skip_cols = 0;
+ }
+
+ slsmg_write_nstring(str, width);
+ return width;
+}
+
static void hist_browser__show_callchain_entry(struct hist_browser *browser,
struct callchain_list *chain,
const char *str, int offset,
@@ -543,9 +568,10 @@ static void hist_browser__show_callchain_entry(struct hist_browser *browser,
int color, width;
char folded_sign = callchain_list__folded(chain);
bool show_annotated = browser->show_dso && chain->ms.sym && symbol__annotation(chain->ms.sym)->src;
+ char buf[2] = { folded_sign, 0 };

color = HE_COLORSET_NORMAL;
- width = browser->b.width - (offset + 2);
+ width = browser->b.width;
if (ui_browser__is_current_entry(&browser->b, row)) {
browser->selection = &chain->ms;
color = HE_COLORSET_SELECTED;
@@ -554,10 +580,17 @@ static void hist_browser__show_callchain_entry(struct hist_browser *browser,

ui_browser__set_color(&browser->b, color);
hist_browser__gotorc(browser, row, 0);
- slsmg_write_nstring(" ", offset);
- slsmg_printf("%c", folded_sign);
- ui_browser__write_graph(&browser->b, show_annotated ? SLSMG_RARROW_CHAR : ' ');
- slsmg_write_nstring(str, width);
+ width -= callchain_print_skip(arg, " ", offset);
+ width -= callchain_print_skip(arg, buf, 1);
+ if (arg->skip_cols > 0)
+ arg->skip_cols--;
+ else {
+ ui_browser__write_graph(&browser->b,
+ show_annotated ? SLSMG_RARROW_CHAR : ' ');
+ width--;
+ }
+ width -= callchain_print_skip(arg, str, width);
+ slsmg_write_nstring("", width);
}

static void hist_browser__fprintf_callchain_entry(struct hist_browser *b __maybe_unused,
@@ -642,6 +675,7 @@ static int hist_browser__show_callchain(struct hist_browser *browser,
str = alloc_str;
}

+ arg->skip_cols = browser->skip_cols;
print(browser, chain, str, offset + extra_offset, row, arg);

free(alloc_str);
@@ -661,6 +695,7 @@ do_next:
else
new_total = total;

+ arg->skip_cols = browser->skip_cols;
row += hist_browser__show_callchain(browser, &child->rb_root,
new_level, row, new_total,
print, arg, is_output_full);
@@ -867,6 +902,7 @@ static int hist_browser__show_entry(struct hist_browser *browser,
struct callchain_print_arg arg = {
.row_offset = row_offset,
.is_current_entry = current_entry,
+ .skip_cols = browser->skip_cols,
};

if (callchain_param.mode == CHAIN_GRAPH_REL) {
--
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/