提交 59cd358a 编写于 作者: I Ingo Molnar

Merge tag 'perf-core-for-mingo' of...

Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent

Annotation fixes/improvements from Arnaldo Carvalho de Melo:

. Make the annotatation toggles (hide_src_code, jump_arrows, use_offset, etc)
  global so that navigation doesn't resets them on new annotations.

. Introduce an '[annotate]' config file section to allow permanent changes
  to the annotate browser defaults.
Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: NIngo Molnar <mingo@kernel.org>
...@@ -19,3 +19,11 @@ ...@@ -19,3 +19,11 @@
# Default, disable using /dev/null # Default, disable using /dev/null
dir = /root/.debug dir = /root/.debug
[annotate]
# Defaults
hide_src_code = false
use_offset = true
jump_arrows = true
show_nr_jumps = false
...@@ -35,16 +35,16 @@ int ui_browser__set_color(struct ui_browser *browser, int color) ...@@ -35,16 +35,16 @@ int ui_browser__set_color(struct ui_browser *browser, int color)
return ret; return ret;
} }
void ui_browser__set_percent_color(struct ui_browser *self, void ui_browser__set_percent_color(struct ui_browser *browser,
double percent, bool current) double percent, bool current)
{ {
int color = ui_browser__percent_color(self, percent, current); int color = ui_browser__percent_color(browser, percent, current);
ui_browser__set_color(self, color); ui_browser__set_color(browser, color);
} }
void ui_browser__gotorc(struct ui_browser *self, int y, int x) void ui_browser__gotorc(struct ui_browser *browser, int y, int x)
{ {
SLsmg_gotorc(self->y + y, self->x + x); SLsmg_gotorc(browser->y + y, browser->x + x);
} }
static struct list_head * static struct list_head *
...@@ -73,23 +73,23 @@ ui_browser__list_head_filter_prev_entries(struct ui_browser *browser, ...@@ -73,23 +73,23 @@ ui_browser__list_head_filter_prev_entries(struct ui_browser *browser,
return NULL; return NULL;
} }
void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whence) void ui_browser__list_head_seek(struct ui_browser *browser, off_t offset, int whence)
{ {
struct list_head *head = self->entries; struct list_head *head = browser->entries;
struct list_head *pos; struct list_head *pos;
if (self->nr_entries == 0) if (browser->nr_entries == 0)
return; return;
switch (whence) { switch (whence) {
case SEEK_SET: case SEEK_SET:
pos = ui_browser__list_head_filter_entries(self, head->next); pos = ui_browser__list_head_filter_entries(browser, head->next);
break; break;
case SEEK_CUR: case SEEK_CUR:
pos = self->top; pos = browser->top;
break; break;
case SEEK_END: case SEEK_END:
pos = ui_browser__list_head_filter_prev_entries(self, head->prev); pos = ui_browser__list_head_filter_prev_entries(browser, head->prev);
break; break;
default: default:
return; return;
...@@ -99,18 +99,18 @@ void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whenc ...@@ -99,18 +99,18 @@ void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whenc
if (offset > 0) { if (offset > 0) {
while (offset-- != 0) while (offset-- != 0)
pos = ui_browser__list_head_filter_entries(self, pos->next); pos = ui_browser__list_head_filter_entries(browser, pos->next);
} else { } else {
while (offset++ != 0) while (offset++ != 0)
pos = ui_browser__list_head_filter_prev_entries(self, pos->prev); pos = ui_browser__list_head_filter_prev_entries(browser, pos->prev);
} }
self->top = pos; browser->top = pos;
} }
void ui_browser__rb_tree_seek(struct ui_browser *self, off_t offset, int whence) void ui_browser__rb_tree_seek(struct ui_browser *browser, off_t offset, int whence)
{ {
struct rb_root *root = self->entries; struct rb_root *root = browser->entries;
struct rb_node *nd; struct rb_node *nd;
switch (whence) { switch (whence) {
...@@ -118,7 +118,7 @@ void ui_browser__rb_tree_seek(struct ui_browser *self, off_t offset, int whence) ...@@ -118,7 +118,7 @@ void ui_browser__rb_tree_seek(struct ui_browser *self, off_t offset, int whence)
nd = rb_first(root); nd = rb_first(root);
break; break;
case SEEK_CUR: case SEEK_CUR:
nd = self->top; nd = browser->top;
break; break;
case SEEK_END: case SEEK_END:
nd = rb_last(root); nd = rb_last(root);
...@@ -135,23 +135,23 @@ void ui_browser__rb_tree_seek(struct ui_browser *self, off_t offset, int whence) ...@@ -135,23 +135,23 @@ void ui_browser__rb_tree_seek(struct ui_browser *self, off_t offset, int whence)
nd = rb_prev(nd); nd = rb_prev(nd);
} }
self->top = nd; browser->top = nd;
} }
unsigned int ui_browser__rb_tree_refresh(struct ui_browser *self) unsigned int ui_browser__rb_tree_refresh(struct ui_browser *browser)
{ {
struct rb_node *nd; struct rb_node *nd;
int row = 0; int row = 0;
if (self->top == NULL) if (browser->top == NULL)
self->top = rb_first(self->entries); browser->top = rb_first(browser->entries);
nd = self->top; nd = browser->top;
while (nd != NULL) { while (nd != NULL) {
ui_browser__gotorc(self, row, 0); ui_browser__gotorc(browser, row, 0);
self->write(self, nd, row); browser->write(browser, nd, row);
if (++row == self->height) if (++row == browser->height)
break; break;
nd = rb_next(nd); nd = rb_next(nd);
} }
...@@ -159,17 +159,17 @@ unsigned int ui_browser__rb_tree_refresh(struct ui_browser *self) ...@@ -159,17 +159,17 @@ unsigned int ui_browser__rb_tree_refresh(struct ui_browser *self)
return row; return row;
} }
bool ui_browser__is_current_entry(struct ui_browser *self, unsigned row) bool ui_browser__is_current_entry(struct ui_browser *browser, unsigned row)
{ {
return self->top_idx + row == self->index; return browser->top_idx + row == browser->index;
} }
void ui_browser__refresh_dimensions(struct ui_browser *self) void ui_browser__refresh_dimensions(struct ui_browser *browser)
{ {
self->width = SLtt_Screen_Cols - 1; browser->width = SLtt_Screen_Cols - 1;
self->height = SLtt_Screen_Rows - 2; browser->height = SLtt_Screen_Rows - 2;
self->y = 1; browser->y = 1;
self->x = 0; browser->x = 0;
} }
void ui_browser__handle_resize(struct ui_browser *browser) void ui_browser__handle_resize(struct ui_browser *browser)
...@@ -225,10 +225,10 @@ bool ui_browser__dialog_yesno(struct ui_browser *browser, const char *text) ...@@ -225,10 +225,10 @@ bool ui_browser__dialog_yesno(struct ui_browser *browser, const char *text)
return key == K_ENTER || toupper(key) == 'Y'; return key == K_ENTER || toupper(key) == 'Y';
} }
void ui_browser__reset_index(struct ui_browser *self) void ui_browser__reset_index(struct ui_browser *browser)
{ {
self->index = self->top_idx = 0; browser->index = browser->top_idx = 0;
self->seek(self, 0, SEEK_SET); browser->seek(browser, 0, SEEK_SET);
} }
void __ui_browser__show_title(struct ui_browser *browser, const char *title) void __ui_browser__show_title(struct ui_browser *browser, const char *title)
...@@ -245,26 +245,26 @@ void ui_browser__show_title(struct ui_browser *browser, const char *title) ...@@ -245,26 +245,26 @@ void ui_browser__show_title(struct ui_browser *browser, const char *title)
pthread_mutex_unlock(&ui__lock); pthread_mutex_unlock(&ui__lock);
} }
int ui_browser__show(struct ui_browser *self, const char *title, int ui_browser__show(struct ui_browser *browser, const char *title,
const char *helpline, ...) const char *helpline, ...)
{ {
int err; int err;
va_list ap; va_list ap;
ui_browser__refresh_dimensions(self); ui_browser__refresh_dimensions(browser);
pthread_mutex_lock(&ui__lock); pthread_mutex_lock(&ui__lock);
__ui_browser__show_title(self, title); __ui_browser__show_title(browser, title);
self->title = title; browser->title = title;
free(self->helpline); free(browser->helpline);
self->helpline = NULL; browser->helpline = NULL;
va_start(ap, helpline); va_start(ap, helpline);
err = vasprintf(&self->helpline, helpline, ap); err = vasprintf(&browser->helpline, helpline, ap);
va_end(ap); va_end(ap);
if (err > 0) if (err > 0)
ui_helpline__push(self->helpline); ui_helpline__push(browser->helpline);
pthread_mutex_unlock(&ui__lock); pthread_mutex_unlock(&ui__lock);
return err ? 0 : -1; return err ? 0 : -1;
} }
...@@ -350,7 +350,7 @@ void ui_browser__update_nr_entries(struct ui_browser *browser, u32 nr_entries) ...@@ -350,7 +350,7 @@ void ui_browser__update_nr_entries(struct ui_browser *browser, u32 nr_entries)
browser->seek(browser, browser->top_idx, SEEK_SET); browser->seek(browser, browser->top_idx, SEEK_SET);
} }
int ui_browser__run(struct ui_browser *self, int delay_secs) int ui_browser__run(struct ui_browser *browser, int delay_secs)
{ {
int err, key; int err, key;
...@@ -358,7 +358,7 @@ int ui_browser__run(struct ui_browser *self, int delay_secs) ...@@ -358,7 +358,7 @@ int ui_browser__run(struct ui_browser *self, int delay_secs)
off_t offset; off_t offset;
pthread_mutex_lock(&ui__lock); pthread_mutex_lock(&ui__lock);
err = __ui_browser__refresh(self); err = __ui_browser__refresh(browser);
SLsmg_refresh(); SLsmg_refresh();
pthread_mutex_unlock(&ui__lock); pthread_mutex_unlock(&ui__lock);
if (err < 0) if (err < 0)
...@@ -368,18 +368,18 @@ int ui_browser__run(struct ui_browser *self, int delay_secs) ...@@ -368,18 +368,18 @@ int ui_browser__run(struct ui_browser *self, int delay_secs)
if (key == K_RESIZE) { if (key == K_RESIZE) {
ui__refresh_dimensions(false); ui__refresh_dimensions(false);
ui_browser__refresh_dimensions(self); ui_browser__refresh_dimensions(browser);
__ui_browser__show_title(self, self->title); __ui_browser__show_title(browser, browser->title);
ui_helpline__puts(self->helpline); ui_helpline__puts(browser->helpline);
continue; continue;
} }
if (self->use_navkeypressed && !self->navkeypressed) { if (browser->use_navkeypressed && !browser->navkeypressed) {
if (key == K_DOWN || key == K_UP || if (key == K_DOWN || key == K_UP ||
key == K_PGDN || key == K_PGUP || key == K_PGDN || key == K_PGUP ||
key == K_HOME || key == K_END || key == K_HOME || key == K_END ||
key == ' ') { key == ' ') {
self->navkeypressed = true; browser->navkeypressed = true;
continue; continue;
} else } else
return key; return key;
...@@ -387,59 +387,59 @@ int ui_browser__run(struct ui_browser *self, int delay_secs) ...@@ -387,59 +387,59 @@ int ui_browser__run(struct ui_browser *self, int delay_secs)
switch (key) { switch (key) {
case K_DOWN: case K_DOWN:
if (self->index == self->nr_entries - 1) if (browser->index == browser->nr_entries - 1)
break; break;
++self->index; ++browser->index;
if (self->index == self->top_idx + self->height) { if (browser->index == browser->top_idx + browser->height) {
++self->top_idx; ++browser->top_idx;
self->seek(self, +1, SEEK_CUR); browser->seek(browser, +1, SEEK_CUR);
} }
break; break;
case K_UP: case K_UP:
if (self->index == 0) if (browser->index == 0)
break; break;
--self->index; --browser->index;
if (self->index < self->top_idx) { if (browser->index < browser->top_idx) {
--self->top_idx; --browser->top_idx;
self->seek(self, -1, SEEK_CUR); browser->seek(browser, -1, SEEK_CUR);
} }
break; break;
case K_PGDN: case K_PGDN:
case ' ': case ' ':
if (self->top_idx + self->height > self->nr_entries - 1) if (browser->top_idx + browser->height > browser->nr_entries - 1)
break; break;
offset = self->height; offset = browser->height;
if (self->index + offset > self->nr_entries - 1) if (browser->index + offset > browser->nr_entries - 1)
offset = self->nr_entries - 1 - self->index; offset = browser->nr_entries - 1 - browser->index;
self->index += offset; browser->index += offset;
self->top_idx += offset; browser->top_idx += offset;
self->seek(self, +offset, SEEK_CUR); browser->seek(browser, +offset, SEEK_CUR);
break; break;
case K_PGUP: case K_PGUP:
if (self->top_idx == 0) if (browser->top_idx == 0)
break; break;
if (self->top_idx < self->height) if (browser->top_idx < browser->height)
offset = self->top_idx; offset = browser->top_idx;
else else
offset = self->height; offset = browser->height;
self->index -= offset; browser->index -= offset;
self->top_idx -= offset; browser->top_idx -= offset;
self->seek(self, -offset, SEEK_CUR); browser->seek(browser, -offset, SEEK_CUR);
break; break;
case K_HOME: case K_HOME:
ui_browser__reset_index(self); ui_browser__reset_index(browser);
break; break;
case K_END: case K_END:
offset = self->height - 1; offset = browser->height - 1;
if (offset >= self->nr_entries) if (offset >= browser->nr_entries)
offset = self->nr_entries - 1; offset = browser->nr_entries - 1;
self->index = self->nr_entries - 1; browser->index = browser->nr_entries - 1;
self->top_idx = self->index - offset; browser->top_idx = browser->index - offset;
self->seek(self, -offset, SEEK_END); browser->seek(browser, -offset, SEEK_END);
break; break;
default: default:
return key; return key;
...@@ -448,22 +448,22 @@ int ui_browser__run(struct ui_browser *self, int delay_secs) ...@@ -448,22 +448,22 @@ int ui_browser__run(struct ui_browser *self, int delay_secs)
return -1; return -1;
} }
unsigned int ui_browser__list_head_refresh(struct ui_browser *self) unsigned int ui_browser__list_head_refresh(struct ui_browser *browser)
{ {
struct list_head *pos; struct list_head *pos;
struct list_head *head = self->entries; struct list_head *head = browser->entries;
int row = 0; int row = 0;
if (self->top == NULL || self->top == self->entries) if (browser->top == NULL || browser->top == browser->entries)
self->top = ui_browser__list_head_filter_entries(self, head->next); browser->top = ui_browser__list_head_filter_entries(browser, head->next);
pos = self->top; pos = browser->top;
list_for_each_from(pos, head) { list_for_each_from(pos, head) {
if (!self->filter || !self->filter(self, pos)) { if (!browser->filter || !browser->filter(browser, pos)) {
ui_browser__gotorc(self, row, 0); ui_browser__gotorc(browser, row, 0);
self->write(self, pos, row); browser->write(browser, pos, row);
if (++row == self->height) if (++row == browser->height)
break; break;
} }
} }
...@@ -708,4 +708,6 @@ void ui_browser__init(void) ...@@ -708,4 +708,6 @@ void ui_browser__init(void)
struct ui_browser__colorset *c = &ui_browser__colorsets[i++]; struct ui_browser__colorset *c = &ui_browser__colorsets[i++];
sltt_set_color(c->colorset, c->name, c->fg, c->bg); sltt_set_color(c->colorset, c->name, c->fg, c->bg);
} }
annotate_browser__init();
} }
...@@ -69,4 +69,5 @@ void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whenc ...@@ -69,4 +69,5 @@ void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whenc
unsigned int ui_browser__list_head_refresh(struct ui_browser *self); unsigned int ui_browser__list_head_refresh(struct ui_browser *self);
void ui_browser__init(void); void ui_browser__init(void);
void annotate_browser__init(void);
#endif /* _PERF_UI_BROWSER_H_ */ #endif /* _PERF_UI_BROWSER_H_ */
...@@ -19,6 +19,16 @@ struct browser_disasm_line { ...@@ -19,6 +19,16 @@ struct browser_disasm_line {
int jump_sources; int jump_sources;
}; };
static struct annotate_browser_opt {
bool hide_src_code,
use_offset,
jump_arrows,
show_nr_jumps;
} annotate_browser__opts = {
.use_offset = true,
.jump_arrows = true,
};
struct annotate_browser { struct annotate_browser {
struct ui_browser b; struct ui_browser b;
struct rb_root entries; struct rb_root entries;
...@@ -30,10 +40,6 @@ struct annotate_browser { ...@@ -30,10 +40,6 @@ struct annotate_browser {
int nr_entries; int nr_entries;
int max_jump_sources; int max_jump_sources;
int nr_jumps; int nr_jumps;
bool hide_src_code;
bool use_offset;
bool jump_arrows;
bool show_nr_jumps;
bool searching_backwards; bool searching_backwards;
u8 addr_width; u8 addr_width;
u8 jumps_width; u8 jumps_width;
...@@ -48,11 +54,9 @@ static inline struct browser_disasm_line *disasm_line__browser(struct disasm_lin ...@@ -48,11 +54,9 @@ static inline struct browser_disasm_line *disasm_line__browser(struct disasm_lin
return (struct browser_disasm_line *)(dl + 1); return (struct browser_disasm_line *)(dl + 1);
} }
static bool disasm_line__filter(struct ui_browser *browser, void *entry) static bool disasm_line__filter(struct ui_browser *browser __used, void *entry)
{ {
struct annotate_browser *ab = container_of(browser, struct annotate_browser, b); if (annotate_browser__opts.hide_src_code) {
if (ab->hide_src_code) {
struct disasm_line *dl = list_entry(entry, struct disasm_line, node); struct disasm_line *dl = list_entry(entry, struct disasm_line, node);
return dl->offset == -1; return dl->offset == -1;
} }
...@@ -79,30 +83,30 @@ static int annotate_browser__set_jumps_percent_color(struct annotate_browser *br ...@@ -79,30 +83,30 @@ static int annotate_browser__set_jumps_percent_color(struct annotate_browser *br
return ui_browser__set_color(&browser->b, color); return ui_browser__set_color(&browser->b, color);
} }
static void annotate_browser__write(struct ui_browser *self, void *entry, int row) static void annotate_browser__write(struct ui_browser *browser, void *entry, int row)
{ {
struct annotate_browser *ab = container_of(self, struct annotate_browser, b); struct annotate_browser *ab = container_of(browser, struct annotate_browser, b);
struct disasm_line *dl = list_entry(entry, struct disasm_line, node); struct disasm_line *dl = list_entry(entry, struct disasm_line, node);
struct browser_disasm_line *bdl = disasm_line__browser(dl); struct browser_disasm_line *bdl = disasm_line__browser(dl);
bool current_entry = ui_browser__is_current_entry(self, row); bool current_entry = ui_browser__is_current_entry(browser, row);
bool change_color = (!ab->hide_src_code && bool change_color = (!annotate_browser__opts.hide_src_code &&
(!current_entry || (self->use_navkeypressed && (!current_entry || (browser->use_navkeypressed &&
!self->navkeypressed))); !browser->navkeypressed)));
int width = self->width, printed; int width = browser->width, printed;
char bf[256]; char bf[256];
if (dl->offset != -1 && bdl->percent != 0.0) { if (dl->offset != -1 && bdl->percent != 0.0) {
ui_browser__set_percent_color(self, bdl->percent, current_entry); ui_browser__set_percent_color(browser, bdl->percent, current_entry);
slsmg_printf("%6.2f ", bdl->percent); slsmg_printf("%6.2f ", bdl->percent);
} else { } else {
ui_browser__set_percent_color(self, 0, current_entry); ui_browser__set_percent_color(browser, 0, current_entry);
slsmg_write_nstring(" ", 7); slsmg_write_nstring(" ", 7);
} }
SLsmg_write_char(' '); SLsmg_write_char(' ');
/* The scroll bar isn't being used */ /* The scroll bar isn't being used */
if (!self->navkeypressed) if (!browser->navkeypressed)
width += 1; width += 1;
if (!*dl->line) if (!*dl->line)
...@@ -116,14 +120,14 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro ...@@ -116,14 +120,14 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro
u64 addr = dl->offset; u64 addr = dl->offset;
int color = -1; int color = -1;
if (!ab->use_offset) if (!annotate_browser__opts.use_offset)
addr += ab->start; addr += ab->start;
if (!ab->use_offset) { if (!annotate_browser__opts.use_offset) {
printed = scnprintf(bf, sizeof(bf), "%" PRIx64 ": ", addr); printed = scnprintf(bf, sizeof(bf), "%" PRIx64 ": ", addr);
} else { } else {
if (bdl->jump_sources) { if (bdl->jump_sources) {
if (ab->show_nr_jumps) { if (annotate_browser__opts.show_nr_jumps) {
int prev; int prev;
printed = scnprintf(bf, sizeof(bf), "%*d ", printed = scnprintf(bf, sizeof(bf), "%*d ",
ab->jumps_width, ab->jumps_width,
...@@ -131,7 +135,7 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro ...@@ -131,7 +135,7 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro
prev = annotate_browser__set_jumps_percent_color(ab, bdl->jump_sources, prev = annotate_browser__set_jumps_percent_color(ab, bdl->jump_sources,
current_entry); current_entry);
slsmg_write_nstring(bf, printed); slsmg_write_nstring(bf, printed);
ui_browser__set_color(self, prev); ui_browser__set_color(browser, prev);
} }
printed = scnprintf(bf, sizeof(bf), "%*" PRIx64 ": ", printed = scnprintf(bf, sizeof(bf), "%*" PRIx64 ": ",
...@@ -143,19 +147,19 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro ...@@ -143,19 +147,19 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro
} }
if (change_color) if (change_color)
color = ui_browser__set_color(self, HE_COLORSET_ADDR); color = ui_browser__set_color(browser, HE_COLORSET_ADDR);
slsmg_write_nstring(bf, printed); slsmg_write_nstring(bf, printed);
if (change_color) if (change_color)
ui_browser__set_color(self, color); ui_browser__set_color(browser, color);
if (dl->ins && dl->ins->ops->scnprintf) { if (dl->ins && dl->ins->ops->scnprintf) {
if (ins__is_jump(dl->ins)) { if (ins__is_jump(dl->ins)) {
bool fwd = dl->ops.target.offset > (u64)dl->offset; bool fwd = dl->ops.target.offset > (u64)dl->offset;
ui_browser__write_graph(self, fwd ? SLSMG_DARROW_CHAR : ui_browser__write_graph(browser, fwd ? SLSMG_DARROW_CHAR :
SLSMG_UARROW_CHAR); SLSMG_UARROW_CHAR);
SLsmg_write_char(' '); SLsmg_write_char(' ');
} else if (ins__is_call(dl->ins)) { } else if (ins__is_call(dl->ins)) {
ui_browser__write_graph(self, SLSMG_RARROW_CHAR); ui_browser__write_graph(browser, SLSMG_RARROW_CHAR);
SLsmg_write_char(' '); SLsmg_write_char(' ');
} else { } else {
slsmg_write_nstring(" ", 2); slsmg_write_nstring(" ", 2);
...@@ -164,12 +168,12 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro ...@@ -164,12 +168,12 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro
if (strcmp(dl->name, "retq")) { if (strcmp(dl->name, "retq")) {
slsmg_write_nstring(" ", 2); slsmg_write_nstring(" ", 2);
} else { } else {
ui_browser__write_graph(self, SLSMG_LARROW_CHAR); ui_browser__write_graph(browser, SLSMG_LARROW_CHAR);
SLsmg_write_char(' '); SLsmg_write_char(' ');
} }
} }
disasm_line__scnprintf(dl, bf, sizeof(bf), !ab->use_offset); disasm_line__scnprintf(dl, bf, sizeof(bf), !annotate_browser__opts.use_offset);
slsmg_write_nstring(bf, width - 10 - printed); slsmg_write_nstring(bf, width - 10 - printed);
} }
...@@ -184,7 +188,7 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser) ...@@ -184,7 +188,7 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser)
struct browser_disasm_line *btarget, *bcursor; struct browser_disasm_line *btarget, *bcursor;
unsigned int from, to; unsigned int from, to;
if (!cursor->ins || !ins__is_jump(cursor->ins) || if (!cursor || !cursor->ins || !ins__is_jump(cursor->ins) ||
!disasm_line__has_offset(cursor)) !disasm_line__has_offset(cursor))
return; return;
...@@ -195,7 +199,7 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser) ...@@ -195,7 +199,7 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser)
bcursor = disasm_line__browser(cursor); bcursor = disasm_line__browser(cursor);
btarget = disasm_line__browser(target); btarget = disasm_line__browser(target);
if (ab->hide_src_code) { if (annotate_browser__opts.hide_src_code) {
from = bcursor->idx_asm; from = bcursor->idx_asm;
to = btarget->idx_asm; to = btarget->idx_asm;
} else { } else {
...@@ -209,10 +213,9 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser) ...@@ -209,10 +213,9 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser)
static unsigned int annotate_browser__refresh(struct ui_browser *browser) static unsigned int annotate_browser__refresh(struct ui_browser *browser)
{ {
struct annotate_browser *ab = container_of(browser, struct annotate_browser, b);
int ret = ui_browser__list_head_refresh(browser); int ret = ui_browser__list_head_refresh(browser);
if (ab->jump_arrows) if (annotate_browser__opts.jump_arrows)
annotate_browser__draw_current_jump(browser); annotate_browser__draw_current_jump(browser);
ui_browser__set_color(browser, HE_COLORSET_NORMAL); ui_browser__set_color(browser, HE_COLORSET_NORMAL);
...@@ -272,27 +275,27 @@ static void disasm_rb_tree__insert(struct rb_root *root, struct browser_disasm_l ...@@ -272,27 +275,27 @@ static void disasm_rb_tree__insert(struct rb_root *root, struct browser_disasm_l
rb_insert_color(&bdl->rb_node, root); rb_insert_color(&bdl->rb_node, root);
} }
static void annotate_browser__set_top(struct annotate_browser *self, static void annotate_browser__set_top(struct annotate_browser *browser,
struct disasm_line *pos, u32 idx) struct disasm_line *pos, u32 idx)
{ {
unsigned back; unsigned back;
ui_browser__refresh_dimensions(&self->b); ui_browser__refresh_dimensions(&browser->b);
back = self->b.height / 2; back = browser->b.height / 2;
self->b.top_idx = self->b.index = idx; browser->b.top_idx = browser->b.index = idx;
while (self->b.top_idx != 0 && back != 0) { while (browser->b.top_idx != 0 && back != 0) {
pos = list_entry(pos->node.prev, struct disasm_line, node); pos = list_entry(pos->node.prev, struct disasm_line, node);
if (disasm_line__filter(&self->b, &pos->node)) if (disasm_line__filter(&browser->b, &pos->node))
continue; continue;
--self->b.top_idx; --browser->b.top_idx;
--back; --back;
} }
self->b.top = pos; browser->b.top = pos;
self->b.navkeypressed = true; browser->b.navkeypressed = true;
} }
static void annotate_browser__set_rb_top(struct annotate_browser *browser, static void annotate_browser__set_rb_top(struct annotate_browser *browser,
...@@ -305,7 +308,7 @@ static void annotate_browser__set_rb_top(struct annotate_browser *browser, ...@@ -305,7 +308,7 @@ static void annotate_browser__set_rb_top(struct annotate_browser *browser,
bpos = rb_entry(nd, struct browser_disasm_line, rb_node); bpos = rb_entry(nd, struct browser_disasm_line, rb_node);
pos = ((struct disasm_line *)bpos) - 1; pos = ((struct disasm_line *)bpos) - 1;
idx = bpos->idx; idx = bpos->idx;
if (browser->hide_src_code) if (annotate_browser__opts.hide_src_code)
idx = bpos->idx_asm; idx = bpos->idx_asm;
annotate_browser__set_top(browser, pos, idx); annotate_browser__set_top(browser, pos, idx);
browser->curr_hot = nd; browser->curr_hot = nd;
...@@ -347,12 +350,12 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser) ...@@ -347,12 +350,12 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser)
dl = list_entry(browser->b.top, struct disasm_line, node); dl = list_entry(browser->b.top, struct disasm_line, node);
bdl = disasm_line__browser(dl); bdl = disasm_line__browser(dl);
if (browser->hide_src_code) { if (annotate_browser__opts.hide_src_code) {
if (bdl->idx_asm < offset) if (bdl->idx_asm < offset)
offset = bdl->idx; offset = bdl->idx;
browser->b.nr_entries = browser->nr_entries; browser->b.nr_entries = browser->nr_entries;
browser->hide_src_code = false; annotate_browser__opts.hide_src_code = false;
browser->b.seek(&browser->b, -offset, SEEK_CUR); browser->b.seek(&browser->b, -offset, SEEK_CUR);
browser->b.top_idx = bdl->idx - offset; browser->b.top_idx = bdl->idx - offset;
browser->b.index = bdl->idx; browser->b.index = bdl->idx;
...@@ -367,7 +370,7 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser) ...@@ -367,7 +370,7 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser)
offset = bdl->idx_asm; offset = bdl->idx_asm;
browser->b.nr_entries = browser->nr_asm_entries; browser->b.nr_entries = browser->nr_asm_entries;
browser->hide_src_code = true; annotate_browser__opts.hide_src_code = true;
browser->b.seek(&browser->b, -offset, SEEK_CUR); browser->b.seek(&browser->b, -offset, SEEK_CUR);
browser->b.top_idx = bdl->idx_asm - offset; browser->b.top_idx = bdl->idx_asm - offset;
browser->b.index = bdl->idx_asm; browser->b.index = bdl->idx_asm;
...@@ -376,6 +379,12 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser) ...@@ -376,6 +379,12 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser)
return true; return true;
} }
static void annotate_browser__init_asm_mode(struct annotate_browser *browser)
{
ui_browser__reset_index(&browser->b);
browser->b.nr_entries = browser->nr_asm_entries;
}
static bool annotate_browser__callq(struct annotate_browser *browser, static bool annotate_browser__callq(struct annotate_browser *browser,
int evidx, void (*timer)(void *arg), int evidx, void (*timer)(void *arg),
void *arg, int delay_secs) void *arg, int delay_secs)
...@@ -578,33 +587,46 @@ bool annotate_browser__continue_search_reverse(struct annotate_browser *browser, ...@@ -578,33 +587,46 @@ bool annotate_browser__continue_search_reverse(struct annotate_browser *browser,
return __annotate_browser__search_reverse(browser); return __annotate_browser__search_reverse(browser);
} }
static int annotate_browser__run(struct annotate_browser *self, int evidx, static void annotate_browser__update_addr_width(struct annotate_browser *browser)
{
if (annotate_browser__opts.use_offset)
browser->target_width = browser->min_addr_width;
else
browser->target_width = browser->max_addr_width;
browser->addr_width = browser->target_width;
if (annotate_browser__opts.show_nr_jumps)
browser->addr_width += browser->jumps_width + 1;
}
static int annotate_browser__run(struct annotate_browser *browser, int evidx,
void(*timer)(void *arg), void(*timer)(void *arg),
void *arg, int delay_secs) void *arg, int delay_secs)
{ {
struct rb_node *nd = NULL; struct rb_node *nd = NULL;
struct map_symbol *ms = self->b.priv; struct map_symbol *ms = browser->b.priv;
struct symbol *sym = ms->sym; struct symbol *sym = ms->sym;
const char *help = "Press 'h' for help on key bindings"; const char *help = "Press 'h' for help on key bindings";
int key; int key;
if (ui_browser__show(&self->b, sym->name, help) < 0) if (ui_browser__show(&browser->b, sym->name, help) < 0)
return -1; return -1;
annotate_browser__calc_percent(self, evidx); annotate_browser__calc_percent(browser, evidx);
if (self->curr_hot) { if (browser->curr_hot) {
annotate_browser__set_rb_top(self, self->curr_hot); annotate_browser__set_rb_top(browser, browser->curr_hot);
self->b.navkeypressed = false; browser->b.navkeypressed = false;
} }
nd = self->curr_hot; nd = browser->curr_hot;
while (1) { while (1) {
key = ui_browser__run(&self->b, delay_secs); key = ui_browser__run(&browser->b, delay_secs);
if (delay_secs != 0) { if (delay_secs != 0) {
annotate_browser__calc_percent(self, evidx); annotate_browser__calc_percent(browser, evidx);
/* /*
* Current line focus got out of the list of most active * Current line focus got out of the list of most active
* lines, NULL it so that if TAB|UNTAB is pressed, we * lines, NULL it so that if TAB|UNTAB is pressed, we
...@@ -626,21 +648,21 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx, ...@@ -626,21 +648,21 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx,
if (nd != NULL) { if (nd != NULL) {
nd = rb_prev(nd); nd = rb_prev(nd);
if (nd == NULL) if (nd == NULL)
nd = rb_last(&self->entries); nd = rb_last(&browser->entries);
} else } else
nd = self->curr_hot; nd = browser->curr_hot;
break; break;
case K_UNTAB: case K_UNTAB:
if (nd != NULL) if (nd != NULL)
nd = rb_next(nd); nd = rb_next(nd);
if (nd == NULL) if (nd == NULL)
nd = rb_first(&self->entries); nd = rb_first(&browser->entries);
else else
nd = self->curr_hot; nd = browser->curr_hot;
break; break;
case K_F1: case K_F1:
case 'h': case 'h':
ui_browser__help_window(&self->b, ui_browser__help_window(&browser->b,
"UP/DOWN/PGUP\n" "UP/DOWN/PGUP\n"
"PGDN/SPACE Navigate\n" "PGDN/SPACE Navigate\n"
"q/ESC/CTRL+C Exit\n\n" "q/ESC/CTRL+C Exit\n\n"
...@@ -656,57 +678,62 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx, ...@@ -656,57 +678,62 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx,
"? Search previous string\n"); "? Search previous string\n");
continue; continue;
case 'H': case 'H':
nd = self->curr_hot; nd = browser->curr_hot;
break; break;
case 's': case 's':
if (annotate_browser__toggle_source(self)) if (annotate_browser__toggle_source(browser))
ui_helpline__puts(help); ui_helpline__puts(help);
continue; continue;
case 'o': case 'o':
self->use_offset = !self->use_offset; annotate_browser__opts.use_offset = !annotate_browser__opts.use_offset;
if (self->use_offset) annotate_browser__update_addr_width(browser);
self->target_width = self->min_addr_width;
else
self->target_width = self->max_addr_width;
update_addr_width:
self->addr_width = self->target_width;
if (self->show_nr_jumps)
self->addr_width += self->jumps_width + 1;
continue; continue;
case 'j': case 'j':
self->jump_arrows = !self->jump_arrows; annotate_browser__opts.jump_arrows = !annotate_browser__opts.jump_arrows;
continue; continue;
case 'J': case 'J':
self->show_nr_jumps = !self->show_nr_jumps; annotate_browser__opts.show_nr_jumps = !annotate_browser__opts.show_nr_jumps;
goto update_addr_width; annotate_browser__update_addr_width(browser);
continue;
case '/': case '/':
if (annotate_browser__search(self, delay_secs)) { if (annotate_browser__search(browser, delay_secs)) {
show_help: show_help:
ui_helpline__puts(help); ui_helpline__puts(help);
} }
continue; continue;
case 'n': case 'n':
if (self->searching_backwards ? if (browser->searching_backwards ?
annotate_browser__continue_search_reverse(self, delay_secs) : annotate_browser__continue_search_reverse(browser, delay_secs) :
annotate_browser__continue_search(self, delay_secs)) annotate_browser__continue_search(browser, delay_secs))
goto show_help; goto show_help;
continue; continue;
case '?': case '?':
if (annotate_browser__search_reverse(self, delay_secs)) if (annotate_browser__search_reverse(browser, delay_secs))
goto show_help; goto show_help;
continue; continue;
case 'D': {
static int seq;
ui_helpline__pop();
ui_helpline__fpush("%d: nr_ent=%d, height=%d, idx=%d, top_idx=%d, nr_asm_entries=%d",
seq++, browser->b.nr_entries,
browser->b.height,
browser->b.index,
browser->b.top_idx,
browser->nr_asm_entries);
}
continue;
case K_ENTER: case K_ENTER:
case K_RIGHT: case K_RIGHT:
if (self->selection == NULL) if (browser->selection == NULL)
ui_helpline__puts("Huh? No selection. Report to linux-kernel@vger.kernel.org"); ui_helpline__puts("Huh? No selection. Report to linux-kernel@vger.kernel.org");
else if (self->selection->offset == -1) else if (browser->selection->offset == -1)
ui_helpline__puts("Actions are only available for assembly lines."); ui_helpline__puts("Actions are only available for assembly lines.");
else if (!self->selection->ins) { else if (!browser->selection->ins) {
if (strcmp(self->selection->name, "retq")) if (strcmp(browser->selection->name, "retq"))
goto show_sup_ins; goto show_sup_ins;
goto out; goto out;
} else if (!(annotate_browser__jump(self) || } else if (!(annotate_browser__jump(browser) ||
annotate_browser__callq(self, evidx, timer, arg, delay_secs))) { annotate_browser__callq(browser, evidx, timer, arg, delay_secs))) {
show_sup_ins: show_sup_ins:
ui_helpline__puts("Actions are only available for 'callq', 'retq' & jump instructions."); ui_helpline__puts("Actions are only available for 'callq', 'retq' & jump instructions.");
} }
...@@ -721,10 +748,10 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx, ...@@ -721,10 +748,10 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx,
} }
if (nd != NULL) if (nd != NULL)
annotate_browser__set_rb_top(self, nd); annotate_browser__set_rb_top(browser, nd);
} }
out: out:
ui_browser__hide(&self->b); ui_browser__hide(&browser->b);
return key; return key;
} }
...@@ -801,8 +828,6 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx, ...@@ -801,8 +828,6 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
.priv = &ms, .priv = &ms,
.use_navkeypressed = true, .use_navkeypressed = true,
}, },
.use_offset = true,
.jump_arrows = true,
}; };
int ret = -1; int ret = -1;
...@@ -859,6 +884,12 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx, ...@@ -859,6 +884,12 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
browser.b.nr_entries = browser.nr_entries; browser.b.nr_entries = browser.nr_entries;
browser.b.entries = &notes->src->source, browser.b.entries = &notes->src->source,
browser.b.width += 18; /* Percentage */ browser.b.width += 18; /* Percentage */
if (annotate_browser__opts.hide_src_code)
annotate_browser__init_asm_mode(&browser);
annotate_browser__update_addr_width(&browser);
ret = annotate_browser__run(&browser, evidx, timer, arg, delay_secs); ret = annotate_browser__run(&browser, evidx, timer, arg, delay_secs);
list_for_each_entry_safe(pos, n, &notes->src->source, node) { list_for_each_entry_safe(pos, n, &notes->src->source, node) {
list_del(&pos->node); list_del(&pos->node);
...@@ -869,3 +900,52 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx, ...@@ -869,3 +900,52 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
free(browser.offsets); free(browser.offsets);
return ret; return ret;
} }
#define ANNOTATE_CFG(n) \
{ .name = #n, .value = &annotate_browser__opts.n, }
/*
* Keep the entries sorted, they are bsearch'ed
*/
static struct annotate__config {
const char *name;
bool *value;
} annotate__configs[] = {
ANNOTATE_CFG(hide_src_code),
ANNOTATE_CFG(jump_arrows),
ANNOTATE_CFG(show_nr_jumps),
ANNOTATE_CFG(use_offset),
};
#undef ANNOTATE_CFG
static int annotate_config__cmp(const void *name, const void *cfgp)
{
const struct annotate__config *cfg = cfgp;
return strcmp(name, cfg->name);
}
static int annotate__config(const char *var, const char *value, void *data __used)
{
struct annotate__config *cfg;
const char *name;
if (prefixcmp(var, "annotate.") != 0)
return 0;
name = var + 9;
cfg = bsearch(name, annotate__configs, ARRAY_SIZE(annotate__configs),
sizeof(struct annotate__config), annotate_config__cmp);
if (cfg == NULL)
return -1;
*cfg->value = perf_config_bool(name, value);
return 0;
}
void annotate_browser__init(void)
{
perf_config(annotate__config, NULL);
}
此差异已折叠。
...@@ -120,7 +120,7 @@ static char *parse_value(void) ...@@ -120,7 +120,7 @@ static char *parse_value(void)
static inline int iskeychar(int c) static inline int iskeychar(int c)
{ {
return isalnum(c) || c == '-'; return isalnum(c) || c == '-' || c == '_';
} }
static int get_value(config_fn_t fn, void *data, char *name, unsigned int len) static int get_value(config_fn_t fn, void *data, char *name, unsigned int len)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册