perf map: Add helper map__fprintf_dsoname_dsoff
authorChangbin Du <changbin.du@huawei.com>
Tue, 18 Apr 2023 03:18:24 +0000 (11:18 +0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 12 May 2023 18:21:48 +0000 (15:21 -0300)
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>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Hui Wang <hw.huiwang@huawei.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230418031825.1262579-3-changbin.du@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/map.c
tools/perf/util/map.h

index b7f8909..8c96ce6 100644 (file)
@@ -452,6 +452,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)
+               printed += fprintf(fp, "+0x%" PRIx64, addr);
+       printed += fprintf(fp, ")");
+
+       return printed;
+}
+
 char *map__srcline(struct map *map, u64 addr, struct symbol *sym)
 {
        if (map == NULL)
index 823ab7f..66a87b3 100644 (file)
@@ -194,6 +194,7 @@ static inline void __map__zput(struct map **map)
 
 size_t map__fprintf(struct map *map, FILE *fp);
 size_t map__fprintf_dsoname(struct map *map, FILE *fp);
+size_t map__fprintf_dsoname_dsoff(struct map *map, bool print_off, u64 addr, FILE *fp);
 char *map__srcline(struct map *map, u64 addr, struct symbol *sym);
 int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
                         FILE *fp);