aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/ui/browsers/annotate.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/ui/browsers/annotate.c')
-rw-r--r--tools/perf/util/ui/browsers/annotate.c69
1 files changed, 58 insertions, 11 deletions
diff --git a/tools/perf/util/ui/browsers/annotate.c b/tools/perf/util/ui/browsers/annotate.c
index 76c1d083aa94..77421bab8fdd 100644
--- a/tools/perf/util/ui/browsers/annotate.c
+++ b/tools/perf/util/ui/browsers/annotate.c
@@ -20,6 +20,7 @@ struct annotate_browser {
20 struct ui_browser b; 20 struct ui_browser b;
21 struct rb_root entries; 21 struct rb_root entries;
22 struct rb_node *curr_hot; 22 struct rb_node *curr_hot;
23 struct objdump_line *selection;
23}; 24};
24 25
25struct objdump_line_rb_node { 26struct objdump_line_rb_node {
@@ -36,6 +37,7 @@ struct objdump_line_rb_node *objdump_line__rb(struct objdump_line *self)
36 37
37static void annotate_browser__write(struct ui_browser *self, void *entry, int row) 38static void annotate_browser__write(struct ui_browser *self, void *entry, int row)
38{ 39{
40 struct annotate_browser *ab = container_of(self, struct annotate_browser, b);
39 struct objdump_line *ol = rb_entry(entry, struct objdump_line, node); 41 struct objdump_line *ol = rb_entry(entry, struct objdump_line, node);
40 bool current_entry = ui_browser__is_current_entry(self, row); 42 bool current_entry = ui_browser__is_current_entry(self, row);
41 int width = self->width; 43 int width = self->width;
@@ -58,6 +60,8 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro
58 60
59 if (!current_entry) 61 if (!current_entry)
60 ui_browser__set_color(self, HE_COLORSET_CODE); 62 ui_browser__set_color(self, HE_COLORSET_CODE);
63 else
64 ab->selection = ol;
61} 65}
62 66
63static double objdump_line__calc_percent(struct objdump_line *self, 67static double objdump_line__calc_percent(struct objdump_line *self,
@@ -141,7 +145,8 @@ static void annotate_browser__set_top(struct annotate_browser *self,
141static void annotate_browser__calc_percent(struct annotate_browser *browser, 145static void annotate_browser__calc_percent(struct annotate_browser *browser,
142 int evidx) 146 int evidx)
143{ 147{
144 struct symbol *sym = browser->b.priv; 148 struct map_symbol *ms = browser->b.priv;
149 struct symbol *sym = ms->sym;
145 struct annotation *notes = symbol__annotation(sym); 150 struct annotation *notes = symbol__annotation(sym);
146 struct objdump_line *pos; 151 struct objdump_line *pos;
147 152
@@ -164,17 +169,18 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
164} 169}
165 170
166static int annotate_browser__run(struct annotate_browser *self, int evidx, 171static int annotate_browser__run(struct annotate_browser *self, int evidx,
167 void(*timer)(void *arg) __used, void *arg __used, 172 int nr_events, void(*timer)(void *arg),
168 int delay_secs) 173 void *arg, int delay_secs)
169{ 174{
170 struct rb_node *nd = NULL; 175 struct rb_node *nd = NULL;
171 struct symbol *sym = self->b.priv; 176 struct map_symbol *ms = self->b.priv;
177 struct symbol *sym = ms->sym;
172 /* 178 /*
173 * RIGHT To allow builtin-annotate to cycle thru multiple symbols by 179 * RIGHT To allow builtin-annotate to cycle thru multiple symbols by
174 * examining the exit key for this function. 180 * examining the exit key for this function.
175 */ 181 */
176 int exit_keys[] = { 'H', NEWT_KEY_TAB, NEWT_KEY_UNTAB, 182 int exit_keys[] = { 'H', NEWT_KEY_TAB, NEWT_KEY_UNTAB,
177 NEWT_KEY_RIGHT, 0 }; 183 NEWT_KEY_RIGHT, NEWT_KEY_ENTER, 0 };
178 int key; 184 int key;
179 185
180 if (ui_browser__show(&self->b, sym->name, 186 if (ui_browser__show(&self->b, sym->name,
@@ -238,6 +244,42 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx,
238 case 'H': 244 case 'H':
239 nd = self->curr_hot; 245 nd = self->curr_hot;
240 break; 246 break;
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(&notes->lock);
269
270 if (notes->src == NULL &&
271 symbol__alloc_hist(target, nr_events) < 0) {
272 pthread_mutex_unlock(&notes->lock);
273 ui__warning("Not enough memory for annotating '%s' symbol!\n",
274 target->name);
275 continue;
276 }
277
278 pthread_mutex_unlock(&notes->lock);
279 symbol__tui_annotate(target, ms->map, evidx, nr_events,
280 timer, arg, delay_secs);
281 }
282 break;
241 default: 283 default:
242 goto out; 284 goto out;
243 } 285 }
@@ -250,25 +292,29 @@ out:
250 return key; 292 return key;
251} 293}
252 294
253int hist_entry__tui_annotate(struct hist_entry *he, int evidx, 295int hist_entry__tui_annotate(struct hist_entry *he, int evidx, int nr_events,
254 void(*timer)(void *arg), void *arg, int delay_secs) 296 void(*timer)(void *arg), void *arg, int delay_secs)
255{ 297{
256 return symbol__tui_annotate(he->ms.sym, he->ms.map, evidx, 298 return symbol__tui_annotate(he->ms.sym, he->ms.map, evidx, nr_events,
257 timer, arg, delay_secs); 299 timer, arg, delay_secs);
258} 300}
259 301
260int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx, 302int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
261 void(*timer)(void *arg), void *arg, 303 int nr_events, void(*timer)(void *arg), void *arg,
262 int delay_secs) 304 int delay_secs)
263{ 305{
264 struct objdump_line *pos, *n; 306 struct objdump_line *pos, *n;
265 struct annotation *notes; 307 struct annotation *notes;
308 struct map_symbol ms = {
309 .map = map,
310 .sym = sym,
311 };
266 struct annotate_browser browser = { 312 struct annotate_browser browser = {
267 .b = { 313 .b = {
268 .refresh = ui_browser__list_head_refresh, 314 .refresh = ui_browser__list_head_refresh,
269 .seek = ui_browser__list_head_seek, 315 .seek = ui_browser__list_head_seek,
270 .write = annotate_browser__write, 316 .write = annotate_browser__write,
271 .priv = sym, 317 .priv = &ms,
272 }, 318 },
273 }; 319 };
274 int ret; 320 int ret;
@@ -300,7 +346,8 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
300 346
301 browser.b.entries = &notes->src->source, 347 browser.b.entries = &notes->src->source,
302 browser.b.width += 18; /* Percentage */ 348 browser.b.width += 18; /* Percentage */
303 ret = annotate_browser__run(&browser, evidx, timer, arg, delay_secs); 349 ret = annotate_browser__run(&browser, evidx, nr_events,
350 timer, arg, delay_secs);
304 list_for_each_entry_safe(pos, n, &notes->src->source, node) { 351 list_for_each_entry_safe(pos, n, &notes->src->source, node) {
305 list_del(&pos->node); 352 list_del(&pos->node);
306 objdump_line__free(pos); 353 objdump_line__free(pos);