Re: [PATCH v5 2/3] perf: add helper map__fprintf_dsoname_dsoff

Changbin Du
2023-04-20T02:55:36Z

On Wed, Apr 19, 2023 at 09:58:10PM +0300, Adrian Hunter wrote:
> On 18/04/23 06:18, Changbin Du wrote:
> > This adds a helper function map__fprintf_dsoname_dsoff() to print dsoname
> > with optional dso offset.
> >
> > Suggested-by: Adrian Hunter <adrian.hunter@intel.com>
> > Signed-off-by: Changbin Du <changbin.du@huawei.com>
> > ---
> > tools/perf/util/map.c | 13 +++++++++++++
> > tools/perf/util/map.h | 1 +
> > 2 files changed, 14 insertions(+)
> >
> > diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
> > index d81b6ca18ee9..7da96b41100f 100644
> > --- a/tools/perf/util/map.c
> > +++ b/tools/perf/util/map.c
> > @@ -445,6 +445,19 @@ size_t map__fprintf_dsoname(struct map *map, FILE *fp)
> > return fprintf(fp, "%s", dsoname);
> > }
> >
> > +size_t map__fprintf_dsoname_dsoff(struct map *map, bool print_off, u64 addr, FILE *fp)
> > +{
> > + int printed = 0;
> > +
> > + printed += fprintf(fp, " (");
> > + printed += map__fprintf_dsoname(map, fp);
> > + if (print_off && map && map__dso(map) && !map__dso(map)->kernel)
>
> That will also block vmlinux offsets not just [kernel.kallsyms]
> Is that what was intended?
>
Not only vmlinux, modules are also blocked. We'd better print offset for
vmlinux and modules.

$ sudo perf script -k vmlinux -F +dsoff
perf-exec 2531039 4120893.685967: 1 cycles: ffffffff99094ec4 [unknown] (vmlinux)
perf-exec 2531039 4120893.685970: 1 cycles: ffffffff99094ec4 [unknown] (vmlinux)
perf-exec 2531039 4120893.685972: 9 cycles: ffffffff99094ec4 [unknown] (vmlinux)
perf-exec 2531039 4120893.685973: 194 cycles: ffffffff99094ec6 [unknown] (vmlinux)
perf-exec 2531039 4120893.685974: 4605 cycles: ffffffff99094ec4 [unknown] (vmlinux)
perf-exec 2531039 4120893.685976: 108083 cycles: ffffffff9928e8d0 [unknown] (vmlinux)
ls 2531039 4120893.686003: 2197682 cycles: ffffffff993c92bc [unknown] (vmlinux)
ls 2531039 4120893.686554: 4497190 cycles: ffffffffc159692b strcasestr+0x7b (/lib/modules/5.15.0-60-generic/extra/isac_ipc.ko)
ls 2531039 4120893.687700: 4189758 cycles: ffffffffc18a5d66 delete_net_reject_cache+0x76 (/lib/modules/5.15.0-60-generic/extra/isac_networkfilter.ko)
ls 2531039 4120893.688786: 3780376 cycles: ffffffffc18a67de delete_net_process_info+0x5e (/lib/modules/5.15.0-60-generic/extra/isac_networkfilter.ko)
ls 2531039 4120893.689716: 3416607 cycles: ffffffffc18a67de delete_net_process_info+0x5e (/lib/modules/5.15.0-60-generic/extra/isac_networkfilter.ko)

But I found addr returned by map__dso_map_ip() for 'vmlinux' is not a 'dso
offset'.

$ sudo perf script -k vmlinux -F +dsoff
perf-exec 2531039 4120893.685967: 1 cycles: ffffffff99094ec4 [unknown] (vmlinux+0xffffffff99094ec4)
perf-exec 2531039 4120893.685970: 1 cycles: ffffffff99094ec4 [unknown] (vmlinux+0xffffffff99094ec4)
perf-exec 2531039 4120893.685972: 9 cycles: ffffffff99094ec4 [unknown] (vmlinux+0xffffffff99094ec4)
perf-exec 2531039 4120893.685973: 194 cycles: ffffffff99094ec6 [unknown] (vmlinux+0xffffffff99094ec6)

Do you have better idea?

--
Cheers,
Changbin Du