diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-03-16 15:57:47 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-03-21 11:53:43 -0400 |
commit | d9bd766584491dbb6f96c85a27562eb1289b2ca9 (patch) | |
tree | 3008a766c1fce1129b985ca89f19fa0c455e3e9c | |
parent | 91340c5184f316d687d4522b9aa41b56d58a49b0 (diff) |
perf annotate browser: Add 'P' hotkey to dump annotation to file
Just like we have in the histograms browser used as the main screen for
'perf top --tui' and 'perf report --tui', to print the current
annotation to a file with a named composed by the symbol name and the
".annotation" suffix.
Here is one example of pressing 'A' on 'perf top' to live annotate a
kernel function and then press 'P' to dump that annotation, the
resulting file:
# cat _raw_spin_lock_irqsave.annotation
_raw_spin_lock_irqsave() /proc/kcore
Event: cycles:ppp
7.14 nop
21.43 push %rbx
7.14 pushfq
pop %rax
nop
mov %rax,%rbx
cli
nop
xor %eax,%eax
mov $0x1,%edx
64.29 lock cmpxchg %edx,(%rdi)
test %eax,%eax
↓ jne 2b
mov %rbx,%rax
pop %rbx
← retq
2b: mov %eax,%esi
→ callq queued_spin_lock_slowpath
mov %rbx,%rax
pop %rbx
← retq
#
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-zzmnrwugb5vtk7bvg0rbx150@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/ui/browsers/annotate.c | 4 | ||||
-rw-r--r-- | tools/perf/util/annotate.c | 31 | ||||
-rw-r--r-- | tools/perf/util/annotate.h | 2 |
3 files changed, 37 insertions, 0 deletions
diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c index 916f237c1df8..3834b264ba41 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c | |||
@@ -661,6 +661,7 @@ static int annotate_browser__run(struct annotate_browser *browser, | |||
661 | "t Circulate percent, total period, samples view\n" | 661 | "t Circulate percent, total period, samples view\n" |
662 | "/ Search string\n" | 662 | "/ Search string\n" |
663 | "k Toggle line numbers\n" | 663 | "k Toggle line numbers\n" |
664 | "P Print to [symbol_name].annotation file.\n" | ||
664 | "r Run available scripts\n" | 665 | "r Run available scripts\n" |
665 | "? Search string backwards\n"); | 666 | "? Search string backwards\n"); |
666 | continue; | 667 | continue; |
@@ -737,6 +738,9 @@ show_sup_ins: | |||
737 | } | 738 | } |
738 | continue; | 739 | continue; |
739 | } | 740 | } |
741 | case 'P': | ||
742 | map_symbol__annotation_dump(ms, evsel); | ||
743 | continue; | ||
740 | case 't': | 744 | case 't': |
741 | if (notes->options->show_total_period) { | 745 | if (notes->options->show_total_period) { |
742 | notes->options->show_total_period = false; | 746 | notes->options->show_total_period = false; |
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 7a6a85f9fea6..a7111871440e 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c | |||
@@ -2037,6 +2037,37 @@ int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp) | |||
2037 | return 0; | 2037 | return 0; |
2038 | } | 2038 | } |
2039 | 2039 | ||
2040 | int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel) | ||
2041 | { | ||
2042 | const char *ev_name = perf_evsel__name(evsel); | ||
2043 | char buf[1024]; | ||
2044 | char *filename; | ||
2045 | int err = -1; | ||
2046 | FILE *fp; | ||
2047 | |||
2048 | if (asprintf(&filename, "%s.annotation", ms->sym->name) < 0) | ||
2049 | return -1; | ||
2050 | |||
2051 | fp = fopen(filename, "w"); | ||
2052 | if (fp == NULL) | ||
2053 | goto out_free_filename; | ||
2054 | |||
2055 | if (perf_evsel__is_group_event(evsel)) { | ||
2056 | perf_evsel__group_desc(evsel, buf, sizeof(buf)); | ||
2057 | ev_name = buf; | ||
2058 | } | ||
2059 | |||
2060 | fprintf(fp, "%s() %s\nEvent: %s\n\n", | ||
2061 | ms->sym->name, ms->map->dso->long_name, ev_name); | ||
2062 | symbol__annotate_fprintf2(ms->sym, fp); | ||
2063 | |||
2064 | fclose(fp); | ||
2065 | err = 0; | ||
2066 | out_free_filename: | ||
2067 | free(filename); | ||
2068 | return err; | ||
2069 | } | ||
2070 | |||
2040 | void symbol__annotate_zero_histogram(struct symbol *sym, int evidx) | 2071 | void symbol__annotate_zero_histogram(struct symbol *sym, int evidx) |
2041 | { | 2072 | { |
2042 | struct annotation *notes = symbol__annotation(sym); | 2073 | struct annotation *notes = symbol__annotation(sym); |
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 3faa58045b22..365e9df888cf 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h | |||
@@ -288,6 +288,8 @@ void symbol__annotate_zero_histogram(struct symbol *sym, int evidx); | |||
288 | void symbol__annotate_decay_histogram(struct symbol *sym, int evidx); | 288 | void symbol__annotate_decay_histogram(struct symbol *sym, int evidx); |
289 | void annotated_source__purge(struct annotated_source *as); | 289 | void annotated_source__purge(struct annotated_source *as); |
290 | 290 | ||
291 | int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel); | ||
292 | |||
291 | bool ui__has_annotation(void); | 293 | bool ui__has_annotation(void); |
292 | 294 | ||
293 | int symbol__tty_annotate(struct symbol *sym, struct map *map, | 295 | int symbol__tty_annotate(struct symbol *sym, struct map *map, |