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 | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | struct objdump_line_rb_node { |
| 27 | struct rb_node rb_node; |
| 28 | double percent; |
| 29 | u32 idx; |
| 30 | }; |
| 31 | |
| 32 | static inline |
| 33 | struct objdump_line_rb_node *objdump_line__rb(struct objdump_line *self) |
| 34 | { |
| 35 | return (struct objdump_line_rb_node *)(self + 1); |
| 36 | } |
| 37 | |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 38 | static void annotate_browser__write(struct ui_browser *self, void *entry, int row) |
| 39 | { |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame^] | 40 | struct annotate_browser *ab = container_of(self, struct annotate_browser, b); |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 41 | struct objdump_line *ol = rb_entry(entry, struct objdump_line, node); |
| 42 | bool current_entry = ui_browser__is_current_entry(self, row); |
| 43 | int width = self->width; |
| 44 | |
| 45 | if (ol->offset != -1) { |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 46 | struct objdump_line_rb_node *olrb = objdump_line__rb(ol); |
Arnaldo Carvalho de Melo | 8f9bbc4 | 2010-08-11 14:51:47 -0300 | [diff] [blame] | 47 | ui_browser__set_percent_color(self, olrb->percent, current_entry); |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 48 | slsmg_printf(" %7.2f ", olrb->percent); |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 49 | } else { |
Arnaldo Carvalho de Melo | 8f9bbc4 | 2010-08-11 14:51:47 -0300 | [diff] [blame] | 50 | ui_browser__set_percent_color(self, 0, current_entry); |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 51 | slsmg_write_nstring(" ", 9); |
| 52 | } |
| 53 | |
| 54 | SLsmg_write_char(':'); |
| 55 | slsmg_write_nstring(" ", 8); |
| 56 | if (!*ol->line) |
| 57 | slsmg_write_nstring(" ", width - 18); |
| 58 | else |
| 59 | slsmg_write_nstring(ol->line, width - 18); |
Arnaldo Carvalho de Melo | b99976e | 2011-02-09 13:59:14 -0200 | [diff] [blame] | 60 | |
| 61 | if (!current_entry) |
| 62 | ui_browser__set_color(self, HE_COLORSET_CODE); |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame^] | 63 | else |
| 64 | ab->selection = ol; |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 65 | } |
| 66 | |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 67 | static double objdump_line__calc_percent(struct objdump_line *self, |
Arnaldo Carvalho de Melo | 2f525d0 | 2011-02-04 13:43:24 -0200 | [diff] [blame] | 68 | struct symbol *sym, int evidx) |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 69 | { |
| 70 | double percent = 0.0; |
| 71 | |
| 72 | if (self->offset != -1) { |
| 73 | int len = sym->end - sym->start; |
| 74 | unsigned int hits = 0; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 75 | struct annotation *notes = symbol__annotation(sym); |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 76 | struct source_line *src_line = notes->src->lines; |
Arnaldo Carvalho de Melo | 2f525d0 | 2011-02-04 13:43:24 -0200 | [diff] [blame] | 77 | struct sym_hist *h = annotation__histogram(notes, evidx); |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 78 | s64 offset = self->offset; |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 79 | struct objdump_line *next; |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 80 | |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 81 | next = objdump__get_next_ip_line(¬es->src->source, self); |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 82 | while (offset < (s64)len && |
| 83 | (next == NULL || offset < next->offset)) { |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 84 | if (src_line) { |
| 85 | percent += src_line[offset].percent; |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 86 | } else |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 87 | hits += h->addr[offset]; |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 88 | |
| 89 | ++offset; |
| 90 | } |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 91 | /* |
| 92 | * If the percentage wasn't already calculated in |
| 93 | * symbol__get_source_line, do it now: |
| 94 | */ |
| 95 | if (src_line == NULL && h->sum) |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 96 | percent = 100.0 * hits / h->sum; |
| 97 | } |
| 98 | |
| 99 | return percent; |
| 100 | } |
| 101 | |
| 102 | static void objdump__insert_line(struct rb_root *self, |
| 103 | struct objdump_line_rb_node *line) |
| 104 | { |
| 105 | struct rb_node **p = &self->rb_node; |
| 106 | struct rb_node *parent = NULL; |
| 107 | struct objdump_line_rb_node *l; |
| 108 | |
| 109 | while (*p != NULL) { |
| 110 | parent = *p; |
| 111 | l = rb_entry(parent, struct objdump_line_rb_node, rb_node); |
| 112 | if (line->percent < l->percent) |
| 113 | p = &(*p)->rb_left; |
| 114 | else |
| 115 | p = &(*p)->rb_right; |
| 116 | } |
| 117 | rb_link_node(&line->rb_node, parent, p); |
| 118 | rb_insert_color(&line->rb_node, self); |
| 119 | } |
| 120 | |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 121 | static void annotate_browser__set_top(struct annotate_browser *self, |
| 122 | struct rb_node *nd) |
| 123 | { |
| 124 | struct objdump_line_rb_node *rbpos; |
| 125 | struct objdump_line *pos; |
| 126 | unsigned back; |
| 127 | |
| 128 | ui_browser__refresh_dimensions(&self->b); |
| 129 | back = self->b.height / 2; |
| 130 | rbpos = rb_entry(nd, struct objdump_line_rb_node, rb_node); |
| 131 | pos = ((struct objdump_line *)rbpos) - 1; |
| 132 | self->b.top_idx = self->b.index = rbpos->idx; |
| 133 | |
| 134 | while (self->b.top_idx != 0 && back != 0) { |
| 135 | pos = list_entry(pos->node.prev, struct objdump_line, node); |
| 136 | |
| 137 | --self->b.top_idx; |
| 138 | --back; |
| 139 | } |
| 140 | |
| 141 | self->b.top = pos; |
| 142 | self->curr_hot = nd; |
| 143 | } |
| 144 | |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 145 | static void annotate_browser__calc_percent(struct annotate_browser *browser, |
| 146 | int evidx) |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 147 | { |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame^] | 148 | struct map_symbol *ms = browser->b.priv; |
| 149 | struct symbol *sym = ms->sym; |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 150 | struct annotation *notes = symbol__annotation(sym); |
| 151 | struct objdump_line *pos; |
| 152 | |
| 153 | browser->entries = RB_ROOT; |
| 154 | |
| 155 | pthread_mutex_lock(¬es->lock); |
| 156 | |
| 157 | list_for_each_entry(pos, ¬es->src->source, node) { |
| 158 | struct objdump_line_rb_node *rbpos = objdump_line__rb(pos); |
| 159 | rbpos->percent = objdump_line__calc_percent(pos, sym, evidx); |
| 160 | if (rbpos->percent < 0.01) { |
| 161 | RB_CLEAR_NODE(&rbpos->rb_node); |
| 162 | continue; |
| 163 | } |
| 164 | objdump__insert_line(&browser->entries, rbpos); |
| 165 | } |
| 166 | pthread_mutex_unlock(¬es->lock); |
| 167 | |
| 168 | browser->curr_hot = rb_last(&browser->entries); |
| 169 | } |
| 170 | |
| 171 | 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^] | 172 | int nr_events, void(*timer)(void *arg), |
| 173 | void *arg, int delay_secs) |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 174 | { |
| 175 | struct rb_node *nd = NULL; |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame^] | 176 | struct map_symbol *ms = self->b.priv; |
| 177 | struct symbol *sym = ms->sym; |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 178 | /* |
| 179 | * RIGHT To allow builtin-annotate to cycle thru multiple symbols by |
| 180 | * examining the exit key for this function. |
| 181 | */ |
| 182 | int exit_keys[] = { 'H', NEWT_KEY_TAB, NEWT_KEY_UNTAB, |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame^] | 183 | NEWT_KEY_RIGHT, NEWT_KEY_ENTER, 0 }; |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 184 | int key; |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 185 | |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 186 | if (ui_browser__show(&self->b, sym->name, |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 187 | "<-, -> or ESC: exit, TAB/shift+TAB: " |
| 188 | "cycle hottest lines, H: Hottest") < 0) |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 189 | return -1; |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 190 | |
| 191 | ui_browser__add_exit_keys(&self->b, exit_keys); |
| 192 | annotate_browser__calc_percent(self, evidx); |
| 193 | |
| 194 | if (self->curr_hot) |
| 195 | annotate_browser__set_top(self, self->curr_hot); |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 196 | |
| 197 | nd = self->curr_hot; |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 198 | |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 199 | if (delay_secs != 0) |
| 200 | newtFormSetTimer(self->b.form, delay_secs * 1000); |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 201 | |
| 202 | while (1) { |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 203 | key = ui_browser__run(&self->b); |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 204 | |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 205 | if (delay_secs != 0) { |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 206 | annotate_browser__calc_percent(self, evidx); |
| 207 | /* |
| 208 | * Current line focus got out of the list of most active |
| 209 | * lines, NULL it so that if TAB|UNTAB is pressed, we |
| 210 | * move to curr_hot (current hottest line). |
| 211 | */ |
| 212 | if (nd != NULL && RB_EMPTY_NODE(nd)) |
| 213 | nd = NULL; |
| 214 | } |
| 215 | |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 216 | switch (key) { |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 217 | case -1: |
| 218 | /* |
| 219 | * FIXME we need to check if it was |
| 220 | * es.reason == NEWT_EXIT_TIMER |
| 221 | */ |
Arnaldo Carvalho de Melo | 81cce8d | 2011-10-05 19:11:32 -0300 | [diff] [blame] | 222 | if (timer != NULL) |
| 223 | timer(arg); |
| 224 | |
| 225 | if (delay_secs != 0) |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 226 | symbol__annotate_decay_histogram(sym, evidx); |
| 227 | continue; |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 228 | case NEWT_KEY_TAB: |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 229 | if (nd != NULL) { |
| 230 | nd = rb_prev(nd); |
| 231 | if (nd == NULL) |
| 232 | nd = rb_last(&self->entries); |
| 233 | } else |
| 234 | nd = self->curr_hot; |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 235 | break; |
| 236 | case NEWT_KEY_UNTAB: |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 237 | if (nd != NULL) |
| 238 | nd = rb_next(nd); |
| 239 | if (nd == NULL) |
| 240 | nd = rb_first(&self->entries); |
| 241 | else |
| 242 | nd = self->curr_hot; |
| 243 | break; |
| 244 | case 'H': |
| 245 | nd = self->curr_hot; |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 246 | break; |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame^] | 247 | case NEWT_KEY_ENTER: |
| 248 | if (self->selection != NULL) { |
| 249 | char *s = strstr(self->selection->line, "callq "); |
| 250 | struct annotation *notes; |
| 251 | struct symbol *target; |
| 252 | u64 ip; |
| 253 | |
| 254 | if (s == NULL) |
| 255 | continue; |
| 256 | |
| 257 | s = strchr(s, ' '); |
| 258 | if (s++ == NULL) |
| 259 | continue; |
| 260 | |
| 261 | ip = strtoull(s, NULL, 16); |
| 262 | ip = ms->map->map_ip(ms->map, ip); |
| 263 | target = map__find_symbol(ms->map, ip, NULL); |
| 264 | if (target == NULL) |
| 265 | continue; |
| 266 | |
| 267 | notes = symbol__annotation(target); |
| 268 | pthread_mutex_lock(¬es->lock); |
| 269 | |
| 270 | if (notes->src == NULL && |
| 271 | symbol__alloc_hist(target, nr_events) < 0) { |
| 272 | pthread_mutex_unlock(¬es->lock); |
| 273 | ui__warning("Not enough memory for annotating '%s' symbol!\n", |
| 274 | target->name); |
| 275 | continue; |
| 276 | } |
| 277 | |
| 278 | pthread_mutex_unlock(¬es->lock); |
| 279 | symbol__tui_annotate(target, ms->map, evidx, nr_events, |
| 280 | timer, arg, delay_secs); |
| 281 | } |
| 282 | break; |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 283 | default: |
| 284 | goto out; |
| 285 | } |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 286 | |
| 287 | if (nd != NULL) |
| 288 | annotate_browser__set_top(self, nd); |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 289 | } |
| 290 | out: |
Arnaldo Carvalho de Melo | 59e8fe3 | 2010-08-10 15:44:20 -0300 | [diff] [blame] | 291 | ui_browser__hide(&self->b); |
Arnaldo Carvalho de Melo | b50e003 | 2010-08-11 10:07:43 -0300 | [diff] [blame] | 292 | return key; |
Arnaldo Carvalho de Melo | f1e9214 | 2010-08-10 15:14:53 -0300 | [diff] [blame] | 293 | } |
| 294 | |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame^] | 295 | 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] | 296 | void(*timer)(void *arg), void *arg, int delay_secs) |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 297 | { |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame^] | 298 | 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] | 299 | timer, arg, delay_secs); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 300 | } |
| 301 | |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 302 | 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^] | 303 | int nr_events, void(*timer)(void *arg), void *arg, |
| 304 | int delay_secs) |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 305 | { |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 306 | struct objdump_line *pos, *n; |
Lin Ming | db9a9cbc | 2011-04-08 14:31:26 +0800 | [diff] [blame] | 307 | struct annotation *notes; |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame^] | 308 | struct map_symbol ms = { |
| 309 | .map = map, |
| 310 | .sym = sym, |
| 311 | }; |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 312 | struct annotate_browser browser = { |
| 313 | .b = { |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 314 | .refresh = ui_browser__list_head_refresh, |
| 315 | .seek = ui_browser__list_head_seek, |
| 316 | .write = annotate_browser__write, |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame^] | 317 | .priv = &ms, |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 318 | }, |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 319 | }; |
| 320 | int ret; |
| 321 | |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 322 | if (sym == NULL) |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 323 | return -1; |
| 324 | |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 325 | if (map->dso->annotate_warned) |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 326 | return -1; |
| 327 | |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 328 | 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] | 329 | ui__error_window(ui_helpline__last_msg); |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 330 | return -1; |
| 331 | } |
| 332 | |
| 333 | ui_helpline__push("Press <- or ESC to exit"); |
| 334 | |
Lin Ming | db9a9cbc | 2011-04-08 14:31:26 +0800 | [diff] [blame] | 335 | notes = symbol__annotation(sym); |
| 336 | |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 337 | list_for_each_entry(pos, ¬es->src->source, node) { |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 338 | struct objdump_line_rb_node *rbpos; |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 339 | size_t line_len = strlen(pos->line); |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 340 | |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 341 | if (browser.b.width < line_len) |
| 342 | browser.b.width = line_len; |
| 343 | rbpos = objdump_line__rb(pos); |
| 344 | rbpos->idx = browser.b.nr_entries++; |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 345 | } |
| 346 | |
Lin Ming | db9a9cbc | 2011-04-08 14:31:26 +0800 | [diff] [blame] | 347 | browser.b.entries = ¬es->src->source, |
Arnaldo Carvalho de Melo | 9222116 | 2010-08-09 15:30:40 -0300 | [diff] [blame] | 348 | browser.b.width += 18; /* Percentage */ |
Arnaldo Carvalho de Melo | 3495854 | 2011-10-05 19:35:54 -0300 | [diff] [blame^] | 349 | ret = annotate_browser__run(&browser, evidx, nr_events, |
| 350 | timer, arg, delay_secs); |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 351 | 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] | 352 | list_del(&pos->node); |
| 353 | objdump_line__free(pos); |
| 354 | } |
Arnaldo Carvalho de Melo | 211ef12 | 2010-08-10 14:54:09 -0300 | [diff] [blame] | 355 | return ret; |
| 356 | } |