Skip to content

Commit d3d1f61

Browse files
committed
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 <[email protected]> Cc: Andi Kleen <[email protected]> Cc: David Ahern <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Mike Galbraith <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent cc68628 commit d3d1f61

File tree

1 file changed

+148
-1
lines changed

1 file changed

+148
-1
lines changed

tools/perf/util/ui/browsers/annotate.c

Lines changed: 148 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ struct annotate_browser {
2121
int nr_entries;
2222
bool hide_src_code;
2323
bool use_offset;
24+
bool searching_backwards;
25+
char search_bf[128];
2426
};
2527

2628
struct objdump_line_rb_node {
@@ -176,6 +178,7 @@ static void annotate_browser__set_top(struct annotate_browser *self,
176178
}
177179

178180
self->b.top = pos;
181+
self->b.navkeypressed = true;
179182
}
180183

181184
static void annotate_browser__set_rb_top(struct annotate_browser *browser,
@@ -354,6 +357,132 @@ static bool annotate_browser__jump(struct annotate_browser *browser)
354357
return true;
355358
}
356359

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, &notes->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, &notes->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+
357486
static int annotate_browser__run(struct annotate_browser *self, int evidx,
358487
void(*timer)(void *arg),
359488
void *arg, int delay_secs)
@@ -372,8 +501,10 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx,
372501

373502
annotate_browser__calc_percent(self, evidx);
374503

375-
if (self->curr_hot)
504+
if (self->curr_hot) {
376505
annotate_browser__set_rb_top(self, self->curr_hot);
506+
self->b.navkeypressed = false;
507+
}
377508

378509
nd = self->curr_hot;
379510

@@ -428,6 +559,22 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx,
428559
case 'o':
429560
self->use_offset = !self->use_offset;
430561
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;
431578
case K_ENTER:
432579
case K_RIGHT:
433580
if (self->selection == NULL)

0 commit comments

Comments
 (0)