public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] perf: Fix checking of duplicate probe to give proper hint
@ 2020-02-25 14:41 zhe.he
  2020-02-25 14:41 ` [PATCH 2/2] perf: probe-file: Check return value of strlist__add zhe.he
  2020-02-25 22:34 ` [PATCH 1/2] perf: Fix checking of duplicate probe to give proper hint Masami Hiramatsu
  0 siblings, 2 replies; 6+ messages in thread
From: zhe.he @ 2020-02-25 14:41 UTC (permalink / raw)
  To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
	namhyung, mhiramat, kstewart, tglx, linux-kernel, zhe.he

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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-02-26  7:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-25 14:41 [PATCH 1/2] perf: Fix checking of duplicate probe to give proper hint zhe.he
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox