Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 1 | #include "../browser.h" |
| 2 | #include "../helpline.h" |
| 3 | #include "../libslang.h" |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 4 | #include "../../annotate.h" |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 5 | #include "../../hist.h" |
| 6 | #include "../../sort.h" |
| 7 | #include "../../symbol.h" |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 8 | #include <pthread.h> |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 9 | |
| 10 | static void ui__error_window(const char *fmt, ...) |
| 11 | { |
| 12 | va_list ap; |
| 13 | |
| 14 | va_start(ap, fmt); |
| 15 | newtWinMessagev((char *)"Error", (char *)"Ok", (char *)fmt, ap); |
| 16 | va_end(ap); |
| 17 | } |
| 18 | |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 19 | struct annotate_browser { |
| 20 | struct ui_browser b; |
| 21 | struct rb_root entries; |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 22 | struct rb_node *curr_hot; |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 23 | struct objdump_line *selection; |
Arnaldo Carvalho de Melo | 0361fc2 | 2011-10-14 12:31:21 -0300 | [diff] [blame] | 24 | int nr_asm_entries; |
| 25 | int nr_entries; |
| 26 | bool hide_src_code; |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | struct objdump_line_rb_node { |
| 30 | struct rb_node rb_node; |
| 31 | double percent; |
| 32 | u32 idx; |
Arnaldo Carvalho de Melo | 0361fc2 | 2011-10-14 12:31:21 -0300 | [diff] [blame] | 33 | int idx_asm; |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | static inline |
| 37 | struct objdump_line_rb_node *objdump_line__rb(struct objdump_line *self) |
| 38 | { |
| 39 | return (struct objdump_line_rb_node *)(self + 1); |
| 40 | } |
| 41 | |
Arnaldo Carvalho de Melo | 0361fc2 | 2011-10-14 12:31:21 -0300 | [diff] [blame] | 42 | static bool objdump_line__filter(struct ui_browser *browser, void *entry) |
| 43 | { |
| 44 | struct annotate_browser *ab = container_of(browser, struct annotate_browser, b); |
| 45 | |
| 46 | if (ab->hide_src_code) { |
| 47 | struct objdump_line *ol = list_entry(entry, struct objdump_line, node); |
| 48 | return ol->offset == -1; |
| 49 | } |
| 50 | |
| 51 | return false; |
| 52 | } |
| 53 | |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 54 | static void annotate_browser__write(struct ui_browser *self, void *entry, int row) |
| 55 | { |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 56 | struct annotate_browser *ab = container_of(self, struct annotate_browser, b); |
Arnaldo Carvalho de Melo | 0361fc2 | 2011-10-14 12:31:21 -0300 | [diff] [blame] | 57 | struct objdump_line *ol = list_entry(entry, struct objdump_line, node); |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 58 | bool current_entry = ui_browser__is_current_entry(self, row); |
| 59 | int width = self->width; |
| 60 | |
| 61 | if (ol->offset != -1) { |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 62 | struct objdump_line_rb_node *olrb = objdump_line__rb(ol); |
Arnaldo Carvalho de Melo | 8f9bbc4 | 2010-08-11 14:51:47 -0300 | [diff] [blame] | 63 | ui_browser__set_percent_color(self, olrb->percent, current_entry); |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 64 | slsmg_printf(" %7.2f ", olrb->percent); |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 65 | } else { |
Arnaldo Carvalho de Melo | 8f9bbc4 | 2010-08-11 14:51:47 -0300 | [diff] [blame] | 66 | ui_browser__set_percent_color(self, 0, current_entry); |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 67 | slsmg_write_nstring(" ", 9); |
| 68 | } |
| 69 | |
| 70 | SLsmg_write_char(':'); |
| 71 | slsmg_write_nstring(" ", 8); |
Arnaldo Carvalho de Melo | c172f74 | 2011-10-18 14:31:35 -0200 | [diff] [blame] | 72 | |
| 73 | /* The scroll bar isn't being used */ |
| 74 | if (!self->navkeypressed) |
| 75 | width += 1; |
| 76 | |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 77 | if (!*ol->line) |
| 78 | slsmg_write_nstring(" ", width - 18); |
| 79 | else |
| 80 | slsmg_write_nstring(ol->line, width - 18); |
Arnaldo Carvalho de Melo | b99976e | 2011-02-09 13:59:14 -0200 | [diff] [blame] | 81 | |
| 82 | if (!current_entry) |
| 83 | ui_browser__set_color(self, HE_COLORSET_CODE); |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 84 | else |
| 85 | ab->selection = ol; |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 86 | } |
| 87 | |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 88 | static double objdump_line__calc_percent(struct objdump_line *self, |
Arnaldo Carvalho de Melo | 2f525d0 | 2011-02-04 13:43:24 -0200 | [diff] [blame] | 89 | struct symbol *sym, int evidx) |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 90 | { |
| 91 | double percent = 0.0; |
| 92 | |
| 93 | if (self->offset != -1) { |
| 94 | int len = sym->end - sym->start; |
| 95 | unsigned int hits = 0; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 96 | struct annotation *notes = symbol__annotation(sym); |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 97 | struct source_line *src_line = notes->src->lines; |
Arnaldo Carvalho de Melo | 2f525d0 | 2011-02-04 13:43:24 -0200 | [diff] [blame] | 98 | struct sym_hist *h = annotation__histogram(notes, evidx); |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 99 | s64 offset = self->offset; |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 100 | struct objdump_line *next; |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 101 | |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 102 | next = objdump__get_next_ip_line(¬es->src->source, self); |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 103 | while (offset < (s64)len && |
| 104 | (next == NULL || offset < next->offset)) { |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 105 | if (src_line) { |
| 106 | percent += src_line[offset].percent; |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 107 | } else |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 108 | hits += h->addr[offset]; |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 109 | |
| 110 | ++offset; |
| 111 | } |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 112 | /* |
| 113 | * If the percentage wasn't already calculated in |
| 114 | * symbol__get_source_line, do it now: |
| 115 | */ |
| 116 | if (src_line == NULL && h->sum) |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 117 | percent = 100.0 * hits / h->sum; |
| 118 | } |
| 119 | |
| 120 | return percent; |
| 121 | } |
| 122 | |
| 123 | static void objdump__insert_line(struct rb_root *self, |
| 124 | struct objdump_line_rb_node *line) |
| 125 | { |
| 126 | struct rb_node **p = &self->rb_node; |
| 127 | struct rb_node *parent = NULL; |
| 128 | struct objdump_line_rb_node *l; |
| 129 | |
| 130 | while (*p != NULL) { |
| 131 | parent = *p; |
| 132 | l = rb_entry(parent, struct objdump_line_rb_node, rb_node); |
| 133 | if (line->percent < l->percent) |
| 134 | p = &(*p)->rb_left; |
| 135 | else |
| 136 | p = &(*p)->rb_right; |
| 137 | } |
| 138 | rb_link_node(&line->rb_node, parent, p); |
| 139 | rb_insert_color(&line->rb_node, self); |
| 140 | } |
| 141 | |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 142 | static void annotate_browser__set_top(struct annotate_browser *self, |
| 143 | struct rb_node *nd) |
| 144 | { |
| 145 | struct objdump_line_rb_node *rbpos; |
| 146 | struct objdump_line *pos; |
| 147 | unsigned back; |
| 148 | |
| 149 | ui_browser__refresh_dimensions(&self->b); |
| 150 | back = self->b.height / 2; |
| 151 | rbpos = rb_entry(nd, struct objdump_line_rb_node, rb_node); |
| 152 | pos = ((struct objdump_line *)rbpos) - 1; |
| 153 | self->b.top_idx = self->b.index = rbpos->idx; |
| 154 | |
| 155 | while (self->b.top_idx != 0 && back != 0) { |
| 156 | pos = list_entry(pos->node.prev, struct objdump_line, node); |
| 157 | |
| 158 | --self->b.top_idx; |
| 159 | --back; |
| 160 | } |
| 161 | |
| 162 | self->b.top = pos; |
| 163 | self->curr_hot = nd; |
| 164 | } |
| 165 | |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 166 | static void annotate_browser__calc_percent(struct annotate_browser *browser, |
| 167 | int evidx) |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 168 | { |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 169 | struct map_symbol *ms = browser->b.priv; |
| 170 | struct symbol *sym = ms->sym; |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 171 | struct annotation *notes = symbol__annotation(sym); |
| 172 | struct objdump_line *pos; |
| 173 | |
| 174 | browser->entries = RB_ROOT; |
| 175 | |
| 176 | pthread_mutex_lock(¬es->lock); |
| 177 | |
| 178 | list_for_each_entry(pos, ¬es->src->source, node) { |
| 179 | struct objdump_line_rb_node *rbpos = objdump_line__rb(pos); |
| 180 | rbpos->percent = objdump_line__calc_percent(pos, sym, evidx); |
| 181 | if (rbpos->percent < 0.01) { |
| 182 | RB_CLEAR_NODE(&rbpos->rb_node); |
| 183 | continue; |
| 184 | } |
| 185 | objdump__insert_line(&browser->entries, rbpos); |
| 186 | } |
| 187 | pthread_mutex_unlock(¬es->lock); |
| 188 | |
| 189 | browser->curr_hot = rb_last(&browser->entries); |
| 190 | } |
| 191 | |
Arnaldo Carvalho de Melo | 0361fc2 | 2011-10-14 12:31:21 -0300 | [diff] [blame] | 192 | static bool annotate_browser__toggle_source(struct annotate_browser *browser) |
| 193 | { |
| 194 | struct objdump_line *ol; |
| 195 | struct objdump_line_rb_node *olrb; |
| 196 | off_t offset = browser->b.index - browser->b.top_idx; |
| 197 | |
| 198 | browser->b.seek(&browser->b, offset, SEEK_CUR); |
| 199 | ol = list_entry(browser->b.top, struct objdump_line, node); |
| 200 | olrb = objdump_line__rb(ol); |
| 201 | |
| 202 | if (browser->hide_src_code) { |
| 203 | if (olrb->idx_asm < offset) |
| 204 | offset = olrb->idx; |
| 205 | |
| 206 | browser->b.nr_entries = browser->nr_entries; |
| 207 | browser->hide_src_code = false; |
| 208 | browser->b.seek(&browser->b, -offset, SEEK_CUR); |
| 209 | browser->b.top_idx = olrb->idx - offset; |
| 210 | browser->b.index = olrb->idx; |
| 211 | } else { |
| 212 | if (olrb->idx_asm < 0) { |
| 213 | ui_helpline__puts("Only available for assembly lines."); |
| 214 | browser->b.seek(&browser->b, -offset, SEEK_CUR); |
| 215 | return false; |
| 216 | } |
| 217 | |
| 218 | if (olrb->idx_asm < offset) |
| 219 | offset = olrb->idx_asm; |
| 220 | |
| 221 | browser->b.nr_entries = browser->nr_asm_entries; |
| 222 | browser->hide_src_code = true; |
| 223 | browser->b.seek(&browser->b, -offset, SEEK_CUR); |
| 224 | browser->b.top_idx = olrb->idx_asm - offset; |
| 225 | browser->b.index = olrb->idx_asm; |
| 226 | } |
| 227 | |
| 228 | return true; |
| 229 | } |
| 230 | |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 231 | static int annotate_browser__run(struct annotate_browser *self, int evidx, |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 232 | int nr_events, void(*timer)(void *arg), |
| 233 | void *arg, int delay_secs) |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 234 | { |
| 235 | struct rb_node *nd = NULL; |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 236 | struct map_symbol *ms = self->b.priv; |
| 237 | struct symbol *sym = ms->sym; |
Arnaldo Carvalho de Melo | 0361fc2 | 2011-10-14 12:31:21 -0300 | [diff] [blame] | 238 | const char *help = "<-, ESC: exit, TAB/shift+TAB: cycle hottest lines, " |
| 239 | "H: Hottest, -> Line action, S -> Toggle source " |
| 240 | "code view"; |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 241 | int key; |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 242 | |
Arnaldo Carvalho de Melo | 0361fc2 | 2011-10-14 12:31:21 -0300 | [diff] [blame] | 243 | if (ui_browser__show(&self->b, sym->name, help) < 0) |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 244 | return -1; |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 245 | |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 246 | annotate_browser__calc_percent(self, evidx); |
| 247 | |
| 248 | if (self->curr_hot) |
| 249 | annotate_browser__set_top(self, self->curr_hot); |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 250 | |
| 251 | nd = self->curr_hot; |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 252 | |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 253 | while (1) { |
Arnaldo Carvalho de Melo | 3af6e33 | 2011-10-13 08:52:46 -0300 | [diff] [blame] | 254 | key = ui_browser__run(&self->b, delay_secs); |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 255 | |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 256 | if (delay_secs != 0) { |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 257 | annotate_browser__calc_percent(self, evidx); |
| 258 | /* |
| 259 | * Current line focus got out of the list of most active |
| 260 | * lines, NULL it so that if TAB|UNTAB is pressed, we |
| 261 | * move to curr_hot (current hottest line). |
| 262 | */ |
| 263 | if (nd != NULL && RB_EMPTY_NODE(nd)) |
| 264 | nd = NULL; |
| 265 | } |
| 266 | |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 267 | switch (key) { |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 268 | case -1: |
| 269 | /* |
| 270 | * FIXME we need to check if it was |
| 271 | * es.reason == NEWT_EXIT_TIMER |
| 272 | */ |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 273 | if (timer != NULL) |
| 274 | timer(arg); |
| 275 | |
| 276 | if (delay_secs != 0) |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 277 | symbol__annotate_decay_histogram(sym, evidx); |
| 278 | continue; |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 279 | case NEWT_KEY_TAB: |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 280 | if (nd != NULL) { |
| 281 | nd = rb_prev(nd); |
| 282 | if (nd == NULL) |
| 283 | nd = rb_last(&self->entries); |
| 284 | } else |
| 285 | nd = self->curr_hot; |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 286 | break; |
| 287 | case NEWT_KEY_UNTAB: |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 288 | if (nd != NULL) |
| 289 | nd = rb_next(nd); |
| 290 | if (nd == NULL) |
| 291 | nd = rb_first(&self->entries); |
| 292 | else |
| 293 | nd = self->curr_hot; |
| 294 | break; |
| 295 | case 'H': |
| 296 | nd = self->curr_hot; |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 297 | break; |
Arnaldo Carvalho de Melo | 0361fc2 | 2011-10-14 12:31:21 -0300 | [diff] [blame] | 298 | case 'S': |
| 299 | if (annotate_browser__toggle_source(self)) |
| 300 | ui_helpline__puts(help); |
| 301 | continue; |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 302 | case NEWT_KEY_ENTER: |
Arnaldo Carvalho de Melo | 234a537 | 2011-10-06 09:45:29 -0300 | [diff] [blame] | 303 | case NEWT_KEY_RIGHT: |
| 304 | if (self->selection == NULL) { |
| 305 | ui_helpline__puts("Huh? No selection. Report to linux-kernel@vger.kernel.org"); |
| 306 | continue; |
| 307 | } |
| 308 | |
| 309 | if (self->selection->offset == -1) { |
| 310 | ui_helpline__puts("Actions are only available for assembly lines."); |
| 311 | continue; |
| 312 | } else { |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 313 | char *s = strstr(self->selection->line, "callq "); |
| 314 | struct annotation *notes; |
| 315 | struct symbol *target; |
| 316 | u64 ip; |
| 317 | |
Arnaldo Carvalho de Melo | 234a537 | 2011-10-06 09:45:29 -0300 | [diff] [blame] | 318 | if (s == NULL) { |
| 319 | ui_helpline__puts("Actions are only available for the 'callq' instruction."); |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 320 | continue; |
Arnaldo Carvalho de Melo | 234a537 | 2011-10-06 09:45:29 -0300 | [diff] [blame] | 321 | } |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 322 | |
| 323 | s = strchr(s, ' '); |
Arnaldo Carvalho de Melo | 234a537 | 2011-10-06 09:45:29 -0300 | [diff] [blame] | 324 | if (s++ == NULL) { |
| 325 | ui_helpline__puts("Invallid callq instruction."); |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 326 | continue; |
Arnaldo Carvalho de Melo | 234a537 | 2011-10-06 09:45:29 -0300 | [diff] [blame] | 327 | } |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 328 | |
| 329 | ip = strtoull(s, NULL, 16); |
| 330 | ip = ms->map->map_ip(ms->map, ip); |
| 331 | target = map__find_symbol(ms->map, ip, NULL); |
Arnaldo Carvalho de Melo | 234a537 | 2011-10-06 09:45:29 -0300 | [diff] [blame] | 332 | if (target == NULL) { |
| 333 | ui_helpline__puts("The called function was not found."); |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 334 | continue; |
Arnaldo Carvalho de Melo | 234a537 | 2011-10-06 09:45:29 -0300 | [diff] [blame] | 335 | } |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 336 | |
| 337 | notes = symbol__annotation(target); |
| 338 | pthread_mutex_lock(¬es->lock); |
| 339 | |
| 340 | if (notes->src == NULL && |
| 341 | symbol__alloc_hist(target, nr_events) < 0) { |
| 342 | pthread_mutex_unlock(¬es->lock); |
| 343 | ui__warning("Not enough memory for annotating '%s' symbol!\n", |
| 344 | target->name); |
| 345 | continue; |
| 346 | } |
| 347 | |
| 348 | pthread_mutex_unlock(¬es->lock); |
| 349 | symbol__tui_annotate(target, ms->map, evidx, nr_events, |
| 350 | timer, arg, delay_secs); |
| 351 | } |
Arnaldo Carvalho de Melo | fe46e64 | 2011-10-19 13:18:13 -0200 | [diff] [blame^] | 352 | continue; |
Arnaldo Carvalho de Melo | 7296d66 | 2011-10-14 09:37:38 -0300 | [diff] [blame] | 353 | case NEWT_KEY_LEFT: |
| 354 | case NEWT_KEY_ESCAPE: |
Arnaldo Carvalho de Melo | ed7e566 | 2011-10-13 08:31:22 -0300 | [diff] [blame] | 355 | case 'q': |
| 356 | case CTRL('c'): |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 357 | goto out; |
Arnaldo Carvalho de Melo | ed7e566 | 2011-10-13 08:31:22 -0300 | [diff] [blame] | 358 | default: |
| 359 | continue; |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 360 | } |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 361 | |
| 362 | if (nd != NULL) |
| 363 | annotate_browser__set_top(self, nd); |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 364 | } |
| 365 | out: |
Arnaldo Carvalho de Melo | 59e8fe3 | 2010-08-10 15:44:20 -0300 | [diff] [blame] | 366 | ui_browser__hide(&self->b); |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 367 | return key; |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 368 | } |
| 369 | |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 370 | int hist_entry__tui_annotate(struct hist_entry *he, int evidx, int nr_events, |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 371 | void(*timer)(void *arg), void *arg, int delay_secs) |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 372 | { |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 373 | return symbol__tui_annotate(he->ms.sym, he->ms.map, evidx, nr_events, |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 374 | timer, arg, delay_secs); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 375 | } |
| 376 | |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 377 | int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx, |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 378 | int nr_events, void(*timer)(void *arg), void *arg, |
| 379 | int delay_secs) |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 380 | { |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 381 | struct objdump_line *pos, *n; |
Lin Ming | db9a9cbc | 2011-04-08 14:31:26 +0800 | [diff] [blame] | 382 | struct annotation *notes; |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 383 | struct map_symbol ms = { |
| 384 | .map = map, |
| 385 | .sym = sym, |
| 386 | }; |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 387 | struct annotate_browser browser = { |
| 388 | .b = { |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 389 | .refresh = ui_browser__list_head_refresh, |
| 390 | .seek = ui_browser__list_head_seek, |
| 391 | .write = annotate_browser__write, |
Arnaldo Carvalho de Melo | 0361fc2 | 2011-10-14 12:31:21 -0300 | [diff] [blame] | 392 | .filter = objdump_line__filter, |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 393 | .priv = &ms, |
Arnaldo Carvalho de Melo | c172f74 | 2011-10-18 14:31:35 -0200 | [diff] [blame] | 394 | .use_navkeypressed = true, |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 395 | }, |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 396 | }; |
| 397 | int ret; |
| 398 | |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 399 | if (sym == NULL) |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 400 | return -1; |
| 401 | |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 402 | if (map->dso->annotate_warned) |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 403 | return -1; |
| 404 | |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 405 | if (symbol__annotate(sym, map, sizeof(struct objdump_line_rb_node)) < 0) { |
Arnaldo Carvalho de Melo | 1e6dd07 | 2010-08-10 15:58:50 -0300 | [diff] [blame] | 406 | ui__error_window(ui_helpline__last_msg); |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 407 | return -1; |
| 408 | } |
| 409 | |
| 410 | ui_helpline__push("Press <- or ESC to exit"); |
| 411 | |
Lin Ming | db9a9cbc | 2011-04-08 14:31:26 +0800 | [diff] [blame] | 412 | notes = symbol__annotation(sym); |
| 413 | |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 414 | list_for_each_entry(pos, ¬es->src->source, node) { |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 415 | struct objdump_line_rb_node *rbpos; |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 416 | size_t line_len = strlen(pos->line); |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 417 | |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 418 | if (browser.b.width < line_len) |
| 419 | browser.b.width = line_len; |
| 420 | rbpos = objdump_line__rb(pos); |
Arnaldo Carvalho de Melo | 0361fc2 | 2011-10-14 12:31:21 -0300 | [diff] [blame] | 421 | rbpos->idx = browser.nr_entries++; |
| 422 | if (pos->offset != -1) |
| 423 | rbpos->idx_asm = browser.nr_asm_entries++; |
| 424 | else |
| 425 | rbpos->idx_asm = -1; |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 426 | } |
| 427 | |
Arnaldo Carvalho de Melo | 0361fc2 | 2011-10-14 12:31:21 -0300 | [diff] [blame] | 428 | browser.b.nr_entries = browser.nr_entries; |
Lin Ming | db9a9cbc | 2011-04-08 14:31:26 +0800 | [diff] [blame] | 429 | browser.b.entries = ¬es->src->source, |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 430 | browser.b.width += 18; /* Percentage */ |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame] | 431 | ret = annotate_browser__run(&browser, evidx, nr_events, |
| 432 | timer, arg, delay_secs); |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 433 | list_for_each_entry_safe(pos, n, ¬es->src->source, node) { |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 434 | list_del(&pos->node); |
| 435 | objdump_line__free(pos); |
| 436 | } |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 437 | return ret; |
| 438 | } |