* [PATCH perf,bpf 0/2] show bpf program info from perf.data header
@ 2019-03-14 18:25 Song Liu
2019-03-14 18:25 ` [PATCH perf,bpf 1/2] perf, bpf: refactor perf_event__synthesize_one_bpf_prog() Song Liu
2019-03-14 18:25 ` [PATCH perf,bpf 2/2] perf, bpf: show BPF program name in print_bpf_prog_info() Song Liu
0 siblings, 2 replies; 4+ messages in thread
From: Song Liu @ 2019-03-14 18:25 UTC (permalink / raw)
To: bpf, netdev, linux-kernel
Cc: ast, daniel, kernel-team, peterz, acme, jolsa, namhyung, sdf, Song Liu
This set enables printing name, address, and size of bpf programs stored
in perf.data file.
This set applies on top of https://lkml.org/lkml/2019/3/12/39 and the
uintptr_t fix (https://lkml.org/lkml/2019/3/14/624).
Thanks!
Song Liu (2):
perf, bpf: refactor perf_event__synthesize_one_bpf_prog()
perf, bpf: show BPF program name in print_bpf_prog_info()
tools/perf/util/bpf-event.c | 96 +++++++++++++++++++++++++++----------
tools/perf/util/bpf-event.h | 10 +++-
tools/perf/util/header.c | 5 +-
3 files changed, 82 insertions(+), 29 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH perf,bpf 1/2] perf, bpf: refactor perf_event__synthesize_one_bpf_prog()
2019-03-14 18:25 [PATCH perf,bpf 0/2] show bpf program info from perf.data header Song Liu
@ 2019-03-14 18:25 ` Song Liu
2019-03-14 18:25 ` [PATCH perf,bpf 2/2] perf, bpf: show BPF program name in print_bpf_prog_info() Song Liu
1 sibling, 0 replies; 4+ messages in thread
From: Song Liu @ 2019-03-14 18:25 UTC (permalink / raw)
To: bpf, netdev, linux-kernel
Cc: ast, daniel, kernel-team, peterz, acme, jolsa, namhyung, sdf, Song Liu
Extract logic to create program names to synthesize_bpf_prog_name(), so
that it can be reused in header.c:print_bpf_prog_info().
This commit doesn't change the behavior.
Signed-off-by: Song Liu <songliubraving@fb.com>
---
tools/perf/util/bpf-event.c | 60 +++++++++++++++++++++----------------
1 file changed, 34 insertions(+), 26 deletions(-)
diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c
index 3c01055a8c99..6e035e08aa2d 100644
--- a/tools/perf/util/bpf-event.c
+++ b/tools/perf/util/bpf-event.c
@@ -111,6 +111,38 @@ static int perf_env__fetch_btf(struct perf_env *env,
return 0;
}
+static int synthesize_bpf_prog_name(char *buf, int size,
+ struct bpf_prog_info *info,
+ struct btf *btf,
+ u32 sub_id)
+{
+ u8 (*prog_tags)[BPF_TAG_SIZE] = (void *)(uintptr_t)(info->prog_tags);
+ void *func_infos = (void *)(uintptr_t)(info->func_info);
+ u32 sub_prog_cnt = info->nr_jited_ksyms;
+ const struct bpf_func_info *finfo;
+ const char *short_name = NULL;
+ const struct btf_type *t;
+ int name_len;
+
+ name_len = snprintf(buf, size, "bpf_prog_");
+ name_len += snprintf_hex(buf + name_len, size - name_len,
+ prog_tags[sub_id], BPF_TAG_SIZE);
+ if (btf) {
+ finfo = func_infos + sub_id * info->func_info_rec_size;
+ t = btf__type_by_id(btf, finfo->type_id);
+ short_name = btf__name_by_offset(btf, t->name_off);
+ } else if (sub_id == 0 && sub_prog_cnt == 1) {
+ /* no subprog */
+ if (info->name[0])
+ short_name = info->name;
+ } else
+ short_name = "F";
+ if (short_name)
+ name_len += snprintf(buf + name_len, size - name_len,
+ "_%s", short_name);
+ return name_len;
+}
+
/*
* Synthesize PERF_RECORD_KSYMBOL and PERF_RECORD_BPF_EVENT for one bpf
* program. One PERF_RECORD_BPF_EVENT is generated for the program. And
@@ -135,7 +167,6 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session,
struct bpf_prog_info_node *info_node;
struct bpf_prog_info *info;
struct btf *btf = NULL;
- bool has_btf = false;
struct perf_env *env;
u32 sub_prog_cnt, i;
int err = 0;
@@ -189,19 +220,13 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session,
btf = NULL;
goto out;
}
- has_btf = true;
perf_env__fetch_btf(env, info->btf_id, btf);
}
/* Synthesize PERF_RECORD_KSYMBOL */
for (i = 0; i < sub_prog_cnt; i++) {
- u8 (*prog_tags)[BPF_TAG_SIZE] = (void *)(uintptr_t)(info->prog_tags);
__u32 *prog_lens = (__u32 *)(uintptr_t)(info->jited_func_lens);
__u64 *prog_addrs = (__u64 *)(uintptr_t)(info->jited_ksyms);
- void *func_infos = (void *)(uintptr_t)(info->func_info);
- const struct bpf_func_info *finfo;
- const char *short_name = NULL;
- const struct btf_type *t;
int name_len;
*ksymbol_event = (struct ksymbol_event){
@@ -214,26 +239,9 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session,
.ksym_type = PERF_RECORD_KSYMBOL_TYPE_BPF,
.flags = 0,
};
- name_len = snprintf(ksymbol_event->name, KSYM_NAME_LEN,
- "bpf_prog_");
- name_len += snprintf_hex(ksymbol_event->name + name_len,
- KSYM_NAME_LEN - name_len,
- prog_tags[i], BPF_TAG_SIZE);
- if (has_btf) {
- finfo = func_infos + i * info->func_info_rec_size;
- t = btf__type_by_id(btf, finfo->type_id);
- short_name = btf__name_by_offset(btf, t->name_off);
- } else if (i == 0 && sub_prog_cnt == 1) {
- /* no subprog */
- if (info->name[0])
- short_name = info->name;
- } else
- short_name = "F";
- if (short_name)
- name_len += snprintf(ksymbol_event->name + name_len,
- KSYM_NAME_LEN - name_len,
- "_%s", short_name);
+ name_len = synthesize_bpf_prog_name(ksymbol_event->name,
+ KSYM_NAME_LEN, info, btf, i);
ksymbol_event->header.size += PERF_ALIGN(name_len + 1,
sizeof(u64));
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH perf,bpf 2/2] perf, bpf: show BPF program name in print_bpf_prog_info()
2019-03-14 18:25 [PATCH perf,bpf 0/2] show bpf program info from perf.data header Song Liu
2019-03-14 18:25 ` [PATCH perf,bpf 1/2] perf, bpf: refactor perf_event__synthesize_one_bpf_prog() Song Liu
@ 2019-03-14 18:25 ` Song Liu
2019-03-14 18:29 ` Song Liu
1 sibling, 1 reply; 4+ messages in thread
From: Song Liu @ 2019-03-14 18:25 UTC (permalink / raw)
To: bpf, netdev, linux-kernel
Cc: ast, daniel, kernel-team, peterz, acme, jolsa, namhyung, sdf, Song Liu
This patch enables showing bpf program name 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
# bpf_prog_info 10: bpf_prog_2a142ef67aaad174
# bpf_prog_info 13: bpf_prog_47368425825d7384_task__task_newt
Signed-off-by: Song Liu <songliubraving@fb.com>
---
tools/perf/util/bpf-event.c | 36 ++++++++++++++++++++++++++++++++++++
tools/perf/util/bpf-event.h | 10 +++++++++-
| 5 +++--
3 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c
index 6e035e08aa2d..dde35a36e2de 100644
--- a/tools/perf/util/bpf-event.c
+++ b/tools/perf/util/bpf-event.c
@@ -433,3 +433,39 @@ int bpf_event__add_sb_event(struct perf_evlist **evlist,
return perf_evlist__add_sb_event(evlist, &attr, bpf_event__sb_cb, env);
}
+
+void bpf_event__print_bpf_prog_info(struct bpf_prog_info *info,
+ struct perf_env *env,
+ FILE *fp)
+{
+ char name[KSYM_NAME_LEN];
+ struct btf *btf = NULL;
+ u32 sub_prog_cnt, i;
+
+ sub_prog_cnt = info->nr_jited_ksyms;
+ if (sub_prog_cnt != info->nr_prog_tags ||
+ sub_prog_cnt != info->nr_jited_func_lens)
+ return;
+
+ if (info->btf_id) {
+ struct btf_node *node;
+
+ node = perf_env__find_btf(env, info->btf_id);
+ if (node)
+ btf = btf__new((__u8 *)(node->data),
+ node->data_size);
+ }
+
+ if (sub_prog_cnt == 1) {
+ synthesize_bpf_prog_name(name, KSYM_NAME_LEN, info, btf, 0);
+ fprintf(fp, "# bpf_prog_info %u: %s\n", info->id, name);
+ return;
+ }
+
+ fprintf(fp, "# bpf_prog_info %u:\n", info->id);
+ for (i = 0; i < sub_prog_cnt; i++) {
+ synthesize_bpf_prog_name(name, KSYM_NAME_LEN, info, btf, i);
+
+ fprintf(fp, "# \tsub_prog %u: %s\n", i, name);
+ }
+}
diff --git a/tools/perf/util/bpf-event.h b/tools/perf/util/bpf-event.h
index 249909c826e7..4270dfd9cde9 100644
--- a/tools/perf/util/bpf-event.h
+++ b/tools/perf/util/bpf-event.h
@@ -38,7 +38,9 @@ int perf_event__synthesize_bpf_events(struct perf_session *session,
struct record_opts *opts);
int bpf_event__add_sb_event(struct perf_evlist **evlist,
struct perf_env *env);
-
+void bpf_event__print_bpf_prog_info(struct bpf_prog_info *info,
+ struct perf_env *env,
+ FILE *fp);
#else
static inline int machine__process_bpf_event(struct machine *machine __maybe_unused,
union perf_event *event __maybe_unused,
@@ -61,5 +63,11 @@ static int bpf_event__add_sb_event(struct perf_evlist **evlist __maybe_unused,
return 0;
}
+void bpf_event__print_bpf_prog_info(struct bpf_prog_info *info,
+ struct perf_env *env,
+ FILE *fp)
+{
+
+}
#endif // HAVE_LIBBPF_SUPPORT
#endif
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 7decd2d1dbda..588a80bdd500 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1434,8 +1434,9 @@ static void print_bpf_prog_info(struct feat_fd *ff, FILE *fp)
node = rb_entry(next, struct bpf_prog_info_node, rb_node);
next = rb_next(&node->rb_node);
- fprintf(fp, "# bpf_prog_info of id %u\n",
- node->info_linear->info.id);
+
+ bpf_event__print_bpf_prog_info(&node->info_linear->info,
+ env, fp);
}
up_read(&env->bpf_progs.lock);
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH perf,bpf 2/2] perf, bpf: show BPF program name in print_bpf_prog_info()
2019-03-14 18:25 ` [PATCH perf,bpf 2/2] perf, bpf: show BPF program name in print_bpf_prog_info() Song Liu
@ 2019-03-14 18:29 ` Song Liu
0 siblings, 0 replies; 4+ messages in thread
From: Song Liu @ 2019-03-14 18:29 UTC (permalink / raw)
To: bpf, Networking, linux-kernel
Cc: Alexei Starovoitov, Daniel Borkmann, Kernel Team, Peter Zijlstra,
Arnaldo Carvalho de Melo, Jiri Olsa, Namhyung Kim,
Stanislav Fomichev
> On Mar 14, 2019, at 11:25 AM, Song Liu <songliubraving@fb.com> wrote:
>
> This patch enables showing bpf program name 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
> # bpf_prog_info 10: bpf_prog_2a142ef67aaad174
> # bpf_prog_info 13: bpf_prog_47368425825d7384_task__task_newt
>
> Signed-off-by: Song Liu <songliubraving@fb.com>
Please ignore this patch, and use the other PATCH 2/2 with address and
size information instead.
Thanks,
Song
> ---
> tools/perf/util/bpf-event.c | 36 ++++++++++++++++++++++++++++++++++++
> tools/perf/util/bpf-event.h | 10 +++++++++-
> tools/perf/util/header.c | 5 +++--
> 3 files changed, 48 insertions(+), 3 deletions(-)
>
> diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c
> index 6e035e08aa2d..dde35a36e2de 100644
> --- a/tools/perf/util/bpf-event.c
> +++ b/tools/perf/util/bpf-event.c
> @@ -433,3 +433,39 @@ int bpf_event__add_sb_event(struct perf_evlist **evlist,
>
> return perf_evlist__add_sb_event(evlist, &attr, bpf_event__sb_cb, env);
> }
> +
> +void bpf_event__print_bpf_prog_info(struct bpf_prog_info *info,
> + struct perf_env *env,
> + FILE *fp)
> +{
> + char name[KSYM_NAME_LEN];
> + struct btf *btf = NULL;
> + u32 sub_prog_cnt, i;
> +
> + sub_prog_cnt = info->nr_jited_ksyms;
> + if (sub_prog_cnt != info->nr_prog_tags ||
> + sub_prog_cnt != info->nr_jited_func_lens)
> + return;
> +
> + if (info->btf_id) {
> + struct btf_node *node;
> +
> + node = perf_env__find_btf(env, info->btf_id);
> + if (node)
> + btf = btf__new((__u8 *)(node->data),
> + node->data_size);
> + }
> +
> + if (sub_prog_cnt == 1) {
> + synthesize_bpf_prog_name(name, KSYM_NAME_LEN, info, btf, 0);
> + fprintf(fp, "# bpf_prog_info %u: %s\n", info->id, name);
> + return;
> + }
> +
> + fprintf(fp, "# bpf_prog_info %u:\n", info->id);
> + for (i = 0; i < sub_prog_cnt; i++) {
> + synthesize_bpf_prog_name(name, KSYM_NAME_LEN, info, btf, i);
> +
> + fprintf(fp, "# \tsub_prog %u: %s\n", i, name);
> + }
> +}
> diff --git a/tools/perf/util/bpf-event.h b/tools/perf/util/bpf-event.h
> index 249909c826e7..4270dfd9cde9 100644
> --- a/tools/perf/util/bpf-event.h
> +++ b/tools/perf/util/bpf-event.h
> @@ -38,7 +38,9 @@ int perf_event__synthesize_bpf_events(struct perf_session *session,
> struct record_opts *opts);
> int bpf_event__add_sb_event(struct perf_evlist **evlist,
> struct perf_env *env);
> -
> +void bpf_event__print_bpf_prog_info(struct bpf_prog_info *info,
> + struct perf_env *env,
> + FILE *fp);
> #else
> static inline int machine__process_bpf_event(struct machine *machine __maybe_unused,
> union perf_event *event __maybe_unused,
> @@ -61,5 +63,11 @@ static int bpf_event__add_sb_event(struct perf_evlist **evlist __maybe_unused,
> return 0;
> }
>
> +void bpf_event__print_bpf_prog_info(struct bpf_prog_info *info,
> + struct perf_env *env,
> + FILE *fp)
> +{
> +
> +}
> #endif // HAVE_LIBBPF_SUPPORT
> #endif
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index 7decd2d1dbda..588a80bdd500 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -1434,8 +1434,9 @@ static void print_bpf_prog_info(struct feat_fd *ff, FILE *fp)
>
> node = rb_entry(next, struct bpf_prog_info_node, rb_node);
> next = rb_next(&node->rb_node);
> - fprintf(fp, "# bpf_prog_info of id %u\n",
> - node->info_linear->info.id);
> +
> + bpf_event__print_bpf_prog_info(&node->info_linear->info,
> + env, fp);
> }
>
> up_read(&env->bpf_progs.lock);
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-03-14 18:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-14 18:25 [PATCH perf,bpf 0/2] show bpf program info from perf.data header Song Liu
2019-03-14 18:25 ` [PATCH perf,bpf 1/2] perf, bpf: refactor perf_event__synthesize_one_bpf_prog() Song Liu
2019-03-14 18:25 ` [PATCH perf,bpf 2/2] perf, bpf: show BPF program name in print_bpf_prog_info() Song Liu
2019-03-14 18:29 ` Song Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).