Commit d3b52f71 authored by Adrian Hunter's avatar Adrian Hunter Committed by Arnaldo Carvalho de Melo

perf script: Refine printing of dso offset (dsoff)

Print dso offset only for object files, and in those cases force using the
dso->long_name if the dso->name starts with '[' or the dso is kcore, in
order to avoid special names such as [vdso], or mixing up kcore with
vmlinux.
Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
Cc: Changbin Du <changbin.du@huawei.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20230424055107.12105-3-adrian.hunter@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 24f0af6d
...@@ -67,6 +67,39 @@ char dso__symtab_origin(const struct dso *dso) ...@@ -67,6 +67,39 @@ char dso__symtab_origin(const struct dso *dso)
return origin[dso->symtab_type]; return origin[dso->symtab_type];
} }
bool dso__is_object_file(const struct dso *dso)
{
switch (dso->binary_type) {
case DSO_BINARY_TYPE__KALLSYMS:
case DSO_BINARY_TYPE__GUEST_KALLSYMS:
case DSO_BINARY_TYPE__JAVA_JIT:
case DSO_BINARY_TYPE__BPF_PROG_INFO:
case DSO_BINARY_TYPE__BPF_IMAGE:
case DSO_BINARY_TYPE__OOL:
return false;
case DSO_BINARY_TYPE__VMLINUX:
case DSO_BINARY_TYPE__GUEST_VMLINUX:
case DSO_BINARY_TYPE__DEBUGLINK:
case DSO_BINARY_TYPE__BUILD_ID_CACHE:
case DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO:
case DSO_BINARY_TYPE__FEDORA_DEBUGINFO:
case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO:
case DSO_BINARY_TYPE__MIXEDUP_UBUNTU_DEBUGINFO:
case DSO_BINARY_TYPE__BUILDID_DEBUGINFO:
case DSO_BINARY_TYPE__SYSTEM_PATH_DSO:
case DSO_BINARY_TYPE__GUEST_KMODULE:
case DSO_BINARY_TYPE__GUEST_KMODULE_COMP:
case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE:
case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP:
case DSO_BINARY_TYPE__KCORE:
case DSO_BINARY_TYPE__GUEST_KCORE:
case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO:
case DSO_BINARY_TYPE__NOT_FOUND:
default:
return true;
}
}
int dso__read_binary_type_filename(const struct dso *dso, int dso__read_binary_type_filename(const struct dso *dso,
enum dso_binary_type type, enum dso_binary_type type,
char *root_dir, char *filename, size_t size) char *root_dir, char *filename, size_t size)
......
...@@ -396,6 +396,8 @@ static inline bool dso__is_kallsyms(const struct dso *dso) ...@@ -396,6 +396,8 @@ static inline bool dso__is_kallsyms(const struct dso *dso)
return dso->kernel && dso->long_name[0] != '/'; return dso->kernel && dso->long_name[0] != '/';
} }
bool dso__is_object_file(const struct dso *dso);
void dso__free_a2l(struct dso *dso); void dso__free_a2l(struct dso *dso);
enum dso_type dso__type(struct dso *dso, struct machine *machine); enum dso_type dso__type(struct dso *dso, struct machine *machine);
......
...@@ -431,14 +431,21 @@ size_t map__fprintf(struct map *map, FILE *fp) ...@@ -431,14 +431,21 @@ size_t map__fprintf(struct map *map, FILE *fp)
map__start(map), map__end(map), map__pgoff(map), dso->name); map__start(map), map__end(map), map__pgoff(map), dso->name);
} }
size_t map__fprintf_dsoname(struct map *map, FILE *fp) static bool prefer_dso_long_name(const struct dso *dso, bool print_off)
{
return dso->long_name &&
(symbol_conf.show_kernel_path ||
(print_off && (dso->name[0] == '[' || dso__is_kcore(dso))));
}
static size_t __map__fprintf_dsoname(struct map *map, bool print_off, FILE *fp)
{ {
char buf[symbol_conf.pad_output_len_dso + 1]; char buf[symbol_conf.pad_output_len_dso + 1];
const char *dsoname = "[unknown]"; const char *dsoname = "[unknown]";
const struct dso *dso = map ? map__dso(map) : NULL; const struct dso *dso = map ? map__dso(map) : NULL;
if (dso) { if (dso) {
if (symbol_conf.show_kernel_path && dso->long_name) if (prefer_dso_long_name(dso, print_off))
dsoname = dso->long_name; dsoname = dso->long_name;
else else
dsoname = dso->name; dsoname = dso->name;
...@@ -452,13 +459,21 @@ size_t map__fprintf_dsoname(struct map *map, FILE *fp) ...@@ -452,13 +459,21 @@ size_t map__fprintf_dsoname(struct map *map, FILE *fp)
return fprintf(fp, "%s", dsoname); return fprintf(fp, "%s", dsoname);
} }
size_t map__fprintf_dsoname(struct map *map, FILE *fp)
{
return __map__fprintf_dsoname(map, false, fp);
}
size_t map__fprintf_dsoname_dsoff(struct map *map, bool print_off, u64 addr, FILE *fp) size_t map__fprintf_dsoname_dsoff(struct map *map, bool print_off, u64 addr, FILE *fp)
{ {
const struct dso *dso = map ? map__dso(map) : NULL;
int printed = 0; int printed = 0;
if (print_off && (!dso || !dso__is_object_file(dso)))
print_off = false;
printed += fprintf(fp, " ("); printed += fprintf(fp, " (");
printed += map__fprintf_dsoname(map, fp); printed += __map__fprintf_dsoname(map, print_off, fp);
if (print_off && map && map__dso(map) && !map__dso(map)->kernel) if (print_off)
printed += fprintf(fp, "+0x%" PRIx64, addr); printed += fprintf(fp, "+0x%" PRIx64, addr);
printed += fprintf(fp, ")"); printed += fprintf(fp, ")");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment