Skip to contentSkip to conversation

perf/probe: Provide perf interface for uprobes

PATCH In review Srikar Dronamraju 1 participant 4 messages Apr 16, 2012 – May 14, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 perf/probe: Provide perf interface for uprobes

From: Srikar Dronamraju <[email protected]>

- Enhances perf to probe user space executables and libraries.
- Enhances -F/--funcs option of "perf probe" to list possible probe points in an executable file or library.
- Documents userspace probing support in perf.

[ Probing a function in the executable using function name ] perf probe -x /bin/zsh zfree

[ Probing a library function using function name ] perf probe -x /lib64/libc.so.6 malloc

[ list probe-able functions in an executable ]
perf probe -F -x /bin/zsh

[ list probe-able functions in an library]
perf probe -F -x /lib/libc.so.6

---

Changelog:
(v9)
- Handled comments from Masami Hiramatsu that helps reduce code changes.
- Handled usability comment(print complete name of file) from Ingo Molnar.

(v5)
- Removed the separate documentation change patch and added the documentation changes as part of this patch.

Usage:
[root@localhost ~]# perf probe -x /bin/zsh zfree
Add new event:
probe_zsh:zfree (on /bin/zsh:0x45400)

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

perf record -e probe_zsh:zfree -aR sleep 1

[root@localhost ~]# perf record -e probe_zsh:zfree -aR sleep 15 [ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.314 MB perf.data (~13715 samples) ] [root@localhost ~]# perf report --stdio
# Events: 3K probe_zsh:zfree
#

# Overhead  Command  Shared Object  Symbol
# ........  .......  .............  ......

#
100.00% zsh zsh [.] zfree

#
# (For a higher level overview, try: perf report --sort comm,dso) #
[root@localhost ~]

[ Probing a library function using function name ]
--------------------------------------------------
[root@localhost]#

[root@localhost]# perf probe -x /lib64/libc.so.6 malloc
Add new event:
  probe_libc:malloc    (on /lib64/libc-2.5.so:0x74dc0)

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

perf record -e probe_libc:malloc -aR sleep 1

[root@localhost]#

[root@localhost]# perf probe --list
  probe_libc:malloc    (on /lib64/libc-2.5.so:0x0000000000074dc0)

Show last 10 functions in /bin/zsh.

# perf probe -F -x /bin/zsh | tail
zstrtol
ztrcmp
ztrdup
ztrduppfx
ztrftime
ztrlen
ztrncpy
ztrsub
zwarn
zwarnnam

Show first 10 functions in /lib/libc.so.6

# perf probe -F -x /lib/libc.so.6 | head
_IO_adjust_column
_IO_adjust_wcolumn
_IO_default_doallocate
_IO_default_finish
_IO_default_pbackfail
_IO_default_uflow
_IO_default_xsgetn
_IO_default_xsputn
_IO_do_write@@GLIBC_2.2.5
_IO_doallocbuf
 tools/perf/Documentation/perf-probe.txt |   15 +
 tools/perf/builtin-probe.c              |   43 +++
 tools/perf/util/probe-event.c           |  422 +++++++++++++++++++++++++------
 tools/perf/util/probe-event.h           |   12 +
 tools/perf/util/symbol.c                |    8 +
 tools/perf/util/symbol.h                |    1 
 6 files changed, 403 insertions(+), 98 deletions(-)
tools/perf/Documentation/perf-probe.txt +14 -1
index 2780d9c..fb673be 100644
@@ -77,7 +77,8 @@ OPTIONS
 
 -F::
 --funcs::
-	Show available functions in given module or kernel.
+	Show available functions in given module or kernel. With -x/--exec,
+	can also list functions in a user space executable / shared library.
 
 --filter=FILTER::
 	(Only for --vars and --funcs) Set filter. FILTER is a combination of glob
@@ -98,6 +99,11 @@ OPTIONS
 --max-probes::
 	Set the maximum number of probe points for an event. Default is 128.
 
+-x::
+--exec=PATH::
+	Specify path to the executable or shared library file for user
+	space tracing. Can also be used with --funcs option.
+
 PROBE SYNTAX
 ------------
 Probe points are defined by following syntax.
@@ -182,6 +188,13 @@ Delete all probes on schedule().
 
  ./perf probe --del='schedule*'
 
+Add probes at zfree() function on /bin/zsh
+
+ ./perf probe -x /bin/zsh zfree
+
+Add probes at malloc() function on libc
+
+ ./perf probe -x /lib/libc.so.6 malloc
 
 SEE ALSO
 --------
tools/perf/builtin-probe.c +37 -6

91 lines not on this page · raw message

tools/perf/util/probe-event.c +336 -86

638 lines not on this page · raw message

tools/perf/util/probe-event.h +7 -5
index a7dee83..f9f3de8 100644
@@ -7,7 +7,7 @@
 
 extern bool probe_event_dry_run;
 
-/* kprobe-tracer tracing point */
+/* kprobe-tracer and uprobe-tracer tracing point */
 struct probe_trace_point {
 	char		*symbol;	/* Base symbol */
 	char		*module;	/* Module name */
@@ -21,7 +21,7 @@ struct probe_trace_arg_ref {
 	long				offset;	/* Offset value */
 };
 
-/* kprobe-tracer tracing argument */
+/* kprobe-tracer and uprobe-tracer tracing argument */
 struct probe_trace_arg {
 	char				*name;	/* Argument name */
 	char				*value;	/* Base value */
@@ -29,12 +29,13 @@ struct probe_trace_arg {
 	struct probe_trace_arg_ref	*ref;	/* Referencing offset */
 };
 
-/* kprobe-tracer tracing event (point + arg) */
+/* kprobe-tracer and uprobe-tracer tracing event (point + arg) */
 struct probe_trace_event {
 	char				*event;	/* Event name */
 	char				*group;	/* Group name */
 	struct probe_trace_point	point;	/* Trace point */
 	int				nargs;	/* Number of args */
+	bool				uprobes;	/* uprobes only */
 	struct probe_trace_arg		*args;	/* Arguments */
 };
 
@@ -70,6 +71,7 @@ struct perf_probe_event {
 	char			*group;	/* Group name */
 	struct perf_probe_point	point;	/* Probe point */
 	int			nargs;	/* Number of arguments */
+	bool			uprobes;
 	struct perf_probe_arg	*args;	/* Arguments */
 };
 
@@ -129,8 +131,8 @@ extern int show_line_range(struct line_range *lr, const char *module);
 extern int show_available_vars(struct perf_probe_event *pevs, int npevs,
 			       int max_probe_points, const char *module,
 			       struct strfilter *filter, bool externs);
-extern int show_available_funcs(const char *module, struct strfilter *filter);
-
+extern int show_available_funcs(const char *module, struct strfilter *filter,
+				bool user);
 
 /* Maximum index number of event-name postfix */
 #define MAX_EVENT_INDEX	1024
tools/perf/util/symbol.c +8 -0
index c0a028c..caaf75a 100644
@@ -2784,3 +2784,11 @@ int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
 
 	return ret;
 }
+
+struct map *dso__new_map(const char *name)
+{
+	struct dso *dso = dso__new(name);
+	struct map *map = map__new2(0, dso, MAP__FUNCTION);
+
+	return map;
+}
tools/perf/util/symbol.h +1 -0
index ac49ef2..9e7742c 100644
@@ -237,6 +237,7 @@ void dso__set_long_name(struct dso *dso, char *name);
 void dso__set_build_id(struct dso *dso, void *build_id);
 void dso__read_running_kernel_build_id(struct dso *dso,
 				       struct machine *machine);
+struct map *dso__new_map(const char *name);
 struct symbol *dso__find_symbol(struct dso *dso, enum map_type type,
 				u64 addr);
 struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw

RFC PATCH 2/2 perf/probe: Detect probe target when m/x options are absent

From: Srikar Dronamraju <[email protected]>

Options -m and -x explicitly allow tracing of modules / user space binaries. In absense of these options, check if the first argument can be used as a target.

perf probe /bin/zsh zfree is equivalent to perf probe -x /bin/zsh zfree.

---
 tools/perf/Documentation/perf-probe.txt |    8 ++++--
 tools/perf/builtin-probe.c              |   43 +++++++++++++++++++++++++++++--
 2 files changed, 46 insertions(+), 5 deletions(-)
tools/perf/Documentation/perf-probe.txt +6 -2
index fb673be..51205f0 100644
@@ -104,6 +104,10 @@ OPTIONS
 	Specify path to the executable or shared library file for user
 	space tracing. Can also be used with --funcs option.
 
+In absence of -m/-x options, perf probe checks if the first argument after
+the options is an absolute path name. If its an absolute path, perf probe
+uses it as a target module/target user space binary to probe.
+
 PROBE SYNTAX
 ------------
 Probe points are defined by following syntax.
@@ -190,11 +194,11 @@ Delete all probes on schedule().
 
 Add probes at zfree() function on /bin/zsh
 
- ./perf probe -x /bin/zsh zfree
+ ./perf probe -x /bin/zsh zfree or ./perf probe /bin/zsh zfree
 
 Add probes at malloc() function on libc
 
- ./perf probe -x /lib/libc.so.6 malloc
+ ./perf probe -x /lib/libc.so.6 malloc or ./perf probe /lib/libc.so.6 malloc
 
 SEE ALSO
 --------
tools/perf/builtin-probe.c +40 -3

61 lines not on this page · raw message

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw

[tip:perf/uprobes] perf probe: Detect probe target when m/ x options are absent

Commit-ID:  73eff9f56e15598c8399c0b86899fd889b97f085
Gitweb:     http://git.kernel.org/tip/73eff9f56e15598c8399c0b86899fd889b97f085
Author:     Srikar Dronamraju <[email protected]>
AuthorDate: Mon, 16 Apr 2012 17:39:25 +0530
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 11 May 2012 13:58:53 -0300

perf probe: Detect probe target when m/x options are absent

Options -m and -x explicitly allow tracing of modules / user space binaries. In absense of these options, check if the first argument can be used as a target.

perf probe /bin/zsh zfree is equivalent to perf probe -x /bin/zsh zfree.

Cc Ananth N Mavinakayanahalli <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Anton Arapov <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Jim Keniston <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Linux-mm <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 tools/perf/Documentation/perf-probe.txt |    8 ++++-
 tools/perf/builtin-probe.c              |   43 ++++++++++++++++++++++++++++--
 2 files changed, 46 insertions(+), 5 deletions(-)
tools/perf/Documentation/perf-probe.txt +6 -2
index fb673be..b715cb7 100644
@@ -104,6 +104,10 @@ OPTIONS
 	Specify path to the executable or shared library file for user
 	space tracing. Can also be used with --funcs option.
 
+In absence of -m/-x options, perf probe checks if the first argument after
+the options is an absolute path name. If its an absolute path, perf probe
+uses it as a target module/target user space binary to probe.
+
 PROBE SYNTAX
 ------------
 Probe points are defined by following syntax.
@@ -190,11 +194,11 @@ Delete all probes on schedule().
 
 Add probes at zfree() function on /bin/zsh
 
- ./perf probe -x /bin/zsh zfree
+ ./perf probe -x /bin/zsh zfree or ./perf probe /bin/zsh zfree
 
 Add probes at malloc() function on libc
 
- ./perf probe -x /lib/libc.so.6 malloc
+ ./perf probe -x /lib/libc.so.6 malloc or ./perf probe /lib/libc.so.6 malloc
 
 SEE ALSO
 --------
tools/perf/builtin-probe.c +40 -3

61 lines not on this page · raw message

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw

[tip:perf/uprobes] perf probe: Provide perf interface for uprobes

In reply to Srikar Dronamraju
Commit-ID:  225466f1c2d816c33b4341008f45dfdc83a9f0cb
Gitweb:     http://git.kernel.org/tip/225466f1c2d816c33b4341008f45dfdc83a9f0cb
Author:     Srikar Dronamraju <[email protected]>
AuthorDate: Mon, 16 Apr 2012 17:39:09 +0530
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 11 May 2012 13:58:17 -0300

perf probe: Provide perf interface for uprobes

- Enhances perf to probe user space executables and libraries.
- Enhances -F/--funcs option of "perf probe" to list possible probe points in an executable file or library.
- Documents userspace probing support in perf.

[ Probing a function in the executable using function name ] perf probe -x /bin/zsh zfree

[ Probing a library function using function name ] perf probe -x /lib64/libc.so.6 malloc

[ list probe-able functions in an executable ]
perf probe -F -x /bin/zsh

[ list probe-able functions in an library]
perf probe -F -x /lib/libc.so.6

Cc Ananth N Mavinakayanahalli <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Anton Arapov <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Jim Keniston <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Linux-mm <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 tools/perf/Documentation/perf-probe.txt |   15 +-
 tools/perf/builtin-probe.c              |   43 +++-
 tools/perf/util/probe-event.c           |  422 ++++++++++++++++++++++++-------
 tools/perf/util/probe-event.h           |   12 +-
 tools/perf/util/symbol.c                |    8 +
 tools/perf/util/symbol.h                |    1 +
 6 files changed, 403 insertions(+), 98 deletions(-)
tools/perf/Documentation/perf-probe.txt +14 -1
index 2780d9c..fb673be 100644
@@ -77,7 +77,8 @@ OPTIONS
 
 -F::
 --funcs::
-	Show available functions in given module or kernel.
+	Show available functions in given module or kernel. With -x/--exec,
+	can also list functions in a user space executable / shared library.
 
 --filter=FILTER::
 	(Only for --vars and --funcs) Set filter. FILTER is a combination of glob
@@ -98,6 +99,11 @@ OPTIONS
 --max-probes::
 	Set the maximum number of probe points for an event. Default is 128.
 
+-x::
+--exec=PATH::
+	Specify path to the executable or shared library file for user
+	space tracing. Can also be used with --funcs option.
+
 PROBE SYNTAX
 ------------
 Probe points are defined by following syntax.
@@ -182,6 +188,13 @@ Delete all probes on schedule().
 
  ./perf probe --del='schedule*'
 
+Add probes at zfree() function on /bin/zsh
+
+ ./perf probe -x /bin/zsh zfree
+
+Add probes at malloc() function on libc
+
+ ./perf probe -x /lib/libc.so.6 malloc
 
 SEE ALSO
 --------
tools/perf/builtin-probe.c +37 -6

91 lines not on this page · raw message

tools/perf/util/probe-event.c +336 -86

638 lines not on this page · raw message

tools/perf/util/probe-event.h +7 -5
index a7dee83..f9f3de8 100644
@@ -7,7 +7,7 @@
 
 extern bool probe_event_dry_run;
 
-/* kprobe-tracer tracing point */
+/* kprobe-tracer and uprobe-tracer tracing point */
 struct probe_trace_point {
 	char		*symbol;	/* Base symbol */
 	char		*module;	/* Module name */
@@ -21,7 +21,7 @@ struct probe_trace_arg_ref {
 	long				offset;	/* Offset value */
 };
 
-/* kprobe-tracer tracing argument */
+/* kprobe-tracer and uprobe-tracer tracing argument */
 struct probe_trace_arg {
 	char				*name;	/* Argument name */
 	char				*value;	/* Base value */
@@ -29,12 +29,13 @@ struct probe_trace_arg {
 	struct probe_trace_arg_ref	*ref;	/* Referencing offset */
 };
 
-/* kprobe-tracer tracing event (point + arg) */
+/* kprobe-tracer and uprobe-tracer tracing event (point + arg) */
 struct probe_trace_event {
 	char				*event;	/* Event name */
 	char				*group;	/* Group name */
 	struct probe_trace_point	point;	/* Trace point */
 	int				nargs;	/* Number of args */
+	bool				uprobes;	/* uprobes only */
 	struct probe_trace_arg		*args;	/* Arguments */
 };
 
@@ -70,6 +71,7 @@ struct perf_probe_event {
 	char			*group;	/* Group name */
 	struct perf_probe_point	point;	/* Probe point */
 	int			nargs;	/* Number of arguments */
+	bool			uprobes;
 	struct perf_probe_arg	*args;	/* Arguments */
 };
 
@@ -129,8 +131,8 @@ extern int show_line_range(struct line_range *lr, const char *module);
 extern int show_available_vars(struct perf_probe_event *pevs, int npevs,
 			       int max_probe_points, const char *module,
 			       struct strfilter *filter, bool externs);
-extern int show_available_funcs(const char *module, struct strfilter *filter);
-
+extern int show_available_funcs(const char *module, struct strfilter *filter,
+				bool user);
 
 /* Maximum index number of event-name postfix */
 #define MAX_EVENT_INDEX	1024
tools/perf/util/symbol.c +8 -0
index c0a028c..caaf75a 100644
@@ -2784,3 +2784,11 @@ int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
 
 	return ret;
 }
+
+struct map *dso__new_map(const char *name)
+{
+	struct dso *dso = dso__new(name);
+	struct map *map = map__new2(0, dso, MAP__FUNCTION);
+
+	return map;
+}
tools/perf/util/symbol.h +1 -0
index 1f00388..5649d63 100644
@@ -242,6 +242,7 @@ void dso__set_long_name(struct dso *dso, char *name);
 void dso__set_build_id(struct dso *dso, void *build_id);
 void dso__read_running_kernel_build_id(struct dso *dso,
 				       struct machine *machine);
+struct map *dso__new_map(const char *name);
 struct symbol *dso__find_symbol(struct dso *dso, enum map_type type,
 				u64 addr);
 struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>