perf annotate: allow 's' on source code lines
PATCH 1/1 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.
--- tools/perf/ui/browsers/annotate.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-)
tools/perf/ui/browsers/annotate.c +25 -3
@@ -343,6 +343,29 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser, browser->curr_hot =rb_last (&browser->entries); } +static struct annotation_line *annotate_browser__find_next_asm_line ( +struct annotate_browser *browser, +struct annotation_line *al) +{ +struct annotation_line *it = al; + +/* find next asm line */ +list_for_each_entry_continue (it, browser->b.top, node) { +if (it->idx_asm >=0 ) +return it; + } + +/* no asm line found forwards, try backwards */ + it = al; +list_for_each_entry_continue_reverse (it, browser->b.top, node) { +if (it->idx_asm >=0 ) +return it; + } + +/* There are no asm lines */ +return al; +} +static bool annotate_browser__toggle_source (struct annotate_browser *browser) {struct annotation *notes =browser__annotation (&browser->b);
@@ -363,9 +386,8 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser) browser->b.index = al->idx; }else {if (al->idx_asm <0 ) { -ui_helpline__puts ("Only available for assembly lines." ); - browser->b.seek (&browser->b, -offset,SEEK_CUR ); -return false; +/* move cursor to next asm line */ + al =annotate_browser__find_next_asm_line (browser, al); }if (al->idx_asm < offset)
Signature · 1 line
2.31.1
Ian Rogers
reviewerQuoted 32 lines · Riccardo Mancini
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.Signed-off-by Riccardo Mancini <[email protected]>--- tools/perf/ui/browsers/annotate.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-)tools/perf/ui/browsers/annotate.c +11
-0@@ -343,6 +343,29 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser, browser->curr_hot =rb_last (&browser->entries); } +static struct annotation_line *annotate_browser__find_next_asm_line ( +struct annotate_browser *browser, +struct annotation_line *al) +{ +struct annotation_line *it = al; + +/* find next asm line */ +list_for_each_entry_continue (it, browser->b.top, node) { +if (it->idx_asm >=0 ) +return it; + }
tools/perf/ui/browsers/annotate.c static void annotate_browser__calc_percent(struct annotate_browser *browser, · line 366
Quoted 10 lines
tools/perf/ui/browsers/annotate.c +10
-0+ +/* no asm line found forwards, try backwards */ + it = al; +list_for_each_entry_continue_reverse (it, browser->b.top, node) { +if (it->idx_asm >=0 ) +return it; + } + +/* There are no asm lines */ +return al;
Does this error case need handling in the caller?
Thanks,
Ian
Quoted 20 lines
tools/perf/ui/browsers/annotate.c +4
-4+} +static bool annotate_browser__toggle_source (struct annotate_browser *browser) {struct annotation *notes =browser__annotation (&browser->b);@@ -363,9 +386,8 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser) browser->b.index = al->idx; }else {if (al->idx_asm <0 ) { -ui_helpline__puts ("Only available for assembly lines." ); - browser->b.seek (&browser->b, -offset,SEEK_CUR ); -return false; +/* move cursor to next asm line */ + al =annotate_browser__find_next_asm_line (browser, al); }if (al->idx_asm < offset) --2.31.1
Hi,
thank you for your comment.
Quoted 39 lines · Ian Rogers
Quoted 38 lines · Riccardo Mancini
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.Signed-off-by Riccardo Mancini <[email protected]>---
tools/perf/ui/browsers/annotate.c | 28 +++++++++++++++++++++++++---1 file changed, 25 insertions(+), 3 deletions(-)tools/perf/ui/browsers/annotate.c +15
-0@@ -343,6 +343,29 @@ static void annotate_browser__calc_percent(structannotate_browser *browser, browser->curr_hot = rb_last(&browser->entries); } +static struct annotation_line *annotate_browser__find_next_asm_line ( + struct annotate_browser *browser, + struct annotation_line *al) +{ + struct annotation_line *it = al; + + /* find next asm line */ + list_for_each_entry_continue(it, browser->b.top, node) { + if (it->idx_asm >= 0) + return it; + } + + /* no asm line found forwards, try backwards */ + it = al; + list_for_each_entry_continue_reverse(it, browser->b.top, node) {
Quoted 8 lines
tools/perf/ui/browsers/annotate.c static void annotate_browser__calc_percent(struct annotate_browser *browser, · line 366
Quoted 6 lines
tools/perf/ui/browsers/annotate.c +6
-0+ if (it->idx_asm >= 0) + return it; + } + + /* There are no asm lines */ + return al;Does this error case need handling in the caller?
Agreed.
I believe this should never happen, but in case it happens it will cause problems.
I'll change it to return NULL and handle it in the caller.
Thanks,
Riccardo
Quoted 28 lines
Thanks,
IanQuoted 24 lines
tools/perf/ui/browsers/annotate.c +2
-0+} +static bool
annotate_browser__toggle_source(struct annotate_browser *browser)
{
struct annotation *notes =browser__annotation(&browser->b);tools/perf/ui/browsers/annotate.c +2
-3@@ -363,9 +386,8 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser) browser->b.index = al->idx; } else { if (al->idx_asm < 0) { - ui_helpline__puts("Only available for assembly lines."); - browser->b.seek(&browser->b, -offset, SEEK_CUR); - return false; + /* move cursor to next asm line */ + al = annotate_browser__find_next_asm_line(browser, al);}
if (
al->idx_asm< offset)
--
2.31.1