diff options
author | Song Liu <songliubraving@fb.com> | 2019-03-19 12:54:54 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-03-21 10:27:04 -0400 |
commit | f8dfeae009effc0b6dac2741cf8d7cbb91edb982 (patch) | |
tree | 019a88a4d163c1b54a8bd48e1cf2ec08314d7b93 | |
parent | fc462ac75b36daaa61e9bda7fba66ed1b3a500b4 (diff) |
perf bpf: Show more BPF program info in print_bpf_prog_info()
This patch enables showing bpf program name, address, and size in the
header.
Before the patch:
perf report --header-only
...
# bpf_prog_info of id 9
# bpf_prog_info of id 10
# bpf_prog_info of id 13
After the patch:
# bpf_prog_info 9: bpf_prog_7be49e3934a125ba addr 0xffffffffa0024947 size 229
# bpf_prog_info 10: bpf_prog_2a142ef67aaad174 addr 0xffffffffa007c94d size 229
# bpf_prog_info 13: bpf_prog_47368425825d7384_task__task_newt addr 0xffffffffa0251137 size 369
Committer notes:
Fix the fallback definition when HAVE_LIBBPF_SUPPORT is not defined,
i.e. add the missing 'static inline' and add the __maybe_unused to the
args. Also add stdio.h since we now use FILE * in bpf-event.h.
Signed-off-by: Song Liu <songliubraving@fb.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stanislav Fomichev <sdf@google.com>
Link: http://lkml.kernel.org/r/20190319165454.1298742-3-songliubraving@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/bpf-event.c | 40 | ||||
-rw-r--r-- | tools/perf/util/bpf-event.h | 11 | ||||
-rw-r--r-- | tools/perf/util/header.c | 5 |
3 files changed, 53 insertions, 3 deletions
diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c index d5b041649f26..2a4a0da35632 100644 --- a/tools/perf/util/bpf-event.c +++ b/tools/perf/util/bpf-event.c | |||
@@ -438,3 +438,43 @@ int bpf_event__add_sb_event(struct perf_evlist **evlist, | |||
438 | 438 | ||
439 | return perf_evlist__add_sb_event(evlist, &attr, bpf_event__sb_cb, env); | 439 | return perf_evlist__add_sb_event(evlist, &attr, bpf_event__sb_cb, env); |
440 | } | 440 | } |
441 | |||
442 | void bpf_event__print_bpf_prog_info(struct bpf_prog_info *info, | ||
443 | struct perf_env *env, | ||
444 | FILE *fp) | ||
445 | { | ||
446 | __u32 *prog_lens = (__u32 *)(uintptr_t)(info->jited_func_lens); | ||
447 | __u64 *prog_addrs = (__u64 *)(uintptr_t)(info->jited_ksyms); | ||
448 | char name[KSYM_NAME_LEN]; | ||
449 | struct btf *btf = NULL; | ||
450 | u32 sub_prog_cnt, i; | ||
451 | |||
452 | sub_prog_cnt = info->nr_jited_ksyms; | ||
453 | if (sub_prog_cnt != info->nr_prog_tags || | ||
454 | sub_prog_cnt != info->nr_jited_func_lens) | ||
455 | return; | ||
456 | |||
457 | if (info->btf_id) { | ||
458 | struct btf_node *node; | ||
459 | |||
460 | node = perf_env__find_btf(env, info->btf_id); | ||
461 | if (node) | ||
462 | btf = btf__new((__u8 *)(node->data), | ||
463 | node->data_size); | ||
464 | } | ||
465 | |||
466 | if (sub_prog_cnt == 1) { | ||
467 | synthesize_bpf_prog_name(name, KSYM_NAME_LEN, info, btf, 0); | ||
468 | fprintf(fp, "# bpf_prog_info %u: %s addr 0x%llx size %u\n", | ||
469 | info->id, name, prog_addrs[0], prog_lens[0]); | ||
470 | return; | ||
471 | } | ||
472 | |||
473 | fprintf(fp, "# bpf_prog_info %u:\n", info->id); | ||
474 | for (i = 0; i < sub_prog_cnt; i++) { | ||
475 | synthesize_bpf_prog_name(name, KSYM_NAME_LEN, info, btf, i); | ||
476 | |||
477 | fprintf(fp, "# \tsub_prog %u: %s addr 0x%llx size %u\n", | ||
478 | i, name, prog_addrs[i], prog_lens[i]); | ||
479 | } | ||
480 | } | ||
diff --git a/tools/perf/util/bpf-event.h b/tools/perf/util/bpf-event.h index 8cb1189149ec..04c33b3bfe28 100644 --- a/tools/perf/util/bpf-event.h +++ b/tools/perf/util/bpf-event.h | |||
@@ -7,6 +7,7 @@ | |||
7 | #include <pthread.h> | 7 | #include <pthread.h> |
8 | #include <api/fd/array.h> | 8 | #include <api/fd/array.h> |
9 | #include "event.h" | 9 | #include "event.h" |
10 | #include <stdio.h> | ||
10 | 11 | ||
11 | struct machine; | 12 | struct machine; |
12 | union perf_event; | 13 | union perf_event; |
@@ -38,7 +39,9 @@ int perf_event__synthesize_bpf_events(struct perf_session *session, | |||
38 | struct record_opts *opts); | 39 | struct record_opts *opts); |
39 | int bpf_event__add_sb_event(struct perf_evlist **evlist, | 40 | int bpf_event__add_sb_event(struct perf_evlist **evlist, |
40 | struct perf_env *env); | 41 | struct perf_env *env); |
41 | 42 | void bpf_event__print_bpf_prog_info(struct bpf_prog_info *info, | |
43 | struct perf_env *env, | ||
44 | FILE *fp); | ||
42 | #else | 45 | #else |
43 | static inline int machine__process_bpf_event(struct machine *machine __maybe_unused, | 46 | static inline int machine__process_bpf_event(struct machine *machine __maybe_unused, |
44 | union perf_event *event __maybe_unused, | 47 | union perf_event *event __maybe_unused, |
@@ -61,5 +64,11 @@ static inline int bpf_event__add_sb_event(struct perf_evlist **evlist __maybe_un | |||
61 | return 0; | 64 | return 0; |
62 | } | 65 | } |
63 | 66 | ||
67 | static inline void bpf_event__print_bpf_prog_info(struct bpf_prog_info *info __maybe_unused, | ||
68 | struct perf_env *env __maybe_unused, | ||
69 | FILE *fp __maybe_unused) | ||
70 | { | ||
71 | |||
72 | } | ||
64 | #endif // HAVE_LIBBPF_SUPPORT | 73 | #endif // HAVE_LIBBPF_SUPPORT |
65 | #endif | 74 | #endif |
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 01dda2f65d36..b9e693825873 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -1468,8 +1468,9 @@ static void print_bpf_prog_info(struct feat_fd *ff, FILE *fp) | |||
1468 | 1468 | ||
1469 | node = rb_entry(next, struct bpf_prog_info_node, rb_node); | 1469 | node = rb_entry(next, struct bpf_prog_info_node, rb_node); |
1470 | next = rb_next(&node->rb_node); | 1470 | next = rb_next(&node->rb_node); |
1471 | fprintf(fp, "# bpf_prog_info of id %u\n", | 1471 | |
1472 | node->info_linear->info.id); | 1472 | bpf_event__print_bpf_prog_info(&node->info_linear->info, |
1473 | env, fp); | ||
1473 | } | 1474 | } |
1474 | 1475 | ||
1475 | up_read(&env->bpf_progs.lock); | 1476 | up_read(&env->bpf_progs.lock); |