linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitrii Dolgov <9erthalion6@gmail.com>
To: linux-perf-users@vger.kernel.org
Cc: acme@kernel.org, mingo@redhat.com, jolsa@kernel.org,
	irogers@google.com, adrian.hunter@intel.com,
	Dmitrii Dolgov <9erthalion6@gmail.com>
Subject: [RFC PATCH v1] perf record: Correct address filters for duplicated symbols
Date: Fri,  6 Jan 2023 21:37:51 +0100	[thread overview]
Message-ID: <20230106203751.403270-1-9erthalion6@gmail.com> (raw)

It seems the logic to handle duplicated symbols is off. In case if the
symbol index is specified it will:

* find a match
* continue searching
* check that start is not null and idx is set on the next loop
* exit with the error code 1

My guess is the expectation was that at this point the second match is
found (because *start is not null), although the new symbol hasn't pass
dso_sym_match yet. Here is how it looks like:

    $ readelf -a postgres | grep simple_heap_update
        4716: 00000000004e23e5   352 FUNC    GLOBAL DEFAULT   13 simple_heap_update
        27829: 00000000004e23e5   352 FUNC    GLOBAL DEFAULT   13 simple_heap_update

    $ perf record -p <pid> -e intel_pt// \
        --filter 'filter simple_heap_update #1 @ postgres' -- sleep 60

        Failed to parse address filter: 'filter simple_heap_update #1 @ postgres'
        Filter format is: filter|start|stop|tracestop <start symbol or address> [/ <end symbol or size>] [@<file name>]
        Where multiple filters are separated by space or comma.

Correct by returning error only after checking whether the symbol is
matching or not. After modifications the case above seems to be working
as expected:

    $ perf record -p <pid> -e intel_pt// \
        --filter 'filter simple_heap_update #1 @ postgres' -- sleep 60

    # update heap a couple of times

    $ perf script --itrace=c

        branches: 4e23fe simple_heap_update+0x19 => 54829c GetCurrentCommandId+0x0
        # [...]
        branches: 4e23fe simple_heap_update+0x19 => 54829c GetCurrentCommandId+0x0
        # [...]

Signed-off-by: Dmitrii Dolgov <9erthalion6@gmail.com>
---
 tools/perf/util/auxtrace.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index b59c278fe9ed..112cef56d6c2 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -2593,15 +2593,23 @@ static int find_dso_sym(struct dso *dso, const char *sym_name, u64 *start,
 
 	sym = dso__first_symbol(dso);
 	while (sym) {
+		/* Verify duplicates if one match was already found */
 		if (*start) {
 			if (!*size)
 				*size = sym->start - *start;
-			if (idx > 0) {
-				if (*size)
-					return 1;
-			} else if (dso_sym_match(sym, sym_name, &cnt, idx)) {
-				print_duplicate_syms(dso, sym_name);
-				return -EINVAL;
+
+			if (dso_sym_match(sym, sym_name, &cnt, idx)) {
+				if (idx > 0) {
+					/*
+					 * There is already one match with the specified index, now
+					 * we found the second one, something is wrong.
+					 */
+					if (*size)
+						return 1;
+				} else {
+					print_duplicate_syms(dso, sym_name);
+					return -EINVAL;
+				}
 			}
 		} else if (dso_sym_match(sym, sym_name, &cnt, idx)) {
 			*start = sym->start;
-- 
2.31.1


             reply	other threads:[~2023-01-06 20:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-06 20:37 Dmitrii Dolgov [this message]
2023-01-09  7:02 ` [RFC PATCH v1] perf record: Correct address filters for duplicated symbols Adrian Hunter
2023-01-10 10:48   ` Dmitry Dolgov
2023-01-11 13:17     ` Arnaldo Carvalho de Melo
2023-01-11 13:34       ` Dmitry Dolgov

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=20230106203751.403270-1-9erthalion6@gmail.com \
    --to=9erthalion6@gmail.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.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).