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

perf ui: Move annotate browser to util/ui/browsers/

LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+151 -131
+6 -1
tools/perf/Makefile
··· 158 158 # Define NO_DWARF if you do not want debug-info analysis feature at all. 159 159 160 160 $(shell sh -c 'mkdir -p $(OUTPUT)scripts/{perl,python}/Perf-Trace-Util/' 2> /dev/null) 161 - $(shell sh -c 'mkdir -p $(OUTPUT)util/{ui,scripting-engines}/' 2> /dev/null) 161 + $(shell sh -c 'mkdir -p $(OUTPUT)util/{ui/browsers,scripting-engines}/' 2> /dev/null) 162 162 $(shell sh -c 'mkdir $(OUTPUT)bench' 2> /dev/null) 163 163 164 164 $(OUTPUT)PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE ··· 569 569 EXTLIBS += -lnewt -lslang 570 570 LIB_OBJS += $(OUTPUT)util/newt.o 571 571 LIB_OBJS += $(OUTPUT)util/ui/browser.o 572 + LIB_OBJS += $(OUTPUT)util/ui/browsers/annotate.o 572 573 LIB_OBJS += $(OUTPUT)util/ui/helpline.o 573 574 LIB_OBJS += $(OUTPUT)util/ui/progress.o 574 575 LIB_H += util/ui/browser.h 575 576 LIB_H += util/ui/helpline.h 577 + LIB_H += util/ui/libslang.h 576 578 LIB_H += util/ui/progress.h 577 579 endif 578 580 endif ··· 977 975 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $< 978 976 979 977 $(OUTPUT)util/ui/browser.o: util/ui/browser.c $(OUTPUT)PERF-CFLAGS 978 + $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $< 979 + 980 + $(OUTPUT)util/ui/browsers/annotate.o: util/ui/browsers/annotate.c $(OUTPUT)PERF-CFLAGS 980 981 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $< 981 982 982 983 $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS
+1
tools/perf/util/debug.h
··· 30 30 31 31 static inline void ui_progress__delete(struct ui_progress *self __used) {} 32 32 #else 33 + extern char browser__last_msg[]; 33 34 int browser__show_help(const char *format, va_list ap); 34 35 #include "ui/progress.h" 35 36 #endif
+2 -130
tools/perf/util/newt.c
··· 1 1 #define _GNU_SOURCE 2 2 #include <stdio.h> 3 3 #undef _GNU_SOURCE 4 - /* 5 - * slang versions <= 2.0.6 have a "#if HAVE_LONG_LONG" that breaks 6 - * the build if it isn't defined. Use the equivalent one that glibc 7 - * has on features.h. 8 - */ 9 - #include <features.h> 10 - #ifndef HAVE_LONG_LONG 11 - #define HAVE_LONG_LONG __GLIBC_HAVE_LONG_LONG 12 - #endif 13 - #include <slang.h> 4 + #include "ui/libslang.h" 14 5 #include <signal.h> 15 6 #include <stdlib.h> 16 7 #include <elf.h> ··· 16 25 #include "symbol.h" 17 26 #include "ui/browser.h" 18 27 #include "ui/helpline.h" 19 - 20 - #if SLANG_VERSION < 20104 21 - #define slsmg_printf(msg, args...) SLsmg_printf((char *)msg, ##args) 22 - #define slsmg_write_nstring(msg, len) SLsmg_write_nstring((char *)msg, len) 23 - #define sltt_set_color(obj, name, fg, bg) SLtt_set_color(obj,(char *)name,\ 24 - (char *)fg, (char *)bg) 25 - #else 26 - #define slsmg_printf SLsmg_printf 27 - #define slsmg_write_nstring SLsmg_write_nstring 28 - #define sltt_set_color SLtt_set_color 29 - #endif 30 28 31 29 newtComponent newt_form__new(void); 32 30 ··· 52 72 return 0; 53 73 } 54 74 55 - static char browser__last_msg[1024]; 75 + char browser__last_msg[1024]; 56 76 57 77 int browser__show_help(const char *format, va_list ap) 58 78 { ··· 172 192 return newtWinChoice(NULL, yes, no, (char *)msg) == 1; 173 193 } 174 194 175 - static void ui__error_window(const char *fmt, ...) 176 - { 177 - va_list ap; 178 - 179 - va_start(ap, fmt); 180 - newtWinMessagev((char *)"Error", (char *)"Ok", (char *)fmt, ap); 181 - va_end(ap); 182 - } 183 - 184 - static void annotate_browser__write(struct ui_browser *self, void *entry, int row) 185 - { 186 - struct objdump_line *ol = rb_entry(entry, struct objdump_line, node); 187 - bool current_entry = ui_browser__is_current_entry(self, row); 188 - int width = self->width; 189 - 190 - if (ol->offset != -1) { 191 - struct hist_entry *he = self->priv; 192 - struct symbol *sym = he->ms.sym; 193 - int len = he->ms.sym->end - he->ms.sym->start; 194 - unsigned int hits = 0; 195 - double percent = 0.0; 196 - int color; 197 - struct sym_priv *priv = symbol__priv(sym); 198 - struct sym_ext *sym_ext = priv->ext; 199 - struct sym_hist *h = priv->hist; 200 - s64 offset = ol->offset; 201 - struct objdump_line *next = objdump__get_next_ip_line(self->entries, ol); 202 - 203 - while (offset < (s64)len && 204 - (next == NULL || offset < next->offset)) { 205 - if (sym_ext) { 206 - percent += sym_ext[offset].percent; 207 - } else 208 - hits += h->ip[offset]; 209 - 210 - ++offset; 211 - } 212 - 213 - if (sym_ext == NULL && h->sum) 214 - percent = 100.0 * hits / h->sum; 215 - 216 - color = ui_browser__percent_color(percent, current_entry); 217 - SLsmg_set_color(color); 218 - slsmg_printf(" %7.2f ", percent); 219 - if (!current_entry) 220 - SLsmg_set_color(HE_COLORSET_CODE); 221 - } else { 222 - int color = ui_browser__percent_color(0, current_entry); 223 - SLsmg_set_color(color); 224 - slsmg_write_nstring(" ", 9); 225 - } 226 - 227 - SLsmg_write_char(':'); 228 - slsmg_write_nstring(" ", 8); 229 - if (!*ol->line) 230 - slsmg_write_nstring(" ", width - 18); 231 - else 232 - slsmg_write_nstring(ol->line, width - 18); 233 - } 234 - 235 195 static char *callchain_list__sym_name(struct callchain_list *self, 236 196 char *bf, size_t bfsize) 237 197 { ··· 180 260 181 261 snprintf(bf, bfsize, "%#Lx", self->ip); 182 262 return bf; 183 - } 184 - 185 - int hist_entry__tui_annotate(struct hist_entry *self) 186 - { 187 - struct newtExitStruct es; 188 - struct objdump_line *pos, *n; 189 - LIST_HEAD(head); 190 - struct ui_browser browser = { 191 - .entries = &head, 192 - .refresh = ui_browser__list_head_refresh, 193 - .seek = ui_browser__list_head_seek, 194 - .write = annotate_browser__write, 195 - .priv = self, 196 - }; 197 - int ret; 198 - 199 - if (self->ms.sym == NULL) 200 - return -1; 201 - 202 - if (self->ms.map->dso->annotate_warned) 203 - return -1; 204 - 205 - if (hist_entry__annotate(self, &head) < 0) { 206 - ui__error_window(browser__last_msg); 207 - return -1; 208 - } 209 - 210 - ui_helpline__push("Press <- or ESC to exit"); 211 - 212 - list_for_each_entry(pos, &head, node) { 213 - size_t line_len = strlen(pos->line); 214 - if (browser.width < line_len) 215 - browser.width = line_len; 216 - ++browser.nr_entries; 217 - } 218 - 219 - browser.width += 18; /* Percentage */ 220 - ui_browser__show(&browser, self->ms.sym->name); 221 - newtFormAddHotKey(browser.form, ' '); 222 - ret = ui_browser__run(&browser, &es); 223 - newtFormDestroy(browser.form); 224 - newtPopWindow(); 225 - list_for_each_entry_safe(pos, n, &head, node) { 226 - list_del(&pos->node); 227 - objdump_line__free(pos); 228 - } 229 - ui_helpline__pop(); 230 - return ret; 231 263 } 232 264 233 265 /* -------------------------------------------------------------------- */
+1
tools/perf/util/ui/browser.h
··· 3 3 4 4 #include <stdbool.h> 5 5 #include <newt.h> 6 + #include <sys/types.h> 6 7 #include "../types.h" 7 8 8 9 #define HE_COLORSET_TOP 50
+114
tools/perf/util/ui/browsers/annotate.c
··· 1 + #include "../browser.h" 2 + #include "../helpline.h" 3 + #include "../libslang.h" 4 + #include "../../hist.h" 5 + #include "../../sort.h" 6 + #include "../../symbol.h" 7 + 8 + static void ui__error_window(const char *fmt, ...) 9 + { 10 + va_list ap; 11 + 12 + va_start(ap, fmt); 13 + newtWinMessagev((char *)"Error", (char *)"Ok", (char *)fmt, ap); 14 + va_end(ap); 15 + } 16 + 17 + static void annotate_browser__write(struct ui_browser *self, void *entry, int row) 18 + { 19 + struct objdump_line *ol = rb_entry(entry, struct objdump_line, node); 20 + bool current_entry = ui_browser__is_current_entry(self, row); 21 + int width = self->width; 22 + 23 + if (ol->offset != -1) { 24 + struct hist_entry *he = self->priv; 25 + struct symbol *sym = he->ms.sym; 26 + int len = he->ms.sym->end - he->ms.sym->start; 27 + unsigned int hits = 0; 28 + double percent = 0.0; 29 + int color; 30 + struct sym_priv *priv = symbol__priv(sym); 31 + struct sym_ext *sym_ext = priv->ext; 32 + struct sym_hist *h = priv->hist; 33 + s64 offset = ol->offset; 34 + struct objdump_line *next = objdump__get_next_ip_line(self->entries, ol); 35 + 36 + while (offset < (s64)len && 37 + (next == NULL || offset < next->offset)) { 38 + if (sym_ext) { 39 + percent += sym_ext[offset].percent; 40 + } else 41 + hits += h->ip[offset]; 42 + 43 + ++offset; 44 + } 45 + 46 + if (sym_ext == NULL && h->sum) 47 + percent = 100.0 * hits / h->sum; 48 + 49 + color = ui_browser__percent_color(percent, current_entry); 50 + SLsmg_set_color(color); 51 + slsmg_printf(" %7.2f ", percent); 52 + if (!current_entry) 53 + SLsmg_set_color(HE_COLORSET_CODE); 54 + } else { 55 + int color = ui_browser__percent_color(0, current_entry); 56 + SLsmg_set_color(color); 57 + slsmg_write_nstring(" ", 9); 58 + } 59 + 60 + SLsmg_write_char(':'); 61 + slsmg_write_nstring(" ", 8); 62 + if (!*ol->line) 63 + slsmg_write_nstring(" ", width - 18); 64 + else 65 + slsmg_write_nstring(ol->line, width - 18); 66 + } 67 + 68 + int hist_entry__tui_annotate(struct hist_entry *self) 69 + { 70 + struct newtExitStruct es; 71 + struct objdump_line *pos, *n; 72 + LIST_HEAD(head); 73 + struct ui_browser browser = { 74 + .entries = &head, 75 + .refresh = ui_browser__list_head_refresh, 76 + .seek = ui_browser__list_head_seek, 77 + .write = annotate_browser__write, 78 + .priv = self, 79 + }; 80 + int ret; 81 + 82 + if (self->ms.sym == NULL) 83 + return -1; 84 + 85 + if (self->ms.map->dso->annotate_warned) 86 + return -1; 87 + 88 + if (hist_entry__annotate(self, &head) < 0) { 89 + ui__error_window(browser__last_msg); 90 + return -1; 91 + } 92 + 93 + ui_helpline__push("Press <- or ESC to exit"); 94 + 95 + list_for_each_entry(pos, &head, node) { 96 + size_t line_len = strlen(pos->line); 97 + if (browser.width < line_len) 98 + browser.width = line_len; 99 + ++browser.nr_entries; 100 + } 101 + 102 + browser.width += 18; /* Percentage */ 103 + ui_browser__show(&browser, self->ms.sym->name); 104 + newtFormAddHotKey(browser.form, ' '); 105 + ret = ui_browser__run(&browser, &es); 106 + newtFormDestroy(browser.form); 107 + newtPopWindow(); 108 + list_for_each_entry_safe(pos, n, &head, node) { 109 + list_del(&pos->node); 110 + objdump_line__free(pos); 111 + } 112 + ui_helpline__pop(); 113 + return ret; 114 + }
+27
tools/perf/util/ui/libslang.h
··· 1 + #ifndef _PERF_UI_SLANG_H_ 2 + #define _PERF_UI_SLANG_H_ 1 3 + /* 4 + * slang versions <= 2.0.6 have a "#if HAVE_LONG_LONG" that breaks 5 + * the build if it isn't defined. Use the equivalent one that glibc 6 + * has on features.h. 7 + */ 8 + #include <features.h> 9 + #ifndef HAVE_LONG_LONG 10 + #define HAVE_LONG_LONG __GLIBC_HAVE_LONG_LONG 11 + #endif 12 + #include <slang.h> 13 + 14 + #if SLANG_VERSION < 20104 15 + #define slsmg_printf(msg, args...) \ 16 + SLsmg_printf((char *)msg, ##args) 17 + #define slsmg_write_nstring(msg, len) \ 18 + SLsmg_write_nstring((char *)msg, len) 19 + #define sltt_set_color(obj, name, fg, bg) \ 20 + SLtt_set_color(obj,(char *)name, (char *)fg, (char *)bg) 21 + #else 22 + #define slsmg_printf SLsmg_printf 23 + #define slsmg_write_nstring SLsmg_write_nstring 24 + #define sltt_set_color SLtt_set_color 25 + #endif 26 + 27 + #endif /* _PERF_UI_SLANG_H_ */