perf annotate: allow 's' on source code lines
PATCH v2 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.
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.
--- tools/perf/ui/browsers/annotate.c | 32 ++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-)
tools/perf/ui/browsers/annotate.c +29 -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 NULL ; +} +static bool annotate_browser__toggle_source (struct annotate_browser *browser) {struct annotation *notes =browser__annotation (&browser->b);
@@ -363,9 +386,12 @@ 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) { + browser->b.seek (&browser->b, -offset,SEEK_CUR ); +return false; + } }if (al->idx_asm < offset)
Signature · 1 line
2.31.1
Quoted 8 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.
Quoted 6 lines
Changes in v2:
- handle case of no asm line found inannotate_browser__find_next_asm_lineby returning NULL and handling error in caller.Signed-off-by Riccardo Mancini <[email protected]>
Quoted 39 lines
--- tools/perf/ui/browsers/annotate.c | 32 ++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-)tools/perf/ui/browsers/annotate.c +23
-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; + } + +/* 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 NULL ; +} +static bool annotate_browser__toggle_source (struct annotate_browser *browser) {struct annotation *notes =browser__annotation (&browser->b);
tools/perf/ui/browsers/annotate.c static bool annotate_browser__toggle_source(struct annotate_browser *browser) · line 389
Quoted 7 lines
tools/perf/ui/browsers/annotate.c +1
-3@@ -363,9 +386,12 @@ 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 */
comment nit, perhaps prefer "closest" rather than "next" due to searching backward.
Thanks,
Ian
Quoted 11 lines
tools/perf/ui/browsers/annotate.c +5
-1+ al =annotate_browser__find_next_asm_line (browser, al); +if (!al) { + browser->b.seek (&browser->b, -offset,SEEK_CUR ); +return false; + } }if (al->idx_asm < offset) --2.31.1
Hi Ian,
Quoted 64 lines · Ian Rogers
Quoted 8 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.Quoted 6 lines
Changes in v2:
- handle case of no asm line found inannotate_browser__find_next_asm_lineby returning NULL and handling error in caller.Signed-off-by Riccardo Mancini <[email protected]>Acked-by Ian Rogers <[email protected]>Quoted 46 lines
---
tools/perf/ui/browsers/annotate.c | 32 ++++++++++++++++++++++++++++---1 file changed, 29 insertions(+), 3 deletions(-)tools/perf/ui/browsers/annotate.c +23
-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) { + if (it->idx_asm >= 0) + return it; + } + + /* There are no asm lines */ + return NULL; +} +static bool
annotate_browser__toggle_source(struct annotate_browser *browser)
{
struct annotation *notes =browser__annotation(&browser->b);tools/perf/ui/browsers/annotate.c +0
-0@@ -363,9 +386,12 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser) browser->b.index = al->idx; } else { if (al->idx_asm < 0) {
Quoted 8 lines
tools/perf/ui/browsers/annotate.c static bool annotate_browser__toggle_source(struct annotate_browser *browser) · line 389
Quoted 5 lines
tools/perf/ui/browsers/annotate.c +1
-3- ui_helpline__puts("Only available for assembly lines."); - browser->b.seek(&browser->b, -offset, SEEK_CUR); - return false; + /* move cursor to next asm line */comment nit, perhaps prefer "closest" rather than "next" due to searching backward.
The backward search is just a fallback in case the forward one finds no asm line, which I believe is unlikely. Maybe it's also impossible, but I don't really know how those lines are generated, so I put a fallback in place. Furthermore, "closest" would imply that a previous asm line could be chosen over a subsequent one if closer, even if the latter is present.
Thanks,
Riccardo
Quoted 17 lines
Thanks,
IanQuoted 13 lines
tools/perf/ui/browsers/annotate.c +3
-0+ al = annotate_browser__find_next_asm_line(browser, al); + if (!al) { + browser->b.seek(&browser->b, -offset,
SEEK_CUR);
+ return false;
+ }
}if (
al->idx_asm< offset)
--
2.31.1
Quoted 77 lines · Riccardo Mancini
Hi Ian,
Quoted 64 lines · Ian Rogers
Quoted 8 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.Quoted 6 lines
Changes in v2:
- handle case of no asm line found inannotate_browser__find_next_asm_lineby returning NULL and handling error in caller.Signed-off-by Riccardo Mancini <[email protected]>Acked-by Ian Rogers <[email protected]>Quoted 46 lines
--- tools/perf/ui/browsers/annotate.c | 32 ++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-)tools/perf/ui/browsers/annotate.c +23
-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; + } + +/* 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 NULL ; +} +static bool annotate_browser__toggle_source (struct annotate_browser *browser){ struct annotation *notes = browser__annotation(&browser->b);tools/perf/ui/browsers/annotate.c +0
-0@@ -363,9 +386,12 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser) browser->b.index = al->idx; }else {if (al->idx_asm <0 ) {Quoted 8 lines
tools/perf/ui/browsers/annotate.c static bool annotate_browser__toggle_source(struct annotate_browser *browser) · line 389
Quoted 5 lines
tools/perf/ui/browsers/annotate.c +1
-3- ui_helpline__puts("Only available for assembly lines."); - browser->b.seek (&browser->b, -offset,SEEK_CUR ); -return false; +/* move cursor to next asm line */ comment nit, perhaps prefer "closest" rather than "next" due to searching backward.
Quoted 8 lines
The backward search is just a fallback in case the forward one finds no asm line, which I believe is unlikely. Maybe it's also impossible, but I don't really know how those lines are generated, so I put a fallback in place. Furthermore, "closest" would imply that a previous asm line could be chosen over a subsequent one if closer, even if the latter is present.
Thanks,
Riccardo
Agreed, thanks for thinking about this.
Quoted 19 lines
Quoted 17 lines
Thanks,
IanQuoted 13 lines
tools/perf/ui/browsers/annotate.c +3
-0+ al =annotate_browser__find_next_asm_line (browser, al); +if (!al) { + browser->b.seek(&browser->b, -offset,
SEEK_CUR);tools/perf/ui/browsers/annotate.c +2
-1+return false; + } }if (al->idx_asm < offset) --2.31.1
Em Tue, Jun 29, 2021 at 08:00:31AM -0700, Ian Rogers escreveu:
Quoted 12 lines · Riccardo Mancini
Quoted 11 lines · Ian Rogers
Quoted 3 lines · Riccardo Mancini
comment nit, perhaps prefer "closest" rather than "next" due to searching backward.
The backward search is just a fallback in case the forward one finds no asm line, which I believe is unlikely. Maybe it's also impossible, but I don't really know how those lines are generated, so I put a fallback in place. Furthermore, "closest" would imply that a previous asm line could be chosen over a subsequent one if closer, even if the latter is present.
Quoted 6 lines
Quoted 2 lines
Thanks,
RiccardoAgreed, thanks for thinking about this.
Acked-by Ian Rogers <[email protected]>
Thanks, applied.
- Arnaldo