Re: [PATCH v5 perf,bpf 08/15] perf, bpf: save btf in a rbtree in perf_env

From: Jiri Olsa
Date: Mon Mar 04 2019 - 08:52:36 EST


On Wed, Feb 27, 2019 at 09:06:36PM -0800, Song Liu wrote:
> btf contains information necessary to annotate bpf programs. This patch
> saves btf for bpf programs loaded in the system.
>
> Signed-off-by: Song Liu <songliubraving@xxxxxx>
> ---
> tools/perf/util/bpf-event.c | 24 ++++++++++++++
> tools/perf/util/bpf-event.h | 7 ++++
> tools/perf/util/env.c | 65 +++++++++++++++++++++++++++++++++++++
> tools/perf/util/env.h | 4 +++
> 4 files changed, 100 insertions(+)
>
> diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c
> index ce81b2c43a51..370b830f2433 100644
> --- a/tools/perf/util/bpf-event.c
> +++ b/tools/perf/util/bpf-event.c
> @@ -34,6 +34,29 @@ int machine__process_bpf_event(struct machine *machine __maybe_unused,
> return 0;
> }
>
> +static int perf_env__fetch_btf(struct perf_env *env,
> + u32 btf_id,
> + struct btf *btf)
> +{
> + struct btf_node *node;
> + u32 data_size;
> + const void *data;
> +
> + data = btf__get_raw_data(btf, &data_size);
> +
> + node = malloc(data_size + sizeof(struct btf_node));
> +
> + if (!node)
> + return -1;
> +
> + node->id = btf_id;
> + node->data_size = data_size;
> + memcpy(node->data, data, data_size);

why don't we store just struct btf itself?

thanks,
jirka