diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-04-07 16:10:30 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-04-07 16:37:22 -0400 |
commit | d3d1f61acf62204bb7b2b4509329247bffaedd7c (patch) | |
tree | f7befbf4b661b4266a22e83ab1d7cd15095a7d1b /tools/perf/util/ui/browsers/annotate.c | |
parent | cc68628096b813010f30f69fcf7d1832d18fa767 (diff) |
perf annotate browser: string search: /?n
Using the same keystrokes as vim:
/ = search forward
n = search next forward/backwards
? = search backwards
Still needs to continue from start/end when not found, use HOME + / or
END + ? for now.
At some point we need a keybindings file to support ones favourite mode,
erm, like EMACS, etc.
Also we now need a 'h' window with all these keybindings.
Requested-by: Andi Kleen <andi@firstfloor.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-rv30xj2i258n0gwkzlu0c0bc@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/ui/browsers/annotate.c')
-rw-r--r-- | tools/perf/util/ui/browsers/annotate.c | 149 |
1 files changed, 148 insertions, 1 deletions
diff --git a/tools/perf/util/ui/browsers/annotate.c b/tools/perf/util/ui/browsers/annotate.c index 752d8d0e480c..c2cfeed3af19 100644 --- a/tools/perf/util/ui/browsers/annotate.c +++ b/tools/perf/util/ui/browsers/annotate.c | |||
@@ -21,6 +21,8 @@ struct annotate_browser { | |||
21 | int nr_entries; | 21 | int nr_entries; |
22 | bool hide_src_code; | 22 | bool hide_src_code; |
23 | bool use_offset; | 23 | bool use_offset; |
24 | bool searching_backwards; | ||
25 | char search_bf[128]; | ||
24 | }; | 26 | }; |
25 | 27 | ||
26 | struct objdump_line_rb_node { | 28 | struct objdump_line_rb_node { |
@@ -176,6 +178,7 @@ static void annotate_browser__set_top(struct annotate_browser *self, | |||
176 | } | 178 | } |
177 | 179 | ||
178 | self->b.top = pos; | 180 | self->b.top = pos; |
181 | self->b.navkeypressed = true; | ||
179 | } | 182 | } |
180 | 183 | ||
181 | static void annotate_browser__set_rb_top(struct annotate_browser *browser, | 184 | static void annotate_browser__set_rb_top(struct annotate_browser *browser, |
@@ -354,6 +357,132 @@ static bool annotate_browser__jump(struct annotate_browser *browser) | |||
354 | return true; | 357 | return true; |
355 | } | 358 | } |
356 | 359 | ||
360 | static struct objdump_line * | ||
361 | annotate_browser__find_string(struct annotate_browser *browser, | ||
362 | char *s, s64 *idx) | ||
363 | { | ||
364 | struct map_symbol *ms = browser->b.priv; | ||
365 | struct symbol *sym = ms->sym; | ||
366 | struct annotation *notes = symbol__annotation(sym); | ||
367 | struct objdump_line *pos = browser->selection; | ||
368 | |||
369 | *idx = browser->b.index; | ||
370 | list_for_each_entry_continue(pos, ¬es->src->source, node) { | ||
371 | if (objdump_line__filter(&browser->b, &pos->node)) | ||
372 | continue; | ||
373 | |||
374 | ++*idx; | ||
375 | |||
376 | if (pos->line && strstr(pos->line, s) != NULL) | ||
377 | return pos; | ||
378 | } | ||
379 | |||
380 | return NULL; | ||
381 | } | ||
382 | |||
383 | static bool __annotate_browser__search(struct annotate_browser *browser) | ||
384 | { | ||
385 | struct objdump_line *line; | ||
386 | s64 idx; | ||
387 | |||
388 | line = annotate_browser__find_string(browser, browser->search_bf, &idx); | ||
389 | if (line == NULL) { | ||
390 | ui_helpline__puts("String not found!"); | ||
391 | return false; | ||
392 | } | ||
393 | |||
394 | annotate_browser__set_top(browser, line, idx); | ||
395 | browser->searching_backwards = false; | ||
396 | return true; | ||
397 | } | ||
398 | |||
399 | static struct objdump_line * | ||
400 | annotate_browser__find_string_reverse(struct annotate_browser *browser, | ||
401 | char *s, s64 *idx) | ||
402 | { | ||
403 | struct map_symbol *ms = browser->b.priv; | ||
404 | struct symbol *sym = ms->sym; | ||
405 | struct annotation *notes = symbol__annotation(sym); | ||
406 | struct objdump_line *pos = browser->selection; | ||
407 | |||
408 | *idx = browser->b.index; | ||
409 | list_for_each_entry_continue_reverse(pos, ¬es->src->source, node) { | ||
410 | if (objdump_line__filter(&browser->b, &pos->node)) | ||
411 | continue; | ||
412 | |||
413 | --*idx; | ||
414 | |||
415 | if (pos->line && strstr(pos->line, s) != NULL) | ||
416 | return pos; | ||
417 | } | ||
418 | |||
419 | return NULL; | ||
420 | } | ||
421 | |||
422 | static bool __annotate_browser__search_reverse(struct annotate_browser *browser) | ||
423 | { | ||
424 | struct objdump_line *line; | ||
425 | s64 idx; | ||
426 | |||
427 | line = annotate_browser__find_string_reverse(browser, browser->search_bf, &idx); | ||
428 | if (line == NULL) { | ||
429 | ui_helpline__puts("String not found!"); | ||
430 | return false; | ||
431 | } | ||
432 | |||
433 | annotate_browser__set_top(browser, line, idx); | ||
434 | browser->searching_backwards = true; | ||
435 | return true; | ||
436 | } | ||
437 | |||
438 | static bool annotate_browser__search_window(struct annotate_browser *browser, | ||
439 | int delay_secs) | ||
440 | { | ||
441 | if (ui_browser__input_window("Search", "String: ", browser->search_bf, | ||
442 | "ENTER: OK, ESC: Cancel", | ||
443 | delay_secs * 2) != K_ENTER || | ||
444 | !*browser->search_bf) | ||
445 | return false; | ||
446 | |||
447 | return true; | ||
448 | } | ||
449 | |||
450 | static bool annotate_browser__search(struct annotate_browser *browser, int delay_secs) | ||
451 | { | ||
452 | if (annotate_browser__search_window(browser, delay_secs)) | ||
453 | return __annotate_browser__search(browser); | ||
454 | |||
455 | return false; | ||
456 | } | ||
457 | |||
458 | static bool annotate_browser__continue_search(struct annotate_browser *browser, | ||
459 | int delay_secs) | ||
460 | { | ||
461 | if (!*browser->search_bf) | ||
462 | return annotate_browser__search(browser, delay_secs); | ||
463 | |||
464 | return __annotate_browser__search(browser); | ||
465 | } | ||
466 | |||
467 | static bool annotate_browser__search_reverse(struct annotate_browser *browser, | ||
468 | int delay_secs) | ||
469 | { | ||
470 | if (annotate_browser__search_window(browser, delay_secs)) | ||
471 | return __annotate_browser__search_reverse(browser); | ||
472 | |||
473 | return false; | ||
474 | } | ||
475 | |||
476 | static | ||
477 | bool annotate_browser__continue_search_reverse(struct annotate_browser *browser, | ||
478 | int delay_secs) | ||
479 | { | ||
480 | if (!*browser->search_bf) | ||
481 | return annotate_browser__search_reverse(browser, delay_secs); | ||
482 | |||
483 | return __annotate_browser__search_reverse(browser); | ||
484 | } | ||
485 | |||
357 | static int annotate_browser__run(struct annotate_browser *self, int evidx, | 486 | static int annotate_browser__run(struct annotate_browser *self, int evidx, |
358 | void(*timer)(void *arg), | 487 | void(*timer)(void *arg), |
359 | void *arg, int delay_secs) | 488 | void *arg, int delay_secs) |
@@ -372,8 +501,10 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx, | |||
372 | 501 | ||
373 | annotate_browser__calc_percent(self, evidx); | 502 | annotate_browser__calc_percent(self, evidx); |
374 | 503 | ||
375 | if (self->curr_hot) | 504 | if (self->curr_hot) { |
376 | annotate_browser__set_rb_top(self, self->curr_hot); | 505 | annotate_browser__set_rb_top(self, self->curr_hot); |
506 | self->b.navkeypressed = false; | ||
507 | } | ||
377 | 508 | ||
378 | nd = self->curr_hot; | 509 | nd = self->curr_hot; |
379 | 510 | ||
@@ -428,6 +559,22 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx, | |||
428 | case 'o': | 559 | case 'o': |
429 | self->use_offset = !self->use_offset; | 560 | self->use_offset = !self->use_offset; |
430 | continue; | 561 | continue; |
562 | case '/': | ||
563 | if (annotate_browser__search(self, delay_secs)) { | ||
564 | show_help: | ||
565 | ui_helpline__puts(help); | ||
566 | } | ||
567 | continue; | ||
568 | case 'n': | ||
569 | if (self->searching_backwards ? | ||
570 | annotate_browser__continue_search_reverse(self, delay_secs) : | ||
571 | annotate_browser__continue_search(self, delay_secs)) | ||
572 | goto show_help; | ||
573 | continue; | ||
574 | case '?': | ||
575 | if (annotate_browser__search_reverse(self, delay_secs)) | ||
576 | goto show_help; | ||
577 | continue; | ||
431 | case K_ENTER: | 578 | case K_ENTER: |
432 | case K_RIGHT: | 579 | case K_RIGHT: |
433 | if (self->selection == NULL) | 580 | if (self->selection == NULL) |