aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/util/bpf-event.c62
1 files changed, 35 insertions, 27 deletions
diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c
index 2a8c245ca942..d5b041649f26 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,
111 return 0; 111 return 0;
112} 112}
113 113
114static int synthesize_bpf_prog_name(char *buf, int size,
115 struct bpf_prog_info *info,
116 struct btf *btf,
117 u32 sub_id)
118{
119 u8 (*prog_tags)[BPF_TAG_SIZE] = (void *)(uintptr_t)(info->prog_tags);
120 void *func_infos = (void *)(uintptr_t)(info->func_info);
121 u32 sub_prog_cnt = info->nr_jited_ksyms;
122 const struct bpf_func_info *finfo;
123 const char *short_name = NULL;
124 const struct btf_type *t;
125 int name_len;
126
127 name_len = snprintf(buf, size, "bpf_prog_");
128 name_len += snprintf_hex(buf + name_len, size - name_len,
129 prog_tags[sub_id], BPF_TAG_SIZE);
130 if (btf) {
131 finfo = func_infos + sub_id * info->func_info_rec_size;
132 t = btf__type_by_id(btf, finfo->type_id);
133 short_name = btf__name_by_offset(btf, t->name_off);
134 } else if (sub_id == 0 && sub_prog_cnt == 1) {
135 /* no subprog */
136 if (info->name[0])
137 short_name = info->name;
138 } else
139 short_name = "F";
140 if (short_name)
141 name_len += snprintf(buf + name_len, size - name_len,
142 "_%s", short_name);
143 return name_len;
144}
145
114/* 146/*
115 * Synthesize PERF_RECORD_KSYMBOL and PERF_RECORD_BPF_EVENT for one bpf 147 * Synthesize PERF_RECORD_KSYMBOL and PERF_RECORD_BPF_EVENT for one bpf
116 * program. One PERF_RECORD_BPF_EVENT is generated for the program. And 148 * 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,
135 struct bpf_prog_info_node *info_node; 167 struct bpf_prog_info_node *info_node;
136 struct bpf_prog_info *info; 168 struct bpf_prog_info *info;
137 struct btf *btf = NULL; 169 struct btf *btf = NULL;
138 bool has_btf = false;
139 struct perf_env *env; 170 struct perf_env *env;
140 u32 sub_prog_cnt, i; 171 u32 sub_prog_cnt, i;
141 int err = 0; 172 int err = 0;
@@ -189,19 +220,13 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session,
189 btf = NULL; 220 btf = NULL;
190 goto out; 221 goto out;
191 } 222 }
192 has_btf = true;
193 perf_env__fetch_btf(env, info->btf_id, btf); 223 perf_env__fetch_btf(env, info->btf_id, btf);
194 } 224 }
195 225
196 /* Synthesize PERF_RECORD_KSYMBOL */ 226 /* Synthesize PERF_RECORD_KSYMBOL */
197 for (i = 0; i < sub_prog_cnt; i++) { 227 for (i = 0; i < sub_prog_cnt; i++) {
198 u8 (*prog_tags)[BPF_TAG_SIZE] = (void *)(uintptr_t)(info->prog_tags); 228 __u32 *prog_lens = (__u32 *)(uintptr_t)(info->jited_func_lens);
199 __u32 *prog_lens = (__u32 *)(uintptr_t)(info->jited_func_lens);
200 __u64 *prog_addrs = (__u64 *)(uintptr_t)(info->jited_ksyms); 229 __u64 *prog_addrs = (__u64 *)(uintptr_t)(info->jited_ksyms);
201 void *func_infos = (void *)(uintptr_t)(info->func_info);
202 const struct bpf_func_info *finfo;
203 const char *short_name = NULL;
204 const struct btf_type *t;
205 int name_len; 230 int name_len;
206 231
207 *ksymbol_event = (struct ksymbol_event){ 232 *ksymbol_event = (struct ksymbol_event){
@@ -214,26 +239,9 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session,
214 .ksym_type = PERF_RECORD_KSYMBOL_TYPE_BPF, 239 .ksym_type = PERF_RECORD_KSYMBOL_TYPE_BPF,
215 .flags = 0, 240 .flags = 0,
216 }; 241 };
217 name_len = snprintf(ksymbol_event->name, KSYM_NAME_LEN,
218 "bpf_prog_");
219 name_len += snprintf_hex(ksymbol_event->name + name_len,
220 KSYM_NAME_LEN - name_len,
221 prog_tags[i], BPF_TAG_SIZE);
222 if (has_btf) {
223 finfo = func_infos + i * info->func_info_rec_size;
224 t = btf__type_by_id(btf, finfo->type_id);
225 short_name = btf__name_by_offset(btf, t->name_off);
226 } else if (i == 0 && sub_prog_cnt == 1) {
227 /* no subprog */
228 if (info->name[0])
229 short_name = info->name;
230 } else
231 short_name = "F";
232 if (short_name)
233 name_len += snprintf(ksymbol_event->name + name_len,
234 KSYM_NAME_LEN - name_len,
235 "_%s", short_name);
236 242
243 name_len = synthesize_bpf_prog_name(ksymbol_event->name,
244 KSYM_NAME_LEN, info, btf, i);
237 ksymbol_event->header.size += PERF_ALIGN(name_len + 1, 245 ksymbol_event->header.size += PERF_ALIGN(name_len + 1,
238 sizeof(u64)); 246 sizeof(u64));
239 247