Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+35 -22
+9
tools/perf/ui/browser.c
··· 52 52 slsmg_write_nstring(msg, width); 53 53 } 54 54 55 + void ui_browser__printf(struct ui_browser *browser __maybe_unused, const char *fmt, ...) 56 + { 57 + va_list args; 58 + 59 + va_start(args, fmt); 60 + slsmg_vprintf(fmt, args); 61 + va_end(args); 62 + } 63 + 55 64 static struct list_head * 56 65 ui_browser__list_head_filter_entries(struct ui_browser *browser, 57 66 struct list_head *pos)
+1
tools/perf/ui/browser.h
··· 39 39 void ui_browser__gotorc(struct ui_browser *browser, int y, int x); 40 40 void ui_browser__write_nstring(struct ui_browser *browser, const char *msg, 41 41 unsigned int width); 42 + void ui_browser__printf(struct ui_browser *browser, const char *fmt, ...); 42 43 void ui_browser__write_graph(struct ui_browser *browser, int graph); 43 44 void __ui_browser__line_arrow(struct ui_browser *browser, unsigned int column, 44 45 u64 start, u64 end);
+10 -9
tools/perf/ui/browsers/annotate.c
··· 1 1 #include "../../util/util.h" 2 2 #include "../browser.h" 3 3 #include "../helpline.h" 4 - #include "../libslang.h" 5 4 #include "../ui.h" 6 5 #include "../util.h" 7 6 #include "../../util/annotate.h" ··· 133 134 ui_browser__set_percent_color(browser, 134 135 bdl->samples[i].percent, 135 136 current_entry); 136 - if (annotate_browser__opts.show_total_period) 137 - slsmg_printf("%6" PRIu64 " ", 138 - bdl->samples[i].nr); 139 - else 140 - slsmg_printf("%6.2f ", bdl->samples[i].percent); 137 + if (annotate_browser__opts.show_total_period) { 138 + ui_browser__printf(browser, "%6" PRIu64 " ", 139 + bdl->samples[i].nr); 140 + } else { 141 + ui_browser__printf(browser, "%6.2f ", 142 + bdl->samples[i].percent); 143 + } 141 144 } 142 145 } else { 143 146 ui_browser__write_nstring(browser, " ", 7 * ab->nr_events); ··· 150 149 } 151 150 if (ab->have_cycles) { 152 151 if (dl->ipc) 153 - slsmg_printf("%*.2f ", IPC_WIDTH - 1, dl->ipc); 152 + ui_browser__printf(browser, "%*.2f ", IPC_WIDTH - 1, dl->ipc); 154 153 else 155 154 ui_browser__write_nstring(browser, " ", IPC_WIDTH); 156 155 if (dl->cycles) 157 - slsmg_printf("%*" PRIu64 " ", 158 - CYCLES_WIDTH - 1, dl->cycles); 156 + ui_browser__printf(browser, "%*" PRIu64 " ", 157 + CYCLES_WIDTH - 1, dl->cycles); 159 158 else 160 159 ui_browser__write_nstring(browser, " ", CYCLES_WIDTH); 161 160 }
+8 -8
tools/perf/ui/browsers/hists.c
··· 1 1 #include <stdio.h> 2 - #include "../libslang.h" 3 2 #include <stdlib.h> 4 3 #include <string.h> 5 4 #include <linux/rbtree.h> ··· 540 541 ui_browser__set_color(&browser->b, color); 541 542 hist_browser__gotorc(browser, row, 0); 542 543 ui_browser__write_nstring(&browser->b, " ", offset); 543 - slsmg_printf("%c", folded_sign); 544 + ui_browser__printf(&browser->b, "%c", folded_sign); 544 545 ui_browser__write_graph(&browser->b, show_annotated ? SLSMG_RARROW_CHAR : ' '); 545 546 ui_browser__write_nstring(&browser->b, str, width); 546 547 } ··· 679 680 ui_browser__set_percent_color(arg->b, percent, arg->current_entry); 680 681 681 682 ret = scnprintf(hpp->buf, hpp->size, fmt, len, percent); 682 - slsmg_printf("%s", hpp->buf); 683 + ui_browser__printf(arg->b, "%s", hpp->buf); 683 684 684 685 advance_hpp(hpp, ret); 685 686 return ret; ··· 712 713 struct hist_entry *he) \ 713 714 { \ 714 715 if (!symbol_conf.cumulate_callchain) { \ 716 + struct hpp_arg *arg = hpp->ptr; \ 715 717 int len = fmt->user_len ?: fmt->len; \ 716 718 int ret = scnprintf(hpp->buf, hpp->size, \ 717 719 "%*s", len, "N/A"); \ 718 - slsmg_printf("%s", hpp->buf); \ 720 + ui_browser__printf(arg->b, "%s", hpp->buf); \ 719 721 \ 720 722 return ret; \ 721 723 } \ ··· 801 801 802 802 if (first) { 803 803 if (symbol_conf.use_callchain) { 804 - slsmg_printf("%c ", folded_sign); 804 + ui_browser__printf(&browser->b, "%c ", folded_sign); 805 805 width -= 2; 806 806 } 807 807 first = false; 808 808 } else { 809 - slsmg_printf(" "); 809 + ui_browser__printf(&browser->b, " "); 810 810 width -= 2; 811 811 } 812 812 ··· 814 814 width -= fmt->color(fmt, &hpp, entry); 815 815 } else { 816 816 width -= fmt->entry(fmt, &hpp, entry); 817 - slsmg_printf("%s", s); 817 + ui_browser__printf(&browser->b, "%s", s); 818 818 } 819 819 } 820 820 ··· 2044 2044 nr_events = convert_unit(nr_events, &unit); 2045 2045 printed = scnprintf(bf, sizeof(bf), "%lu%c%s%s", nr_events, 2046 2046 unit, unit == ' ' ? "" : " ", ev_name); 2047 - slsmg_printf("%s", bf); 2047 + ui_browser__printf(browser, "%s", bf); 2048 2048 2049 2049 nr_events = hists->stats.nr_events[PERF_RECORD_LOST]; 2050 2050 if (nr_events != 0) {
+4 -5
tools/perf/ui/browsers/map.c
··· 1 - #include "../libslang.h" 2 1 #include <elf.h> 3 2 #include <inttypes.h> 4 3 #include <sys/ttydefaults.h> ··· 25 26 int width; 26 27 27 28 ui_browser__set_percent_color(browser, 0, current_entry); 28 - slsmg_printf("%*" PRIx64 " %*" PRIx64 " %c ", 29 - mb->addrlen, sym->start, mb->addrlen, sym->end, 30 - sym->binding == STB_GLOBAL ? 'g' : 31 - sym->binding == STB_LOCAL ? 'l' : 'w'); 29 + ui_browser__printf(browser, "%*" PRIx64 " %*" PRIx64 " %c ", 30 + mb->addrlen, sym->start, mb->addrlen, sym->end, 31 + sym->binding == STB_GLOBAL ? 'g' : 32 + sym->binding == STB_LOCAL ? 'l' : 'w'); 32 33 width = browser->width - ((mb->addrlen * 2) + 4); 33 34 if (width > 0) 34 35 ui_browser__write_nstring(browser, sym->name, width);
+3
tools/perf/ui/libslang.h
··· 14 14 #if SLANG_VERSION < 20104 15 15 #define slsmg_printf(msg, args...) \ 16 16 SLsmg_printf((char *)(msg), ##args) 17 + #define slsmg_vprintf(msg, vargs) \ 18 + SLsmg_vprintf((char *)(msg), vargs) 17 19 #define slsmg_write_nstring(msg, len) \ 18 20 SLsmg_write_nstring((char *)(msg), len) 19 21 #define sltt_set_color(obj, name, fg, bg) \ 20 22 SLtt_set_color(obj,(char *)(name), (char *)(fg), (char *)(bg)) 21 23 #else 22 24 #define slsmg_printf SLsmg_printf 25 + #define slsmg_vprintf SLsmg_vprintf 23 26 #define slsmg_write_nstring SLsmg_write_nstring 24 27 #define sltt_set_color SLtt_set_color 25 28 #endif