mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: <zhe.he@windriver.com>
To: <peterz@infradead.org>, <mingo@redhat.com>, <acme@kernel.org>,
	<mark.rutland@arm.com>, <alexander.shishkin@linux.intel.com>,
	<jolsa@redhat.com>, <namhyung@kernel.org>, <mhiramat@kernel.org>,
	<kstewart@linuxfoundation.org>, <tglx@linutronix.de>,
	<linux-kernel@vger.kernel.org>, <zhe.he@windriver.com>
Subject: [PATCH 1/2] perf: Fix checking of duplicate probe to give proper hint
Date: Tue, 25 Feb 2020 22:41:42 +0800	[thread overview]
Message-ID: <1582641703-233485-1-git-send-email-zhe.he@windriver.com> (raw)

From: He Zhe <zhe.he@windriver.com>

Since commit 72363540c009 ("perf probe: Support multiprobe event") and its
series, if there are multiple probes for one event,
__probe_file__get_namelist would return -EEXIST and cause the following
failure without proper hint, due to adding existing entry to output list.

root@qemuarm64:~# perf probe -x /lib64/libc.so.6 free
Added new events:
  probe_libc:free      (on free in /lib64/libc-2.31.so)
  probe_libc:free      (on free in /lib64/libc-2.31.so)

You can now use it in all perf tools, such as:

        perf record -e probe_libc:free -aR sleep 1

root@qemuarm64:~# perf probe -l
  probe_libc:free      (on free@plt in /lib64/libc-2.31.so)
  probe_libc:free      (on cfree in /lib64/libc-2.31.so)
root@qemuarm64:~# perf probe -x /lib64/libc.so.6 free
  Error: Failed to add events.

As we just want to check if there is any probe with the same name, -EEXIST
can be ignored, so we can have the right hint as before.

root@qemuarm64:~# perf probe -x /lib64/libc.so.6 free
Error: event "free" already exists.
 Hint: Remove existing event by 'perf probe -d'
       or force duplicates by 'perf probe -f'
       or set 'force=yes' in BPF source.
  Error: Failed to add events.

Signed-off-by: He Zhe <zhe.he@windriver.com>
---
 tools/perf/util/probe-file.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index 5003ba403345..cf44c05f89c1 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -201,10 +201,16 @@ static struct strlist *__probe_file__get_namelist(int fd, bool include_group)
 		if (include_group) {
 			ret = e_snprintf(buf, 128, "%s:%s", tev.group,
 					tev.event);
-			if (ret >= 0)
+			if (ret >= 0) {
 				ret = strlist__add(sl, buf);
-		} else
+				if (ret == -EEXIST)
+					ret = 0;
+			}
+		} else {
 			ret = strlist__add(sl, tev.event);
+			if (ret == -EEXIST)
+				ret = 0;
+		}
 		clear_probe_trace_event(&tev);
 		if (ret < 0)
 			break;
-- 
2.24.1


             reply	other threads:[~2020-02-25 14:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-25 14:41 zhe.he [this message]
2020-02-25 14:41 ` [PATCH 2/2] perf: probe-file: Check return value of strlist__add zhe.he
2020-02-25 22:49   ` Masami Hiramatsu
2020-02-26  2:49     ` He Zhe
2020-02-26  7:11       ` Masami Hiramatsu
2020-02-25 22:34 ` [PATCH 1/2] perf: Fix checking of duplicate probe to give proper hint Masami Hiramatsu

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=1582641703-233485-1-git-send-email-zhe.he@windriver.com \
    --to=zhe.he@windriver.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@redhat.com \
    --cc=kstewart@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /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

all inboxes | Powered by JetHome®