[tip:perf/core] perf probe: Fix to cut off incompatible chars from group name

From: tip-bot for Masami Hiramatsu
Date: Thu Sep 29 2016 - 14:21:14 EST


Commit-ID: 35726d3a4ca9ce10811032baf6fa0b3529aac087
Gitweb: http://git.kernel.org/tip/35726d3a4ca9ce10811032baf6fa0b3529aac087
Author: Masami Hiramatsu <mhiramat@xxxxxxxxxx>
AuthorDate: Sat, 24 Sep 2016 00:35:16 +0900
Committer: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
CommitDate: Thu, 29 Sep 2016 11:17:08 -0300

perf probe: Fix to cut off incompatible chars from group name

Cut off the characters which can not use for group name of uprobes
when making it based on executable filename.

For example, if the exec name is libstdc++.so, without this fix
perf probe generates "probe_libstdc++" as the group name, but
it is failed to set because '+' can not be used for group name.

With this fix perf accepts only alphabet, number or '_' for group
name, thus perf generates "probe_libstdc" as the group name.

E.g. with this fix, you can see the event name has no "+".
----
$ ./perf probe -x /usr/lib64/libstdc++.so.6 -D is_open
p:probe_libstdc/is_open /usr/lib64/libstdc++.so.6.0.22:0x8ca80
p:probe_libstdc/is_open_1 /usr/lib64/libstdc++.so.6.0.22:0x8ca70
p:probe_libstdc/is_open_2 /usr/lib64/libstdc++.so.6.0.22:0x8ca60
p:probe_libstdc/is_open_3 /usr/lib64/libstdc++.so.6.0.22:0xb0ad0
p:probe_libstdc/is_open_4 /usr/lib64/libstdc++.so.6.0.22:0xecca9
----

Committer note:

Before this fix:

# perf probe -x /usr/lib64/libstdc++.so.6 is_open
Failed to write event: Invalid argument
Error: Failed to add events.
#

After the fix:

# perf probe -x /usr/lib64/libstdc++.so.6 is_open
Added new events:
probe_libstdc:is_open (on is_open in /usr/lib64/libstdc++.so.6.0.22)
probe_libstdc:is_open_1 (on is_open in /usr/lib64/libstdc++.so.6.0.22)
probe_libstdc:is_open_2 (on is_open in /usr/lib64/libstdc++.so.6.0.22)
probe_libstdc:is_open_3 (on is_open in /usr/lib64/libstdc++.so.6.0.22)
probe_libstdc:is_open_4 (on is_open in /usr/lib64/libstdc++.so.6.0.22)

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

perf record -e probe_libstdc:is_open_4 -aR sleep 1

# perf probe -l probe_libstdc:*
probe_libstdc:is_open (on is_open@libstdc++-v3/include/fstream in /usr/lib64/libstdc++.so.6.0.22)
probe_libstdc:is_open_1 (on is_open@libstdc++-v3/include/fstream in /usr/lib64/libstdc++.so.6.0.22)
probe_libstdc:is_open_2 (on is_open@libstdc++-v3/include/fstream in /usr/lib64/libstdc++.so.6.0.22)
probe_libstdc:is_open_3 (on is_open@src/c++98/basic_file.cc in /usr/lib64/libstdc++.so.6.0.22)
probe_libstdc:is_open_4 (on stdio_filebuf:5@include/ext/stdio_filebuf.h in /usr/lib64/libstdc++.so.6.0.22)
#

Signed-off-by: Masami Hiramatsu <mhiramat@xxxxxxxxxx>
Tested-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Tested-by: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: David Ahern <dsahern@xxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Link: http://lkml.kernel.org/r/147464491667.29804.9553638175441827970.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/probe-event.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index bc60ce4..fcfbef0 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -213,9 +213,13 @@ static int convert_exec_to_group(const char *exec, char **result)
goto out;
}

- ptr2 = strpbrk(ptr1, "-._");
- if (ptr2)
- *ptr2 = '\0';
+ for (ptr2 = ptr1; ptr2 != '\0'; ptr2++) {
+ if (!isalnum(*ptr2) && *ptr2 != '_') {
+ *ptr2 = '\0';
+ break;
+ }
+ }
+
ret = e_snprintf(buf, 64, "%s_%s", PERFPROBE_GROUP, ptr1);
if (ret < 0)
goto out;