From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>, Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
LKML <linux-kernel@vger.kernel.org>,
Ian Rogers <irogers@google.com>,
linux-perf-users@vger.kernel.org,
Song Liu <songliubraving@fb.com>,
bpf@vger.kernel.org
Subject: [PATCH 1/4] perf lock contention: Factor out get_symbol_name_offset()
Date: Wed, 7 Sep 2022 23:37:51 -0700 [thread overview]
Message-ID: <20220908063754.1369709-2-namhyung@kernel.org> (raw)
In-Reply-To: <20220908063754.1369709-1-namhyung@kernel.org>
It's to convert addr to symbol+offset.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/builtin-lock.c | 28 +++++++++++++++++++---------
1 file changed, 19 insertions(+), 9 deletions(-)
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index 70197c0593b1..2a5672f8d22e 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -902,6 +902,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)
{
@@ -944,15 +961,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;
}
--
2.37.2.789.g6183377224-goog
next prev parent reply other threads:[~2022-09-08 6:38 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-08 6:37 [PATCH 0/4] perf lock contention: Improve call stack handling (v1) Namhyung Kim
2022-09-08 6:37 ` Namhyung Kim [this message]
2022-09-08 6:37 ` [PATCH 2/4] perf lock contention: Show full callstack with -v option Namhyung Kim
2022-09-08 6:37 ` [PATCH 3/4] perf lock contention: Allow to change stack depth and skip Namhyung Kim
2022-09-08 6:37 ` [PATCH 4/4] perf lock contention: Skip stack trace from BPF Namhyung Kim
2022-09-08 18:43 ` [PATCH 0/4] perf lock contention: Improve call stack handling (v1) Arnaldo Carvalho de Melo
2022-09-08 23:44 ` Namhyung Kim
2022-09-20 20:22 ` Arnaldo Carvalho de Melo
2022-09-20 21:04 ` Namhyung Kim
2022-09-21 14:09 ` Arnaldo Carvalho de Melo
-- strict thread matches above, loose matches on Subject: below --
2022-09-12 5:53 [PATCH 0/4] perf lock contention: Improve call stack handling (v2) Namhyung Kim
2022-09-12 5:53 ` [PATCH 1/4] perf lock contention: Factor out get_symbol_name_offset() Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220908063754.1369709-2-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=songliubraving@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).