perf annotate: Toggle full address <-> offset display
authorNamhyung Kim <namhyung@kernel.org>
Fri, 23 Sep 2022 17:31:42 +0000 (10:31 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 4 Oct 2022 11:55:22 +0000 (08:55 -0300)
Handle 'f' key to toggle the display offset and full address.  Obviously
it only works when users set to see disassembler output ('o' key).  It'd
be useful when users want to see the full virtual address in the TUI
annotate browser.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20220923173142.805896-5-namhyung@kernel.org
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 9bc1076374ffd454b4989c7fa0cf7525e365d08c..725662e21b23e50433105a26e10ae2a21ea5316c 100644 (file)
@@ -805,7 +805,8 @@ static int annotate_browser__run(struct annotate_browser *browser,
                "r             Run available scripts\n"
                "p             Toggle percent type [local/global]\n"
                "b             Toggle percent base [period/hits]\n"
-               "?             Search string backwards\n");
+               "?             Search string backwards\n"
+               "f             Toggle showing offsets to full address\n");
                        continue;
                case 'r':
                        script_browse(NULL, NULL);
@@ -912,6 +913,9 @@ show_sup_ins:
                        hists__scnprintf_title(hists, title, sizeof(title));
                        annotate_browser__show(&browser->b, title, help);
                        continue;
+               case 'f':
+                       annotation__toggle_full_addr(notes, ms);
+                       continue;
                case K_LEFT:
                case K_ESC:
                case 'q':
index 5bc63c9e0324d5fd1b586833b5baf752504cb013..db475e44f42fae8d87e4e18b0f8afefb0c383526 100644 (file)
@@ -2239,7 +2239,10 @@ int symbol__annotate(struct map_symbol *ms, struct evsel *evsel,
        }
 
        args.ms = *ms;
-       notes->start = map__rip_2objdump(ms->map, sym->start);
+       if (notes->options && notes->options->full_addr)
+               notes->start = map__objdump_2mem(ms->map, ms->sym->start);
+       else
+               notes->start = map__rip_2objdump(ms->map, ms->sym->start);
 
        return symbol__disassemble(sym, &args);
 }
@@ -2762,6 +2765,8 @@ void annotation__update_column_widths(struct annotation *notes)
 {
        if (notes->options->use_offset)
                notes->widths.target = notes->widths.min_addr;
+       else if (notes->options->full_addr)
+               notes->widths.target = BITS_PER_LONG / 4;
        else
                notes->widths.target = notes->widths.max_addr;
 
@@ -2771,6 +2776,18 @@ void annotation__update_column_widths(struct annotation *notes)
                notes->widths.addr += notes->widths.jumps + 1;
 }
 
+void annotation__toggle_full_addr(struct annotation *notes, struct map_symbol *ms)
+{
+       notes->options->full_addr = !notes->options->full_addr;
+
+       if (notes->options->full_addr)
+               notes->start = map__objdump_2mem(ms->map, ms->sym->start);
+       else
+               notes->start = map__rip_2objdump(ms->map, ms->sym->start);
+
+       annotation__update_column_widths(notes);
+}
+
 static void annotation__calc_lines(struct annotation *notes, struct map *map,
                                   struct rb_root *root,
                                   struct annotation_options *opts)
index 3cbd883e4d7ace4e81939541f59a1e7c542aa757..8934072c39e6beefffff0c30048b3bf9962c7d78 100644 (file)
@@ -88,7 +88,8 @@ struct annotation_options {
             show_nr_jumps,
             show_minmax_cycle,
             show_asm_raw,
-            annotate_src;
+            annotate_src,
+            full_addr;
        u8   offset_level;
        int  min_pcnt;
        int  max_lines;
@@ -325,6 +326,7 @@ void annotation__compute_ipc(struct annotation *notes, size_t size);
 void annotation__mark_jump_targets(struct annotation *notes, struct symbol *sym);
 void annotation__update_column_widths(struct annotation *notes);
 void annotation__init_column_widths(struct annotation *notes, struct symbol *sym);
+void annotation__toggle_full_addr(struct annotation *notes, struct map_symbol *ms);
 
 static inline struct sym_hist *annotated_source__histogram(struct annotated_source *src, int idx)
 {