perf annotate: Show full source location with 'l' hotkey
authorMartin Liska <mliska@suse.cz>
Mon, 15 Feb 2021 11:34:46 +0000 (12:34 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Sat, 6 Mar 2021 19:42:31 +0000 (16:42 -0300)
Right now, when Line numbers are displayed, one can't easily find a
source file that the line corresponds to.

When a source line is selected and 'l' is pressed, full source file
location is displayed in perf UI footer line. The hotkey works only for
source code lines.

Signed-off-by: Martin Liška <mliska@suse.cz>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: http://lore.kernel.org/lkml/25a6384f-d862-5dda-4fec-8f0555599c75@suse.cz
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/ui/browsers/annotate.c
tools/perf/util/annotate.c
tools/perf/util/annotate.h

index 35b82caf8090ec3cef1817fff976a1e041a157e3..9f75d767b6da4f2eb3b5f5c8f213cbdc999f31f2 100644 (file)
@@ -381,6 +381,25 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser)
        return true;
 }
 
+#define SYM_TITLE_MAX_SIZE (PATH_MAX + 64)
+
+static void annotate_browser__show_full_location(struct ui_browser *browser)
+{
+       struct annotate_browser *ab = container_of(browser, struct annotate_browser, b);
+       struct disasm_line *cursor = disasm_line(ab->selection);
+       struct annotation_line *al = &cursor->al;
+
+       if (al->offset != -1)
+               ui_helpline__puts("Only available for source code lines.");
+       else if (al->fileloc == NULL)
+               ui_helpline__puts("No source file location.");
+       else {
+               char help_line[SYM_TITLE_MAX_SIZE];
+               sprintf (help_line, "Source file location: %s", al->fileloc);
+               ui_helpline__puts(help_line);
+       }
+}
+
 static void ui_browser__init_asm_mode(struct ui_browser *browser)
 {
        struct annotation *notes = browser__annotation(browser);
@@ -388,8 +407,6 @@ static void ui_browser__init_asm_mode(struct ui_browser *browser)
        browser->nr_entries = notes->nr_asm_entries;
 }
 
-#define SYM_TITLE_MAX_SIZE (PATH_MAX + 64)
-
 static int sym_title(struct symbol *sym, struct map *map, char *title,
                     size_t sz, int percent_type)
 {
@@ -747,6 +764,7 @@ static int annotate_browser__run(struct annotate_browser *browser,
                "c             Show min/max cycle\n"
                "/             Search string\n"
                "k             Toggle line numbers\n"
+               "l             Show full source file location\n"
                "P             Print to [symbol_name].annotation file.\n"
                "r             Run available scripts\n"
                "p             Toggle percent type [local/global]\n"
@@ -760,6 +778,9 @@ static int annotate_browser__run(struct annotate_browser *browser,
                case 'k':
                        notes->options->show_linenr = !notes->options->show_linenr;
                        continue;
+               case 'l':
+                       annotate_browser__show_full_location (&browser->b);
+                       continue;
                case 'H':
                        nd = browser->curr_hot;
                        break;
index f54224586a3d81228737b63403a9e42c7c04f3cc..18eee25b4976bea800bc6266c4819da8dd014f2f 100644 (file)
@@ -1161,6 +1161,7 @@ struct annotate_args {
        s64                       offset;
        char                      *line;
        int                       line_nr;
+       char                      *fileloc;
 };
 
 static void annotation_line__init(struct annotation_line *al,
@@ -1170,6 +1171,7 @@ static void annotation_line__init(struct annotation_line *al,
        al->offset = args->offset;
        al->line = strdup(args->line);
        al->line_nr = args->line_nr;
+       al->fileloc = args->fileloc;
        al->data_nr = nr;
 }
 
@@ -1482,7 +1484,7 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
  */
 static int symbol__parse_objdump_line(struct symbol *sym,
                                      struct annotate_args *args,
-                                     char *parsed_line, int *line_nr)
+                                     char *parsed_line, int *line_nr, char **fileloc)
 {
        struct map *map = args->ms.map;
        struct annotation *notes = symbol__annotation(sym);
@@ -1494,6 +1496,7 @@ static int symbol__parse_objdump_line(struct symbol *sym,
        /* /filename:linenr ? Save line number and ignore. */
        if (regexec(&file_lineno, parsed_line, 2, match, 0) == 0) {
                *line_nr = atoi(parsed_line + match[1].rm_so);
+               *fileloc = strdup(parsed_line);
                return 0;
        }
 
@@ -1513,6 +1516,7 @@ static int symbol__parse_objdump_line(struct symbol *sym,
        args->offset  = offset;
        args->line    = parsed_line;
        args->line_nr = *line_nr;
+       args->fileloc = *fileloc;
        args->ms.sym  = sym;
 
        dl = disasm_line__new(args);
@@ -1807,6 +1811,7 @@ static int symbol__disassemble_bpf(struct symbol *sym,
                        args->offset = -1;
                        args->line = strdup(srcline);
                        args->line_nr = 0;
+                       args->fileloc = NULL;
                        args->ms.sym  = sym;
                        dl = disasm_line__new(args);
                        if (dl) {
@@ -1818,6 +1823,7 @@ static int symbol__disassemble_bpf(struct symbol *sym,
                args->offset = pc;
                args->line = buf + prev_buf_size;
                args->line_nr = 0;
+               args->fileloc = NULL;
                args->ms.sym  = sym;
                dl = disasm_line__new(args);
                if (dl)
@@ -1852,6 +1858,7 @@ symbol__disassemble_bpf_image(struct symbol *sym,
        args->offset = -1;
        args->line = strdup("to be implemented");
        args->line_nr = 0;
+       args->fileloc = NULL;
        dl = disasm_line__new(args);
        if (dl)
                annotation_line__add(&dl->al, &notes->src->source);
@@ -1933,6 +1940,7 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
        bool delete_extract = false;
        bool decomp = false;
        int lineno = 0;
+       char *fileloc = NULL;
        int nline;
        char *line;
        size_t line_len;
@@ -2060,7 +2068,7 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
                 * See disasm_line__new() and struct disasm_line::line_nr.
                 */
                if (symbol__parse_objdump_line(sym, args, expanded_line,
-                                              &lineno) < 0)
+                                              &lineno, &fileloc) < 0)
                        break;
                nline++;
        }
index 096cdaf21b01f20160654989b88983f81d14b1ee..3757416bcf46b01c469658bef04d26217d9b8fe7 100644 (file)
@@ -84,6 +84,7 @@ struct annotation_options {
             print_lines,
             full_path,
             show_linenr,
+            show_fileloc,
             show_nr_jumps,
             show_minmax_cycle,
             show_asm_raw,
@@ -136,6 +137,7 @@ struct annotation_line {
        s64                      offset;
        char                    *line;
        int                      line_nr;
+       char                    *fileloc;
        int                      jump_sources;
        float                    ipc;
        u64                      cycles;