perf ui browser: Introduce ui_browser__printf()

To remove direct access to libslang functions, with the immediate goal
of implementing horizontal scrolling at the ui_browser level, but also
because we may at some point want to implement ui_browser with other UIs
in addition to the current libslang implementation.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-w0niblabqrkecs4o0eogfy6c@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 26270a00
...@@ -52,6 +52,15 @@ void ui_browser__write_nstring(struct ui_browser *browser __maybe_unused, const ...@@ -52,6 +52,15 @@ void ui_browser__write_nstring(struct ui_browser *browser __maybe_unused, const
slsmg_write_nstring(msg, width); slsmg_write_nstring(msg, width);
} }
void ui_browser__printf(struct ui_browser *browser __maybe_unused, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
slsmg_vprintf(fmt, args);
va_end(args);
}
static struct list_head * static struct list_head *
ui_browser__list_head_filter_entries(struct ui_browser *browser, ui_browser__list_head_filter_entries(struct ui_browser *browser,
struct list_head *pos) struct list_head *pos)
......
...@@ -39,6 +39,7 @@ void ui_browser__reset_index(struct ui_browser *browser); ...@@ -39,6 +39,7 @@ void ui_browser__reset_index(struct ui_browser *browser);
void ui_browser__gotorc(struct ui_browser *browser, int y, int x); void ui_browser__gotorc(struct ui_browser *browser, int y, int x);
void ui_browser__write_nstring(struct ui_browser *browser, const char *msg, void ui_browser__write_nstring(struct ui_browser *browser, const char *msg,
unsigned int width); unsigned int width);
void ui_browser__printf(struct ui_browser *browser, const char *fmt, ...);
void ui_browser__write_graph(struct ui_browser *browser, int graph); void ui_browser__write_graph(struct ui_browser *browser, int graph);
void __ui_browser__line_arrow(struct ui_browser *browser, unsigned int column, void __ui_browser__line_arrow(struct ui_browser *browser, unsigned int column,
u64 start, u64 end); u64 start, u64 end);
......
#include "../../util/util.h" #include "../../util/util.h"
#include "../browser.h" #include "../browser.h"
#include "../helpline.h" #include "../helpline.h"
#include "../libslang.h"
#include "../ui.h" #include "../ui.h"
#include "../util.h" #include "../util.h"
#include "../../util/annotate.h" #include "../../util/annotate.h"
...@@ -134,11 +133,13 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int ...@@ -134,11 +133,13 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
ui_browser__set_percent_color(browser, ui_browser__set_percent_color(browser,
bdl->samples[i].percent, bdl->samples[i].percent,
current_entry); current_entry);
if (annotate_browser__opts.show_total_period) if (annotate_browser__opts.show_total_period) {
slsmg_printf("%6" PRIu64 " ", ui_browser__printf(browser, "%6" PRIu64 " ",
bdl->samples[i].nr); bdl->samples[i].nr);
else } else {
slsmg_printf("%6.2f ", bdl->samples[i].percent); ui_browser__printf(browser, "%6.2f ",
bdl->samples[i].percent);
}
} }
} else { } else {
ui_browser__write_nstring(browser, " ", 7 * ab->nr_events); ui_browser__write_nstring(browser, " ", 7 * ab->nr_events);
...@@ -149,11 +150,11 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int ...@@ -149,11 +150,11 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
} }
if (ab->have_cycles) { if (ab->have_cycles) {
if (dl->ipc) if (dl->ipc)
slsmg_printf("%*.2f ", IPC_WIDTH - 1, dl->ipc); ui_browser__printf(browser, "%*.2f ", IPC_WIDTH - 1, dl->ipc);
else else
ui_browser__write_nstring(browser, " ", IPC_WIDTH); ui_browser__write_nstring(browser, " ", IPC_WIDTH);
if (dl->cycles) if (dl->cycles)
slsmg_printf("%*" PRIu64 " ", ui_browser__printf(browser, "%*" PRIu64 " ",
CYCLES_WIDTH - 1, dl->cycles); CYCLES_WIDTH - 1, dl->cycles);
else else
ui_browser__write_nstring(browser, " ", CYCLES_WIDTH); ui_browser__write_nstring(browser, " ", CYCLES_WIDTH);
......
#include <stdio.h> #include <stdio.h>
#include "../libslang.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <linux/rbtree.h> #include <linux/rbtree.h>
...@@ -541,7 +540,7 @@ static void hist_browser__show_callchain_entry(struct hist_browser *browser, ...@@ -541,7 +540,7 @@ static void hist_browser__show_callchain_entry(struct hist_browser *browser,
ui_browser__set_color(&browser->b, color); ui_browser__set_color(&browser->b, color);
hist_browser__gotorc(browser, row, 0); hist_browser__gotorc(browser, row, 0);
ui_browser__write_nstring(&browser->b, " ", offset); ui_browser__write_nstring(&browser->b, " ", offset);
slsmg_printf("%c", folded_sign); ui_browser__printf(&browser->b, "%c", folded_sign);
ui_browser__write_graph(&browser->b, show_annotated ? SLSMG_RARROW_CHAR : ' '); ui_browser__write_graph(&browser->b, show_annotated ? SLSMG_RARROW_CHAR : ' ');
ui_browser__write_nstring(&browser->b, str, width); ui_browser__write_nstring(&browser->b, str, width);
} }
...@@ -680,7 +679,7 @@ static int __hpp__slsmg_color_printf(struct perf_hpp *hpp, const char *fmt, ...) ...@@ -680,7 +679,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); ui_browser__set_percent_color(arg->b, percent, arg->current_entry);
ret = scnprintf(hpp->buf, hpp->size, fmt, len, percent); ret = scnprintf(hpp->buf, hpp->size, fmt, len, percent);
slsmg_printf("%s", hpp->buf); ui_browser__printf(arg->b, "%s", hpp->buf);
advance_hpp(hpp, ret); advance_hpp(hpp, ret);
return ret; return ret;
...@@ -713,10 +712,11 @@ hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt, \ ...@@ -713,10 +712,11 @@ hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt, \
struct hist_entry *he) \ struct hist_entry *he) \
{ \ { \
if (!symbol_conf.cumulate_callchain) { \ if (!symbol_conf.cumulate_callchain) { \
struct hpp_arg *arg = hpp->ptr; \
int len = fmt->user_len ?: fmt->len; \ int len = fmt->user_len ?: fmt->len; \
int ret = scnprintf(hpp->buf, hpp->size, \ int ret = scnprintf(hpp->buf, hpp->size, \
"%*s", len, "N/A"); \ "%*s", len, "N/A"); \
slsmg_printf("%s", hpp->buf); \ ui_browser__printf(arg->b, "%s", hpp->buf); \
\ \
return ret; \ return ret; \
} \ } \
...@@ -801,12 +801,12 @@ static int hist_browser__show_entry(struct hist_browser *browser, ...@@ -801,12 +801,12 @@ static int hist_browser__show_entry(struct hist_browser *browser,
if (first) { if (first) {
if (symbol_conf.use_callchain) { if (symbol_conf.use_callchain) {
slsmg_printf("%c ", folded_sign); ui_browser__printf(&browser->b, "%c ", folded_sign);
width -= 2; width -= 2;
} }
first = false; first = false;
} else { } else {
slsmg_printf(" "); ui_browser__printf(&browser->b, " ");
width -= 2; width -= 2;
} }
...@@ -814,7 +814,7 @@ static int hist_browser__show_entry(struct hist_browser *browser, ...@@ -814,7 +814,7 @@ static int hist_browser__show_entry(struct hist_browser *browser,
width -= fmt->color(fmt, &hpp, entry); width -= fmt->color(fmt, &hpp, entry);
} else { } else {
width -= fmt->entry(fmt, &hpp, entry); width -= fmt->entry(fmt, &hpp, entry);
slsmg_printf("%s", s); ui_browser__printf(&browser->b, "%s", s);
} }
} }
...@@ -2044,7 +2044,7 @@ static void perf_evsel_menu__write(struct ui_browser *browser, ...@@ -2044,7 +2044,7 @@ static void perf_evsel_menu__write(struct ui_browser *browser,
nr_events = convert_unit(nr_events, &unit); nr_events = convert_unit(nr_events, &unit);
printed = scnprintf(bf, sizeof(bf), "%lu%c%s%s", nr_events, printed = scnprintf(bf, sizeof(bf), "%lu%c%s%s", nr_events,
unit, unit == ' ' ? "" : " ", ev_name); unit, unit == ' ' ? "" : " ", ev_name);
slsmg_printf("%s", bf); ui_browser__printf(browser, "%s", bf);
nr_events = hists->stats.nr_events[PERF_RECORD_LOST]; nr_events = hists->stats.nr_events[PERF_RECORD_LOST];
if (nr_events != 0) { if (nr_events != 0) {
......
#include "../libslang.h"
#include <elf.h> #include <elf.h>
#include <inttypes.h> #include <inttypes.h>
#include <sys/ttydefaults.h> #include <sys/ttydefaults.h>
...@@ -26,7 +25,7 @@ static void map_browser__write(struct ui_browser *browser, void *nd, int row) ...@@ -26,7 +25,7 @@ static void map_browser__write(struct ui_browser *browser, void *nd, int row)
int width; int width;
ui_browser__set_percent_color(browser, 0, current_entry); ui_browser__set_percent_color(browser, 0, current_entry);
slsmg_printf("%*" PRIx64 " %*" PRIx64 " %c ", ui_browser__printf(browser, "%*" PRIx64 " %*" PRIx64 " %c ",
mb->addrlen, sym->start, mb->addrlen, sym->end, mb->addrlen, sym->start, mb->addrlen, sym->end,
sym->binding == STB_GLOBAL ? 'g' : sym->binding == STB_GLOBAL ? 'g' :
sym->binding == STB_LOCAL ? 'l' : 'w'); sym->binding == STB_LOCAL ? 'l' : 'w');
......
...@@ -14,12 +14,15 @@ ...@@ -14,12 +14,15 @@
#if SLANG_VERSION < 20104 #if SLANG_VERSION < 20104
#define slsmg_printf(msg, args...) \ #define slsmg_printf(msg, args...) \
SLsmg_printf((char *)(msg), ##args) SLsmg_printf((char *)(msg), ##args)
#define slsmg_vprintf(msg, vargs) \
SLsmg_vprintf((char *)(msg), vargs)
#define slsmg_write_nstring(msg, len) \ #define slsmg_write_nstring(msg, len) \
SLsmg_write_nstring((char *)(msg), len) SLsmg_write_nstring((char *)(msg), len)
#define sltt_set_color(obj, name, fg, bg) \ #define sltt_set_color(obj, name, fg, bg) \
SLtt_set_color(obj,(char *)(name), (char *)(fg), (char *)(bg)) SLtt_set_color(obj,(char *)(name), (char *)(fg), (char *)(bg))
#else #else
#define slsmg_printf SLsmg_printf #define slsmg_printf SLsmg_printf
#define slsmg_vprintf SLsmg_vprintf
#define slsmg_write_nstring SLsmg_write_nstring #define slsmg_write_nstring SLsmg_write_nstring
#define sltt_set_color SLtt_set_color #define sltt_set_color SLtt_set_color
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment