Message ID | 20211210190855.1369060-4-kuifeng@fb.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | BPF |
Headers | show |
Series | Stop using bpf_object__find_program_by_title API | expand |
On Fri, Dec 10, 2021 at 11:10 AM Kui-Feng Lee <kuifeng@fb.com> wrote: > > bpf_obj__find_program_by_title() in libbpf is going to be deprecated. > Call bpf_object_for_each_program to find a program in the section with > a given name instead. > > Signed-off-by: Kui-Feng Lee <kuifeng@fb.com> > --- > tools/perf/builtin-trace.c | 14 +++++++++++++- > 1 file changed, 13 insertions(+), 1 deletion(-) > > diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c > index 624ea12ce5ca..082ecf2b31bf 100644 > --- a/tools/perf/builtin-trace.c > +++ b/tools/perf/builtin-trace.c > @@ -3253,10 +3253,22 @@ static void trace__set_bpf_map_syscalls(struct trace *trace) > > static struct bpf_program *trace__find_bpf_program_by_title(struct trace *trace, const char *name) > { > + struct bpf_program *prog = NULL; > + struct bpf_program *pos; nothing wrong with this, but in similar situations I usually prefer struct bpf_program *pos, *prog = NULL; It's shorter. There were few other places like this in previous patches. > + const char *sec_name; > + > if (trace->bpf_obj == NULL) > return NULL; > > - return bpf_object__find_program_by_title(trace->bpf_obj, name); > + bpf_object__for_each_program(pos, trace->bpf_obj) { > + sec_name = bpf_program__section_name(pos); > + if (sec_name && !strcmp(sec_name, name)) { > + prog = pos; > + break; > + } > + } > + > + return prog; > } > > static struct bpf_program *trace__find_syscall_bpf_prog(struct trace *trace, struct syscall *sc, > -- > 2.30.2 >
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 624ea12ce5ca..082ecf2b31bf 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -3253,10 +3253,22 @@ static void trace__set_bpf_map_syscalls(struct trace *trace) static struct bpf_program *trace__find_bpf_program_by_title(struct trace *trace, const char *name) { + struct bpf_program *prog = NULL; + struct bpf_program *pos; + const char *sec_name; + if (trace->bpf_obj == NULL) return NULL; - return bpf_object__find_program_by_title(trace->bpf_obj, name); + bpf_object__for_each_program(pos, trace->bpf_obj) { + sec_name = bpf_program__section_name(pos); + if (sec_name && !strcmp(sec_name, name)) { + prog = pos; + break; + } + } + + return prog; } static struct bpf_program *trace__find_syscall_bpf_prog(struct trace *trace, struct syscall *sc,
bpf_obj__find_program_by_title() in libbpf is going to be deprecated. Call bpf_object_for_each_program to find a program in the section with a given name instead. Signed-off-by: Kui-Feng Lee <kuifeng@fb.com> --- tools/perf/builtin-trace.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)