@@ -472,6 +472,49 @@ void bpf_metadata_free(struct bpf_metadata *metadata __maybe_unused)
472472
473473#endif /* HAVE_LIBBPF_STRINGS_SUPPORT */
474474
475+ struct bpf_metadata_final_ctx {
476+ const struct perf_tool * tool ;
477+ perf_event__handler_t process ;
478+ struct machine * machine ;
479+ };
480+
481+ static void synthesize_final_bpf_metadata_cb (struct bpf_prog_info_node * node ,
482+ void * data )
483+ {
484+ struct bpf_metadata_final_ctx * ctx = (struct bpf_metadata_final_ctx * )data ;
485+ struct bpf_metadata * metadata = node -> metadata ;
486+ int err ;
487+
488+ if (metadata == NULL )
489+ return ;
490+ err = synthesize_perf_record_bpf_metadata (metadata , ctx -> tool ,
491+ ctx -> process , ctx -> machine );
492+ if (err != 0 ) {
493+ const char * prog_name = metadata -> prog_names [0 ];
494+
495+ if (prog_name != NULL )
496+ pr_warning ("Couldn't synthesize final BPF metadata for %s.\n" , prog_name );
497+ else
498+ pr_warning ("Couldn't synthesize final BPF metadata.\n" );
499+ }
500+ bpf_metadata_free (metadata );
501+ node -> metadata = NULL ;
502+ }
503+
504+ void perf_event__synthesize_final_bpf_metadata (struct perf_session * session ,
505+ perf_event__handler_t process )
506+ {
507+ struct perf_env * env = & session -> header .env ;
508+ struct bpf_metadata_final_ctx ctx = {
509+ .tool = session -> tool ,
510+ .process = process ,
511+ .machine = & session -> machines .host ,
512+ };
513+
514+ perf_env__iterate_bpf_prog_info (env , synthesize_final_bpf_metadata_cb ,
515+ & ctx );
516+ }
517+
475518/*
476519 * Synthesize PERF_RECORD_KSYMBOL and PERF_RECORD_BPF_EVENT for one bpf
477520 * program. One PERF_RECORD_BPF_EVENT is generated for the program. And
@@ -612,6 +655,7 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session,
612655 }
613656
614657 info_node -> info_linear = info_linear ;
658+ info_node -> metadata = NULL ;
615659 if (!perf_env__insert_bpf_prog_info (env , info_node )) {
616660 free (info_linear );
617661 free (info_node );
@@ -803,6 +847,7 @@ static void perf_env__add_bpf_info(struct perf_env *env, u32 id)
803847 arrays |= 1UL << PERF_BPIL_JITED_INSNS ;
804848 arrays |= 1UL << PERF_BPIL_LINE_INFO ;
805849 arrays |= 1UL << PERF_BPIL_JITED_LINE_INFO ;
850+ arrays |= 1UL << PERF_BPIL_MAP_IDS ;
806851
807852 info_linear = get_bpf_prog_info_linear (fd , arrays );
808853 if (IS_ERR_OR_NULL (info_linear )) {
@@ -815,6 +860,7 @@ static void perf_env__add_bpf_info(struct perf_env *env, u32 id)
815860 info_node = malloc (sizeof (struct bpf_prog_info_node ));
816861 if (info_node ) {
817862 info_node -> info_linear = info_linear ;
863+ info_node -> metadata = bpf_metadata_create (& info_linear -> info );
818864 if (!perf_env__insert_bpf_prog_info (env , info_node )) {
819865 free (info_linear );
820866 free (info_node );
0 commit comments