Skip to content

Commit 6de249d

Browse files
Manciukicacmel
authored andcommitted
perf annotate: Allow 's' on source code lines
In perf annotate, when 's' is pressed on a line containing source code, it shows the message "Only available for assembly lines". This patch gets rid of the error, moving the cursr to the next available asm line (or the closest previous one if no asm line is found moving forwards), before hiding source code lines. Changes in v2: - handle case of no asm line found in annotate_browser__find_next_asm_line by returning NULL and handling error in caller. Signed-off-by: Riccardo Mancini <rickyman7@gmail.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Acked-by: Ian Rogers <irogers@google.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Martin Liška <mliska@suse.cz> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lore.kernel.org/lkml/20210624223423.189550-1-rickyman7@gmail.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent ec4c00f commit 6de249d

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

tools/perf/ui/browsers/annotate.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,29 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
343343
browser->curr_hot = rb_last(&browser->entries);
344344
}
345345

346+
static struct annotation_line *annotate_browser__find_next_asm_line(
347+
struct annotate_browser *browser,
348+
struct annotation_line *al)
349+
{
350+
struct annotation_line *it = al;
351+
352+
/* find next asm line */
353+
list_for_each_entry_continue(it, browser->b.top, node) {
354+
if (it->idx_asm >= 0)
355+
return it;
356+
}
357+
358+
/* no asm line found forwards, try backwards */
359+
it = al;
360+
list_for_each_entry_continue_reverse(it, browser->b.top, node) {
361+
if (it->idx_asm >= 0)
362+
return it;
363+
}
364+
365+
/* There are no asm lines */
366+
return NULL;
367+
}
368+
346369
static bool annotate_browser__toggle_source(struct annotate_browser *browser)
347370
{
348371
struct annotation *notes = browser__annotation(&browser->b);
@@ -363,9 +386,12 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser)
363386
browser->b.index = al->idx;
364387
} else {
365388
if (al->idx_asm < 0) {
366-
ui_helpline__puts("Only available for assembly lines.");
367-
browser->b.seek(&browser->b, -offset, SEEK_CUR);
368-
return false;
389+
/* move cursor to next asm line */
390+
al = annotate_browser__find_next_asm_line(browser, al);
391+
if (!al) {
392+
browser->b.seek(&browser->b, -offset, SEEK_CUR);
393+
return false;
394+
}
369395
}
370396

371397
if (al->idx_asm < offset)

0 commit comments

Comments
 (0)