Re: [PATCH 3/3] perf inject: Do not load map/dso when injecting build-id

From: Jiri Olsa
Date: Wed Sep 16 2020 - 04:24:54 EST


On Tue, Sep 15, 2020 at 11:55:34PM +0900, Namhyung Kim wrote:
> On Tue, Sep 15, 2020 at 7:05 PM Jiri Olsa <jolsa@xxxxxxxxxx> wrote:
> >
> > On Mon, Sep 14, 2020 at 11:18:59PM +0900, Namhyung Kim wrote:
> > > No need to load symbols in a DSO when injecting build-id. I guess the
> > > reason was to check the DSO is a special file like anon files. Use
> > > some helper functions in map.c to check them before reading build-id.
> > > Also pass sample event's cpumode to a new build-id event.
> > >
> > > Original-patch-by: Stephane Eranian <eranian@xxxxxxxxxx>
> > > Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
> > > ---
> > > tools/perf/builtin-inject.c | 30 ++++++++++--------------------
> > > tools/perf/util/map.c | 17 +----------------
> > > tools/perf/util/map.h | 14 ++++++++++++++
> > > 3 files changed, 25 insertions(+), 36 deletions(-)
> > >
> > > diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
> > > index a2804d906d2a..6d4e6833efed 100644
> > > --- a/tools/perf/builtin-inject.c
> > > +++ b/tools/perf/builtin-inject.c
> > > @@ -436,21 +436,22 @@ static int dso__read_build_id(struct dso *dso)
> > > }
> > >
> > > static int dso__inject_build_id(struct dso *dso, struct perf_tool *tool,
> > > - struct machine *machine)
> > > + struct machine *machine, u8 cpumode)
> > > {
> > > - u16 misc = PERF_RECORD_MISC_USER;
> > > int err;
> > >
> > > + if (is_anon_memory(dso->long_name))
> > > + return 0;
> > > + if (is_no_dso_memory(dso->long_name))
> > > + return 0;
> >
> > should we check for vdso as well? I don't think it has build id
>
> I don't know.. But I guess there's no reason it shouldn't?

I haven't checked, it's just I always saw only zeros for vdso build ids

jirka
>
>
> >
> > > +
> > > if (dso__read_build_id(dso) < 0) {
> > > pr_debug("no build_id found for %s\n", dso->long_name);
> > > return -1;
> > > }
> > >
> > > - if (dso->kernel)
> > > - misc = PERF_RECORD_MISC_KERNEL;
> > > -
> > > - err = perf_event__synthesize_build_id(tool, dso, misc, perf_event__repipe,
> > > - machine);
> > > + err = perf_event__synthesize_build_id(tool, dso, cpumode,
> > > + perf_event__repipe, machine);
> > > if (err) {
> > > pr_err("Can't synthesize build_id event for %s\n", dso->long_name);
> > > return -1;
> > > @@ -478,19 +479,8 @@ static int perf_event__inject_buildid(struct perf_tool *tool,
> > > if (thread__find_map(thread, sample->cpumode, sample->ip, &al)) {
> > > if (!al.map->dso->hit) {
> > > al.map->dso->hit = 1;
> > > - if (map__load(al.map) >= 0) {
> >
> > nice, that might do some nice speedup, did you see any?
>
> Yes, I believe so. But my quick test on a laptop was too short.
> I will test it again and share the speedup.
>
> Thanks
> Namhyung
>
>
> >
> > jirka
> >
> > > - dso__inject_build_id(al.map->dso, tool, machine);
> > > - /*
> > > - * If this fails, too bad, let the other side
> > > - * account this as unresolved.
> > > - */
> > > - } else {
> > > -#ifdef HAVE_LIBELF_SUPPORT
> > > - pr_warning("no symbols found in %s, maybe "
> > > - "install a debug package?\n",
> > > - al.map->dso->long_name);
> > > -#endif
> > > - }
> > > + dso__inject_build_id(al.map->dso, tool, machine,
> > > + sample->cpumode);
> > > }
> >
> > SNIP
> >
>