perf lock contention: Factor out get_symbol_name_offset()
authorNamhyung Kim <namhyung@kernel.org>
Mon, 12 Sep 2022 05:53:11 +0000 (22:53 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 4 Oct 2022 11:55:22 +0000 (08:55 -0300)
It's to convert addr to symbol+offset.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20220912055314.744552-2-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-lock.c

index 52a6a10a610cb20972b5d1f3df145a0e08bf62a1..eaba6018da69a0905f29cc3729d7aabb8dc3ed90 100644 (file)
@@ -899,6 +899,23 @@ bool is_lock_function(struct machine *machine, u64 addr)
        return false;
 }
 
+static int get_symbol_name_offset(struct map *map, struct symbol *sym, u64 ip,
+                                 char *buf, int size)
+{
+       u64 offset;
+
+       if (map == NULL || sym == NULL) {
+               buf[0] = '\0';
+               return 0;
+       }
+
+       offset = map->map_ip(map, ip) - sym->start;
+
+       if (offset)
+               return scnprintf(buf, size, "%s+%#lx", sym->name, offset);
+       else
+               return strlcpy(buf, sym->name, size);
+}
 static int lock_contention_caller(struct evsel *evsel, struct perf_sample *sample,
                                  char *buf, int size)
 {
@@ -941,15 +958,8 @@ static int lock_contention_caller(struct evsel *evsel, struct perf_sample *sampl
 
                sym = node->ms.sym;
                if (sym && !is_lock_function(machine, node->ip)) {
-                       struct map *map = node->ms.map;
-                       u64 offset;
-
-                       offset = map->map_ip(map, node->ip) - sym->start;
-
-                       if (offset)
-                               scnprintf(buf, size, "%s+%#lx", sym->name, offset);
-                       else
-                               strlcpy(buf, sym->name, size);
+                       get_symbol_name_offset(node->ms.map, sym, node->ip,
+                                              buf, size);
                        return 0;
                }