* [PATCH 21/35] perf probe: Add warning message if there is unexpected event name
2017-12-28 14:29 [GIT PULL 00/35] perf/core improvements and fixes Arnaldo Carvalho de Melo
@ 2017-12-28 14:30 ` Arnaldo Carvalho de Melo
2017-12-28 14:30 ` [PATCH 22/35] perf probe: Cut off the version suffix from " Arnaldo Carvalho de Melo
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-12-28 14:30 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, linux-perf-users, Masami Hiramatsu, Paul Clarke,
bhargavb, linux-rt-users, Arnaldo Carvalho de Melo
From: Masami Hiramatsu <mhiramat@kernel.org>
This improve the error message so that user can know event-name error
before writing new events to kprobe-events interface.
E.g.
======
#./perf probe -x /lib64/libc-2.25.so malloc_get_state*
Internal error: "malloc_get_state@GLIBC_2" is an invalid event name.
Error: Failed to add events.
======
Reported-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Acked-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Reviewed-by: Thomas Richter <tmricht@linux.vnet.ibm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: bhargavb <bhargavaramudu@gmail.com>
Cc: linux-rt-users@vger.kernel.org
Link: http://lkml.kernel.org/r/151275040665.24652.5188568529237584489.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/probe-event.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index b7aaf9b2294d..262d5da86623 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -2625,6 +2625,14 @@ static int get_new_event_name(char *buf, size_t len, const char *base,
out:
free(nbase);
+
+ /* Final validation */
+ if (ret >= 0 && !is_c_func_name(buf)) {
+ pr_warning("Internal error: \"%s\" is an invalid event name.\n",
+ buf);
+ ret = -EINVAL;
+ }
+
return ret;
}
--
2.13.6
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 22/35] perf probe: Cut off the version suffix from event name
2017-12-28 14:29 [GIT PULL 00/35] perf/core improvements and fixes Arnaldo Carvalho de Melo
2017-12-28 14:30 ` [PATCH 21/35] perf probe: Add warning message if there is unexpected event name Arnaldo Carvalho de Melo
@ 2017-12-28 14:30 ` Arnaldo Carvalho de Melo
2017-12-28 14:30 ` [PATCH 23/35] perf probe: Add __return suffix for return events Arnaldo Carvalho de Melo
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-12-28 14:30 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, linux-perf-users, Masami Hiramatsu, Paul Clarke,
linux-rt-users, Arnaldo Carvalho de Melo
From: Masami Hiramatsu <mhiramat@kernel.org>
Cut off the version suffix (e.g. @GLIBC_2.2.5 etc.) from automatic
generated event name. This fixes wildcard event adding like below case;
=====
# perf probe -x /lib64/libc-2.25.so malloc*
Internal error: "malloc_get_state@GLIBC_2" is wrong event name.
Error: Failed to add events.
=====
This failure was caused by a versioned suffix symbol.
With this fix, perf probe automatically cuts the suffix after @ as
below.
=====
# ./perf probe -x /lib64/libc-2.25.so malloc*
Added new events:
probe_libc:malloc_printerr (on malloc* in /usr/lib64/libc-2.25.so)
probe_libc:malloc_consolidate (on malloc* in /usr/lib64/libc-2.25.so)
probe_libc:malloc_check (on malloc* in /usr/lib64/libc-2.25.so)
probe_libc:malloc_hook_ini (on malloc* in /usr/lib64/libc-2.25.so)
probe_libc:malloc (on malloc* in /usr/lib64/libc-2.25.so)
probe_libc:malloc_trim (on malloc* in /usr/lib64/libc-2.25.so)
probe_libc:malloc_usable_size (on malloc* in /usr/lib64/libc-2.25.so)
probe_libc:malloc_stats (on malloc* in /usr/lib64/libc-2.25.so)
probe_libc:malloc_info (on malloc* in /usr/lib64/libc-2.25.so)
probe_libc:mallochook (on malloc* in /usr/lib64/libc-2.25.so)
probe_libc:malloc_get_state (on malloc* in /usr/lib64/libc-2.25.so)
probe_libc:malloc_set_state (on malloc* in /usr/lib64/libc-2.25.so)
You can now use it in all perf tools, such as:
perf record -e probe_libc:malloc_set_state -aR sleep 1
=====
Reported-by: Arnaldo Carvalho de Melo <acme@kernel.org>
Reported-by: bhargavb <bhargavaramudu@gmail.com>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Acked-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Reviewed-by: Thomas Richter <tmricht@linux.vnet.ibm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: linux-rt-users@vger.kernel.org
Link: http://lkml.kernel.org/r/None
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/probe-event.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 262d5da86623..7e582547ac07 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -2584,8 +2584,8 @@ static int get_new_event_name(char *buf, size_t len, const char *base,
if (!nbase)
return -ENOMEM;
- /* Cut off the dot suffixes (e.g. .const, .isra)*/
- p = strchr(nbase, '.');
+ /* Cut off the dot suffixes (e.g. .const, .isra) and version suffixes */
+ p = strpbrk(nbase, ".@");
if (p && p != nbase)
*p = '\0';
--
2.13.6
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 23/35] perf probe: Add __return suffix for return events
2017-12-28 14:29 [GIT PULL 00/35] perf/core improvements and fixes Arnaldo Carvalho de Melo
2017-12-28 14:30 ` [PATCH 21/35] perf probe: Add warning message if there is unexpected event name Arnaldo Carvalho de Melo
2017-12-28 14:30 ` [PATCH 22/35] perf probe: Cut off the version suffix from " Arnaldo Carvalho de Melo
@ 2017-12-28 14:30 ` Arnaldo Carvalho de Melo
2017-12-28 14:30 ` [PATCH 24/35] perf probe: Find versioned symbols from map Arnaldo Carvalho de Melo
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-12-28 14:30 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, linux-perf-users, Masami Hiramatsu, Paul Clarke,
bhargavb, linux-rt-users, Arnaldo Carvalho de Melo
From: Masami Hiramatsu <mhiramat@kernel.org>
Add __return suffix for function return events automatically. Without
this, user have to give --force option and will see the number suffix
for each event like "function_1", which is not easy to recognize.
Instead, this adds __return suffix to it automatically. E.g.
=====
# ./perf probe -x /lib64/libc-2.25.so 'malloc*%return'
Added new events:
probe_libc:malloc_printerr__return (on malloc*%return in /usr/lib64/libc-2.25.so)
probe_libc:malloc_consolidate__return (on malloc*%return in /usr/lib64/libc-2.25.so)
probe_libc:malloc_check__return (on malloc*%return in /usr/lib64/libc-2.25.so)
probe_libc:malloc_hook_ini__return (on malloc*%return in /usr/lib64/libc-2.25.so)
probe_libc:malloc__return (on malloc*%return in /usr/lib64/libc-2.25.so)
probe_libc:malloc_trim__return (on malloc*%return in /usr/lib64/libc-2.25.so)
probe_libc:malloc_usable_size__return (on malloc*%return in /usr/lib64/libc-2.25.so)
probe_libc:malloc_stats__return (on malloc*%return in /usr/lib64/libc-2.25.so)
probe_libc:malloc_info__return (on malloc*%return in /usr/lib64/libc-2.25.so)
probe_libc:mallochook__return (on malloc*%return in /usr/lib64/libc-2.25.so)
probe_libc:malloc_get_state__return (on malloc*%return in /usr/lib64/libc-2.25.so)
probe_libc:malloc_set_state__return (on malloc*%return in /usr/lib64/libc-2.25.so)
You can now use it in all perf tools, such as:
perf record -e probe_libc:malloc_set_state__return -aR sleep 1
=====
Reported-by: Arnaldo Carvalho de Melo <acme@kernel.org>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Acked-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Reviewed-by: Thomas Richter <tmricht@linux.vnet.ibm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: bhargavb <bhargavaramudu@gmail.com>
Cc: linux-rt-users@vger.kernel.org
Link: http://lkml.kernel.org/r/151275046418.24652.6696011972866498489.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/Documentation/perf-probe.txt | 2 +-
tools/perf/util/probe-event.c | 9 +++++----
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
index d7e4869905f1..f96382692f42 100644
--- a/tools/perf/Documentation/perf-probe.txt
+++ b/tools/perf/Documentation/perf-probe.txt
@@ -170,7 +170,7 @@ Probe points are defined by following syntax.
or,
sdt_PROVIDER:SDTEVENT
-'EVENT' specifies the name of new event, if omitted, it will be set the name of the probed function. You can also specify a group name by 'GROUP', if omitted, set 'probe' is used for kprobe and 'probe_<bin>' is used for uprobe.
+'EVENT' specifies the name of new event, if omitted, it will be set the name of the probed function, and for return probes, a "\_\_return" suffix is automatically added to the function name. You can also specify a group name by 'GROUP', if omitted, set 'probe' is used for kprobe and 'probe_<bin>' is used for uprobe.
Note that using existing group name can conflict with other events. Especially, using the group name reserved for kernel modules can hide embedded events in the
modules.
'FUNC' specifies a probed function name, and it may have one of the following options; '+OFFS' is the offset from function entry address in bytes, ':RLN' is the relative-line number from function entry line, and '%return' means that it probes function return. And ';PTN' means lazy matching pattern (see LAZY MATCHING). Note that ';PTN' must be the end of the probe point definition. In addition, '@SRC' specifies a source file which has that function.
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 7e582547ac07..a68141d360b0 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -2573,7 +2573,8 @@ int show_perf_probe_events(struct strfilter *filter)
}
static int get_new_event_name(char *buf, size_t len, const char *base,
- struct strlist *namelist, bool allow_suffix)
+ struct strlist *namelist, bool ret_event,
+ bool allow_suffix)
{
int i, ret;
char *p, *nbase;
@@ -2590,7 +2591,7 @@ static int get_new_event_name(char *buf, size_t len, const char *base,
*p = '\0';
/* Try no suffix number */
- ret = e_snprintf(buf, len, "%s", nbase);
+ ret = e_snprintf(buf, len, "%s%s", nbase, ret_event ? "__return" : "");
if (ret < 0) {
pr_debug("snprintf() failed: %d\n", ret);
goto out;
@@ -2689,8 +2690,8 @@ static int probe_trace_event__set_name(struct probe_trace_event *tev,
group = PERFPROBE_GROUP;
/* Get an unused new event name */
- ret = get_new_event_name(buf, 64, event,
- namelist, allow_suffix);
+ ret = get_new_event_name(buf, 64, event, namelist,
+ tev->point.retprobe, allow_suffix);
if (ret < 0)
return ret;
--
2.13.6
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 24/35] perf probe: Find versioned symbols from map
2017-12-28 14:29 [GIT PULL 00/35] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (2 preceding siblings ...)
2017-12-28 14:30 ` [PATCH 23/35] perf probe: Add __return suffix for return events Arnaldo Carvalho de Melo
@ 2017-12-28 14:30 ` Arnaldo Carvalho de Melo
2017-12-28 14:30 ` [PATCH 25/35] perf string: Add {strdup,strpbrk}_esc() Arnaldo Carvalho de Melo
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-12-28 14:30 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, linux-perf-users, Masami Hiramatsu, Paul Clarke,
bhargavb, linux-rt-users, Arnaldo Carvalho de Melo
From: Masami Hiramatsu <mhiramat@kernel.org>
Commit d80406453ad4 ("perf symbols: Allow user probes on versioned
symbols") allows user to find default versioned symbols (with "@@") in
map. However, it did not enable normal versioned symbol (with "@") for
perf-probe. E.g.
=====
# ./perf probe -x /lib64/libc-2.25.so malloc_get_state
Failed to find symbol malloc_get_state in /usr/lib64/libc-2.25.so
Error: Failed to add events.
=====
This solves above issue by improving perf-probe symbol search function,
as below.
=====
# ./perf probe -x /lib64/libc-2.25.so malloc_get_state
Added new event:
probe_libc:malloc_get_state (on malloc_get_state in /usr/lib64/libc-2.25.so)
You can now use it in all perf tools, such as:
perf record -e probe_libc:malloc_get_state -aR sleep 1
# ./perf probe -l
probe_libc:malloc_get_state (on malloc_get_state@GLIBC_2.2.5 in /usr/lib64/libc-2.25.so)
=====
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Reviewed-by: Thomas Richter <tmricht@linux.vnet.ibm.com>
Acked-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: bhargavb <bhargavaramudu@gmail.com>
Cc: linux-rt-users@vger.kernel.org
Link: http://lkml.kernel.org/r/151275049269.24652.1639103455496216255.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/arch/powerpc/util/sym-handling.c | 8 ++++++++
tools/perf/util/probe-event.c | 20 ++++++++++++++++++--
tools/perf/util/symbol.c | 5 +++++
tools/perf/util/symbol.h | 1 +
4 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/tools/perf/arch/powerpc/util/sym-handling.c b/tools/perf/arch/powerpc/util/sym-handling.c
index 9c4e23d8c8ce..53d83d7e6a09 100644
--- a/tools/perf/arch/powerpc/util/sym-handling.c
+++ b/tools/perf/arch/powerpc/util/sym-handling.c
@@ -64,6 +64,14 @@ int arch__compare_symbol_names_n(const char *namea, const char *nameb,
return strncmp(namea, nameb, n);
}
+
+const char *arch__normalize_symbol_name(const char *name)
+{
+ /* Skip over initial dot */
+ if (name && *name == '.')
+ name++;
+ return name;
+}
#endif
#if defined(_CALL_ELF) && _CALL_ELF == 2
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index a68141d360b0..0d6c66d51939 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -2801,16 +2801,32 @@ static int find_probe_functions(struct map *map, char *name,
int found = 0;
struct symbol *sym;
struct rb_node *tmp;
+ const char *norm, *ver;
+ char *buf = NULL;
if (map__load(map) < 0)
return 0;
map__for_each_symbol(map, sym, tmp) {
- if (strglobmatch(sym->name, name)) {
+ norm = arch__normalize_symbol_name(sym->name);
+ if (!norm)
+ continue;
+
+ /* We don't care about default symbol or not */
+ ver = strchr(norm, '@');
+ if (ver) {
+ buf = strndup(norm, ver - norm);
+ if (!buf)
+ return -ENOMEM;
+ norm = buf;
+ }
+ if (strglobmatch(norm, name)) {
found++;
if (syms && found < probe_conf.max_probes)
syms[found - 1] = sym;
}
+ if (buf)
+ zfree(&buf);
}
return found;
@@ -2856,7 +2872,7 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
* same name but different addresses, this lists all the symbols.
*/
num_matched_functions = find_probe_functions(map, pp->function, syms);
- if (num_matched_functions == 0) {
+ if (num_matched_functions <= 0) {
pr_err("Failed to find symbol %s in %s\n", pp->function,
pev->target ? : "kernel");
ret = -ENOENT;
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 1b67a8639dfe..cc065d4bfafc 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -94,6 +94,11 @@ static int prefix_underscores_count(const char *str)
return tail - str;
}
+const char * __weak arch__normalize_symbol_name(const char *name)
+{
+ return name;
+}
+
int __weak arch__compare_symbol_names(const char *namea, const char *nameb)
{
return strcmp(namea, nameb);
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index a4f0075b4e5c..0563f33c1eb3 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -349,6 +349,7 @@ bool elf__needs_adjust_symbols(GElf_Ehdr ehdr);
void arch__sym_update(struct symbol *s, GElf_Sym *sym);
#endif
+const char *arch__normalize_symbol_name(const char *name);
#define SYMBOL_A 0
#define SYMBOL_B 1
--
2.13.6
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 25/35] perf string: Add {strdup,strpbrk}_esc()
2017-12-28 14:29 [GIT PULL 00/35] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (3 preceding siblings ...)
2017-12-28 14:30 ` [PATCH 24/35] perf probe: Find versioned symbols from map Arnaldo Carvalho de Melo
@ 2017-12-28 14:30 ` Arnaldo Carvalho de Melo
2017-12-28 14:30 ` [PATCH 26/35] perf probe: Support escaped character in parser Arnaldo Carvalho de Melo
2017-12-28 15:17 ` [GIT PULL 00/35] perf/core improvements and fixes Ingo Molnar
6 siblings, 0 replies; 8+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-12-28 14:30 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, linux-perf-users, Masami Hiramatsu, Paul Clarke,
bhargavb, linux-rt-users, Arnaldo Carvalho de Melo
From: Masami Hiramatsu <mhiramat@kernel.org>
To support the special characters escaped by '\' in 'perf probe' event parser.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Reviewed-by: Thomas Richter <tmricht@linux.vnet.ibm.com>
Acked-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: bhargavb <bhargavaramudu@gmail.com>
Cc: linux-rt-users@vger.kernel.org
Link: http://lkml.kernel.org/r/151275052163.24652.18205979384585484358.stgit@devbox
[ Split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/string.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
tools/perf/util/string2.h | 2 ++
2 files changed, 48 insertions(+)
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index aaa08ee8c717..d8bfd0c4d2cb 100644
--- a/tools/perf/util/string.c
+++ b/tools/perf/util/string.c
@@ -396,3 +396,49 @@ char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints
free(expr);
return NULL;
}
+
+/* Like strpbrk(), but not break if it is right after a backslash (escaped) */
+char *strpbrk_esc(char *str, const char *stopset)
+{
+ char *ptr;
+
+ do {
+ ptr = strpbrk(str, stopset);
+ if (ptr == str ||
+ (ptr == str + 1 && *(ptr - 1) != '\\'))
+ break;
+ str = ptr + 1;
+ } while (ptr && *(ptr - 1) == '\\' && *(ptr - 2) != '\\');
+
+ return ptr;
+}
+
+/* Like strdup, but do not copy a single backslash */
+char *strdup_esc(const char *str)
+{
+ char *s, *d, *p, *ret = strdup(str);
+
+ if (!ret)
+ return NULL;
+
+ d = strchr(ret, '\\');
+ if (!d)
+ return ret;
+
+ s = d + 1;
+ do {
+ if (*s == '\0') {
+ *d = '\0';
+ break;
+ }
+ p = strchr(s + 1, '\\');
+ if (p) {
+ memmove(d, s, p - s);
+ d += p - s;
+ s = p + 1;
+ } else
+ memmove(d, s, strlen(s) + 1);
+ } while (p);
+
+ return ret;
+}
diff --git a/tools/perf/util/string2.h b/tools/perf/util/string2.h
index ee14ca5451ab..4c68a09b97e8 100644
--- a/tools/perf/util/string2.h
+++ b/tools/perf/util/string2.h
@@ -39,5 +39,7 @@ static inline char *asprintf_expr_not_in_ints(const char *var, size_t nints, int
return asprintf_expr_inout_ints(var, false, nints, ints);
}
+char *strpbrk_esc(char *str, const char *stopset);
+char *strdup_esc(const char *str);
#endif /* PERF_STRING_H */
--
2.13.6
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 26/35] perf probe: Support escaped character in parser
2017-12-28 14:29 [GIT PULL 00/35] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (4 preceding siblings ...)
2017-12-28 14:30 ` [PATCH 25/35] perf string: Add {strdup,strpbrk}_esc() Arnaldo Carvalho de Melo
@ 2017-12-28 14:30 ` Arnaldo Carvalho de Melo
2017-12-28 15:17 ` [GIT PULL 00/35] perf/core improvements and fixes Ingo Molnar
6 siblings, 0 replies; 8+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-12-28 14:30 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, linux-perf-users, Masami Hiramatsu, Paul Clarke,
bhargavb, linux-rt-users, Arnaldo Carvalho de Melo
From: Masami Hiramatsu <mhiramat@kernel.org>
Support the special characters escaped by '\' in parser. This allows
user to specify versions directly like below.
=====
# ./perf probe -x /lib64/libc-2.25.so malloc_get_state\\@GLIBC_2.2.5
Added new event:
probe_libc:malloc_get_state (on malloc_get_state@GLIBC_2.2.5 in /usr/lib64/libc-2.25.so)
You can now use it in all perf tools, such as:
perf record -e probe_libc:malloc_get_state -aR sleep 1
=====
Or, you can use separators in source filename, e.g.
=====
# ./perf probe -x /opt/test/a.out foo+bar.c:3
Semantic error :There is non-digit character in offset.
Error: Command Parse Error.
=====
Usually "+" in source file cause parser error, but
=====
# ./perf probe -x /opt/test/a.out foo\\+bar.c:4
Added new event:
probe_a:main (on @foo+bar.c:4 in /opt/test/a.out)
You can now use it in all perf tools, such as:
perf record -e probe_a:main -aR sleep 1
=====
escaped "\+" allows you to specify that.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Reviewed-by: Thomas Richter <tmricht@linux.vnet.ibm.com>
Acked-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: bhargavb <bhargavaramudu@gmail.com>
Cc: linux-rt-users@vger.kernel.org
Link: http://lkml.kernel.org/r/151309111236.18107.5634753157435343410.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/Documentation/perf-probe.txt | 16 +++++++++
tools/perf/util/probe-event.c | 58 ++++++++++++++++++++-------------
2 files changed, 51 insertions(+), 23 deletions(-)
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
index f96382692f42..b6866a05edd2 100644
--- a/tools/perf/Documentation/perf-probe.txt
+++ b/tools/perf/Documentation/perf-probe.txt
@@ -182,6 +182,14 @@ Note that before using the SDT event, the target binary (on which SDT events are
For details of the SDT, see below.
https://sourceware.org/gdb/onlinedocs/gdb/Static-Probe-Points.html
+ESCAPED CHARACTER
+-----------------
+
+In the probe syntax, '=', '@', '+', ':' and ';' are treated as a special character. You can use a backslash ('\') to escape the special characters.
+This is useful if you need to probe on a specific versioned symbols, like @GLIBC_... suffixes, or also you need to specify a source file which includes the special characters.
+Note that usually single backslash is consumed by shell, so you might need to pass double backslash (\\) or wrapping with single quotes (\'AAA\@BBB').
+See EXAMPLES how it is used.
+
PROBE ARGUMENT
--------------
Each probe argument follows below syntax.
@@ -277,6 +285,14 @@ Add a USDT probe to a target process running in a different mount namespace
./perf probe --target-ns <target pid> -x /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el7_3.x86_64/jre/lib/amd64/server/libjvm.so %sdt_hotspot:thread__sleep__end
+Add a probe on specific versioned symbol by backslash escape
+
+ ./perf probe -x /lib64/libc-2.25.so 'malloc_get_state\@GLIBC_2.2.5'
+
+Add a probe in a source file using special characters by backslash escape
+
+ ./perf probe -x /opt/test/a.out 'foo\+bar.c:4'
+
SEE ALSO
--------
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 0d6c66d51939..e1dbc9821617 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -1325,27 +1325,30 @@ static int parse_perf_probe_event_name(char **arg, struct perf_probe_event *pev)
{
char *ptr;
- ptr = strchr(*arg, ':');
+ ptr = strpbrk_esc(*arg, ":");
if (ptr) {
*ptr = '\0';
if (!pev->sdt && !is_c_func_name(*arg))
goto ng_name;
- pev->group = strdup(*arg);
+ pev->group = strdup_esc(*arg);
if (!pev->group)
return -ENOMEM;
*arg = ptr + 1;
} else
pev->group = NULL;
- if (!pev->sdt && !is_c_func_name(*arg)) {
+
+ pev->event = strdup_esc(*arg);
+ if (pev->event == NULL)
+ return -ENOMEM;
+
+ if (!pev->sdt && !is_c_func_name(pev->event)) {
+ zfree(&pev->event);
ng_name:
+ zfree(&pev->group);
semantic_error("%s is bad for event name -it must "
"follow C symbol-naming rule.\n", *arg);
return -EINVAL;
}
- pev->event = strdup(*arg);
- if (pev->event == NULL)
- return -ENOMEM;
-
return 0;
}
@@ -1373,7 +1376,7 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
arg++;
}
- ptr = strpbrk(arg, ";=@+%");
+ ptr = strpbrk_esc(arg, ";=@+%");
if (pev->sdt) {
if (ptr) {
if (*ptr != '@') {
@@ -1387,7 +1390,7 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
pev->target = build_id_cache__origname(tmp);
free(tmp);
} else
- pev->target = strdup(ptr + 1);
+ pev->target = strdup_esc(ptr + 1);
if (!pev->target)
return -ENOMEM;
*ptr = '\0';
@@ -1421,13 +1424,14 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
*
* Otherwise, we consider arg to be a function specification.
*/
- if (!strpbrk(arg, "+@%") && (ptr = strpbrk(arg, ";:")) != NULL) {
+ if (!strpbrk_esc(arg, "+@%")) {
+ ptr = strpbrk_esc(arg, ";:");
/* This is a file spec if it includes a '.' before ; or : */
- if (memchr(arg, '.', ptr - arg))
+ if (ptr && memchr(arg, '.', ptr - arg))
file_spec = true;
}
- ptr = strpbrk(arg, ";:+@%");
+ ptr = strpbrk_esc(arg, ";:+@%");
if (ptr) {
nc = *ptr;
*ptr++ = '\0';
@@ -1436,7 +1440,7 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
if (arg[0] == '\0')
tmp = NULL;
else {
- tmp = strdup(arg);
+ tmp = strdup_esc(arg);
if (tmp == NULL)
return -ENOMEM;
}
@@ -1469,12 +1473,12 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
arg = ptr;
c = nc;
if (c == ';') { /* Lazy pattern must be the last part */
- pp->lazy_line = strdup(arg);
+ pp->lazy_line = strdup(arg); /* let leave escapes */
if (pp->lazy_line == NULL)
return -ENOMEM;
break;
}
- ptr = strpbrk(arg, ";:+@%");
+ ptr = strpbrk_esc(arg, ";:+@%");
if (ptr) {
nc = *ptr;
*ptr++ = '\0';
@@ -1501,7 +1505,7 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
semantic_error("SRC@SRC is not allowed.\n");
return -EINVAL;
}
- pp->file = strdup(arg);
+ pp->file = strdup_esc(arg);
if (pp->file == NULL)
return -ENOMEM;
break;
@@ -2803,23 +2807,31 @@ static int find_probe_functions(struct map *map, char *name,
struct rb_node *tmp;
const char *norm, *ver;
char *buf = NULL;
+ bool cut_version = true;
if (map__load(map) < 0)
return 0;
+ /* If user gives a version, don't cut off the version from symbols */
+ if (strchr(name, '@'))
+ cut_version = false;
+
map__for_each_symbol(map, sym, tmp) {
norm = arch__normalize_symbol_name(sym->name);
if (!norm)
continue;
- /* We don't care about default symbol or not */
- ver = strchr(norm, '@');
- if (ver) {
- buf = strndup(norm, ver - norm);
- if (!buf)
- return -ENOMEM;
- norm = buf;
+ if (cut_version) {
+ /* We don't care about default symbol or not */
+ ver = strchr(norm, '@');
+ if (ver) {
+ buf = strndup(norm, ver - norm);
+ if (!buf)
+ return -ENOMEM;
+ norm = buf;
+ }
}
+
if (strglobmatch(norm, name)) {
found++;
if (syms && found < probe_conf.max_probes)
--
2.13.6
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [GIT PULL 00/35] perf/core improvements and fixes
2017-12-28 14:29 [GIT PULL 00/35] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (5 preceding siblings ...)
2017-12-28 14:30 ` [PATCH 26/35] perf probe: Support escaped character in parser Arnaldo Carvalho de Melo
@ 2017-12-28 15:17 ` Ingo Molnar
6 siblings, 0 replies; 8+ messages in thread
From: Ingo Molnar @ 2017-12-28 15:17 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: linux-kernel, linux-perf-users, Adrian Hunter, Alexander Shishkin,
Andi Kleen, bhargavb, Cheng Jian, David Ahern, David S . Miller,
Ganapatrao Kulkarni, Greg Kroah-Hartman, Heiko Carstens,
Hendrik Brueckner, Jin Yao, Jiri Olsa, Jonathan Hermann,
Kan Liang, Kim Phillips, Li Bin
* Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> Hi Ingo,
>
> Please consider pulling,
>
> - Arnaldo
>
>
> Test results at the end of this message, as usual.
>
> The following changes since commit faaf95677f33dac910b6cbe917cabea43c8c1616:
>
> Merge branch 'perf/urgent' into perf/core, to pick up fixes (2017-12-18 18:13:00 +0100)
>
> are available in the git repository at:
>
> git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-core-for-mingo-4.16-20171227
>
> for you to fetch changes up to 5d4fd9c8b83b36d34521b3af361a5726899045bf:
>
> perf tools: Auto-complete for events with ':' (2017-12-27 12:16:00 -0300)
>
> ----------------------------------------------------------------
> perf/core improvements and fixes:
>
> - Allow system wide 'perf stat --per-thread', sorting the result (Jin Yao)
>
> E.g.:
>
> [root@jouet ~]# perf stat --per-thread --metrics IPC
> ^C
> Performance counter stats for 'system wide':
>
> make-22229 23,012,094,032 inst_retired.any # 0.8 IPC
> cc1-22419 692,027,497 inst_retired.any # 0.8 IPC
> gcc-22418 328,231,855 inst_retired.any # 0.9 IPC
> cc1-22509 220,853,647 inst_retired.any # 0.8 IPC
> gcc-22486 199,874,810 inst_retired.any # 1.0 IPC
> as-22466 177,896,365 inst_retired.any # 0.9 IPC
> cc1-22465 150,732,374 inst_retired.any # 0.8 IPC
> gcc-22508 112,555,593 inst_retired.any # 0.9 IPC
> cc1-22487 108,964,079 inst_retired.any # 0.7 IPC
> qemu-system-x86-2697 21,330,550 inst_retired.any # 0.3 IPC
> systemd-journal-551 20,642,951 inst_retired.any # 0.4 IPC
> docker-containe-17651 9,552,892 inst_retired.any # 0.5 IPC
> dockerd-current-9809 7,528,586 inst_retired.any # 0.5 IPC
> make-22153 12,504,194,380 inst_retired.any # 0.8 IPC
> python2-22429 12,081,290,954 inst_retired.any # 0.8 IPC
> <SNIP>
> python2-22429 15,026,328,103 cpu_clk_unhalted.thread
> cc1-22419 826,660,193 cpu_clk_unhalted.thread
> gcc-22418 365,321,295 cpu_clk_unhalted.thread
> cc1-22509 279,169,362 cpu_clk_unhalted.thread
> gcc-22486 210,156,950 cpu_clk_unhalted.thread
> <SNIP>
>
> 5.638075538 seconds time elapsed
>
> [root@jouet ~]#
>
> - Improve shell auto-completion of perf events (Jin Yao)
>
> - Fix symbol fixup issues in arm64 due to ELF type (Kim Phillips)
>
> - Ignore threads when they vanish after procfs based enumeration and
> before we try to use them with sys_perf_event_open(), i.e. just remove
> them from the thread_map and continue with the rest. This makes, among
> other cases, the previous new feature (perf stat --per-thread for system
> wide, albeit that not seeming to be the motivation for this patch) more
> robust. (Mengting Zhang)
>
> - Generate s390 syscall table from asm/unistd.h, doing like x86,
> removing the dependency on audit-libs to do this id->string translation,
> speeding up the support for newly introducted syscalls (Hendrik Brueckner)
>
> - Fix 'perf test' on filesystems where readdir() returns d_type == DT_UNKNOWN,
> such as XFS (Jiri Olsa)
>
> - Fix PERF_SAMPLE_RAW_DATA endianity handling for cross-arch tracepoint
> processing (Jiri Olsa)
>
> - Add __return suffix for return events in 'perf probe', streamlining
> entry/exit tracing (Masami Hiramatsu)
>
> - Improve support for versioned symbols in 'perf probe" (Masami Hiramatsu)
>
> - Clarify error message about invalid 'perf probe' event names (Masami Hiramatsu)
>
> - Fix check open filename arg using 'perf trace' in a 'perf test' entry for
> systems using glibc >= 2.26, such as some ARM and s390 distros (Michael Petlan)
>
> - Make method for obtaining the (normalized) architecture id for a
> perf.data file or for the running system used by the annotation routines
> generally available, next user will be for generating per arch errno
> string tables to allow for pretty printing errno codes recorded in a
> perf.data file in architecture A to be properly decoded on hardware
> archictecture B. (Arnaldo Carvalho de Melo)
>
> - Remove duplicate includes, found using scripts/checkincludes.pl (Pravin Shedge)
>
> - s390 needs -fPIC, enable it, also revert a patch that supposedly did
> that but instead enabled -fPIC for x86 (Hendrik Brueckner, Arnaldo Carvalho de Melo)
>
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
>
> ----------------------------------------------------------------
> Arnaldo Carvalho de Melo (4):
> perf annotate: Get the cpuid from evsel->evlist->env in symbol__annotate()
> perf annotate: Use perf_env when obtaining the arch name
> perf env: Adopt perf_env__arch() from the annotate code
> Revert "perf s390: Always build with -fPIC"
>
> Hendrik Brueckner (4):
> tools include s390: Grab a copy of arch/s390/include/uapi/asm/unistd.h
> perf s390: Generate system call table from asm/unistd.h
> perf trace: Use generated syscall table on s390 too
> perf s390: Always build with -fPIC
>
> Jin Yao (14):
> perf stat: Define a structure for per-thread shadow stats
> perf stat: Extend rbtree to support per-thread shadow stats
> perf stat: Create the runtime_stat init/exit function
> perf stat: Update per-thread shadow stats
> perf stat: Print per-thread shadow stats
> perf stat: Remove a set of shadow stats static variables
> perf stat: Allocate shadow stats buffer for threads
> perf stat: Update or print per-thread stats
> perf thread_map: Enumerate all threads from /proc
> perf stat: Remove --per-thread pid/tid limitation
> perf stat: Resort '--per-thread' result
> perf tool: Improve bash command line auto-complete for multiple events with comma
> perf tools: Return all events as auto-completions after comma
> perf tools: Auto-complete for events with ':'
>
> Jiri Olsa (3):
> perf utils: Move is_directory() to path.h
> perf test: Handle properly readdir DT_UNKNOWN
> perf evsel: Fix swap for samples with raw data
>
> Kim Phillips (1):
> perf probe arm64: Fix symbol fixup issues due to ELF type
>
> Masami Hiramatsu (6):
> perf probe: Add warning message if there is unexpected event name
> perf probe: Cut off the version suffix from event name
> perf probe: Add __return suffix for return events
> perf probe: Find versioned symbols from map
> perf string: Add {strdup,strpbrk}_esc()
> perf probe: Support escaped character in parser
>
> Mengting Zhang (1):
> perf evsel: Enable ignore_missing_thread for pid option
>
> Michael Petlan (1):
> perf test shell: Fix check open filename arg using 'perf trace'
>
> Pravin Shedge (1):
> perf perf: Remove duplicate includes
>
> tools/arch/s390/include/uapi/asm/unistd.h | 412 ++++++++++++++++++++
> tools/perf/Documentation/perf-probe.txt | 18 +-
> tools/perf/Makefile.config | 11 +-
> tools/perf/arch/arm64/util/Build | 1 +
> tools/perf/arch/arm64/util/sym-handling.c | 22 ++
> tools/perf/arch/common.c | 44 +--
> tools/perf/arch/common.h | 1 -
> tools/perf/arch/powerpc/util/sym-handling.c | 8 +
> tools/perf/arch/s390/Makefile | 21 ++
> tools/perf/arch/s390/entry/syscalls/mksyscalltbl | 36 ++
> tools/perf/bench/futex-hash.c | 1 -
> tools/perf/builtin-c2c.c | 3 -
> tools/perf/builtin-record.c | 5 +-
> tools/perf/builtin-script.c | 20 +-
> tools/perf/builtin-stat.c | 168 +++++++--
> tools/perf/builtin-top.c | 2 +-
> tools/perf/check-headers.sh | 1 +
> tools/perf/perf-completion.sh | 47 ++-
> tools/perf/tests/builtin-test.c | 10 +-
> tools/perf/tests/parse-events.c | 1 -
> tools/perf/tests/shell/trace+probe_vfs_getname.sh | 7 +-
> tools/perf/tests/thread-map.c | 2 +-
> tools/perf/ui/browsers/annotate.c | 4 +-
> tools/perf/ui/gtk/annotate.c | 2 +-
> tools/perf/util/annotate.c | 26 +-
> tools/perf/util/annotate.h | 2 +-
> tools/perf/util/auxtrace.c | 3 -
> tools/perf/util/env.c | 47 +++
> tools/perf/util/env.h | 2 +
> tools/perf/util/evlist.c | 3 +-
> tools/perf/util/evsel.c | 80 +++-
> tools/perf/util/evsel.h | 3 +-
> tools/perf/util/header.c | 2 -
> tools/perf/util/metricgroup.c | 2 -
> tools/perf/util/path.c | 14 +
> tools/perf/util/path.h | 3 +
> tools/perf/util/probe-event.c | 85 +++--
> tools/perf/util/python-ext-sources | 1 +
> .../util/scripting-engines/trace-event-python.c | 1 -
> tools/perf/util/stat-shadow.c | 416 ++++++++++++---------
> tools/perf/util/stat.c | 15 +-
> tools/perf/util/stat.h | 63 +++-
> tools/perf/util/string.c | 46 +++
> tools/perf/util/string2.h | 2 +
> tools/perf/util/symbol.c | 5 +
> tools/perf/util/symbol.h | 1 +
> tools/perf/util/syscalltbl.c | 4 +
> tools/perf/util/target.h | 7 +
> tools/perf/util/thread_map.c | 5 +-
> tools/perf/util/thread_map.h | 2 +-
> tools/perf/util/unwind-libunwind.c | 4 +-
> 51 files changed, 1328 insertions(+), 363 deletions(-)
> create mode 100644 tools/arch/s390/include/uapi/asm/unistd.h
> create mode 100644 tools/perf/arch/arm64/util/sym-handling.c
> create mode 100755 tools/perf/arch/s390/entry/syscalls/mksyscalltbl
Pulled, thanks a lot Arnaldo!
Ingo
^ permalink raw reply [flat|nested] 8+ messages in thread