2009-12-01 08:19:58 +08:00
|
|
|
#ifndef _PROBE_EVENT_H
|
|
|
|
#define _PROBE_EVENT_H
|
|
|
|
|
2009-12-15 23:31:14 +08:00
|
|
|
#include <stdbool.h>
|
2014-02-06 13:32:09 +08:00
|
|
|
#include "intlist.h"
|
2009-12-01 08:20:17 +08:00
|
|
|
#include "strlist.h"
|
2011-01-20 22:15:39 +08:00
|
|
|
#include "strfilter.h"
|
2009-12-01 08:19:58 +08:00
|
|
|
|
2015-05-08 09:03:31 +08:00
|
|
|
/* Probe related configurations */
|
|
|
|
struct probe_conf {
|
|
|
|
bool show_ext_vars;
|
perf probe: Add --range option to show a variable's location range
It is not easy for users to get the accurate byte offset or the line
number where a local variable can be probed.
With '--range' option, local variables in the scope of the probe point
are showed with a byte offset range, and can be added according to this
range information.
For example, there are some variables in the function
generic_perform_write():
<generic_perform_write@mm/filemap.c:0>
0 ssize_t generic_perform_write(struct file *file,
1 struct iov_iter *i, loff_t pos)
2 {
3 struct address_space *mapping = file->f_mapping;
4 const struct address_space_operations *a_ops = mapping->a_ops;
...
42 status = a_ops->write_begin(file, mapping, pos, bytes, flags,
&page, &fsdata);
44 if (unlikely(status < 0))
But we fail when we try to probe the variable 'a_ops' at line 42 or 44.
$ perf probe --add 'generic_perform_write:42 a_ops'
Failed to find the location of a_ops at this address.
Perhaps, it has been optimized out.
This is because the source code do not match the assembly, so a variable
may not be available in the source code line where it appears.
After this patch, we can lookup the accurate byte offset range of a
variable, 'INV' indicates that this variable is not valid at the given
point, but available in the scope:
$ perf probe --vars 'generic_perform_write:42' --range
Available variables at generic_perform_write:42
@<generic_perform_write+141>
[INV] ssize_t written @<generic_perform_write+[324-331]>
[INV] struct address_space_operations* a_ops @<generic_perform_write+[55-61,170-176,223-246]>
[VAL] (unknown_type) fsdata @<generic_perform_write+[70-307,346-411]>
[VAL] loff_t pos @<generic_perform_write+[0-286,286-336,346-411]>
[VAL] long int status @<generic_perform_write+[83-342,346-411]>
[VAL] long unsigned int bytes @<generic_perform_write+[122-311,320-338,346-403,403-411]>
[VAL] struct address_space* mapping @<generic_perform_write+[35-344,346-411]>
[VAL] struct iov_iter* i @<generic_perform_write+[0-340,346-411]>
[VAL] struct page* page @<generic_perform_write+[70-307,346-411]>
Then it is more clear for us to add a probe with this variable:
$ perf probe --add 'generic_perform_write+170 a_ops'
Added new event:
probe:generic_perform_write (on generic_perform_write+170 with a_ops)
Signed-off-by: He Kuang <hekuang@huawei.com>
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1431336304-16863-2-git-send-email-hekuang@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-05-11 17:25:03 +08:00
|
|
|
bool show_location_range;
|
2015-05-08 09:03:31 +08:00
|
|
|
bool force_add;
|
2015-05-08 09:03:33 +08:00
|
|
|
bool no_inlines;
|
2016-06-15 11:28:40 +08:00
|
|
|
bool cache;
|
2015-05-08 09:03:31 +08:00
|
|
|
int max_probes;
|
|
|
|
};
|
|
|
|
extern struct probe_conf probe_conf;
|
2010-03-17 06:06:05 +08:00
|
|
|
extern bool probe_event_dry_run;
|
|
|
|
|
2012-04-16 20:09:09 +08:00
|
|
|
/* kprobe-tracer and uprobe-tracer tracing point */
|
2010-07-29 22:13:51 +08:00
|
|
|
struct probe_trace_point {
|
2015-05-08 09:03:35 +08:00
|
|
|
char *realname; /* function real name (if needed) */
|
2010-03-17 06:06:12 +08:00
|
|
|
char *symbol; /* Base symbol */
|
2011-06-27 15:27:45 +08:00
|
|
|
char *module; /* Module name */
|
2010-03-17 06:06:12 +08:00
|
|
|
unsigned long offset; /* Offset from symbol */
|
perf probe: Support basic dwarf-based operations on uprobe events
Support basic dwarf(debuginfo) based operations for uprobe events. With
this change, perf probe can analyze debuginfo of user application binary
to set up new uprobe event.
This allows perf-probe --add(with local variables, line numbers) and
--line works with -x option. (Actually, --vars has already accepted -x
option)
For example, the following command shows the probe-able lines of a given
user space function. Something that so far was only available in the
'perf probe' tool for kernel space functions:
# ./perf probe -x perf --line map__load
<map__load@/home/fedora/ksrc/linux-2.6/tools/perf/util/map.c:0>
0 int map__load(struct map *map, symbol_filter_t filter)
1 {
2 const char *name = map->dso->long_name;
int nr;
5 if (dso__loaded(map->dso, map->type))
6 return 0;
8 nr = dso__load(map->dso, map, filter);
9 if (nr < 0) {
10 if (map->dso->has_build_id) {
And this shows the available variables at the given line of the
function.
# ./perf probe -x perf --vars map__load:8
Available variables at map__load:8
@<map__load+96>
char* name
struct map* map
symbol_filter_t filter
@<map__find_symbol+112>
char* name
symbol_filter_t filter
@<map__find_symbol_by_name+136>
char* name
symbol_filter_t filter
@<map_groups__find_symbol_by_name+176>
char* name
struct map* map
symbol_filter_t filter
And lastly, we can now define probe(s) with all available
variables on the given line:
# ./perf probe -x perf --add 'map__load:8 $vars'
Added new events:
probe_perf:map__load (on map__load:8 with $vars)
probe_perf:map__load_1 (on map__load:8 with $vars)
probe_perf:map__load_2 (on map__load:8 with $vars)
probe_perf:map__load_3 (on map__load:8 with $vars)
You can now use it in all perf tools, such as:
perf record -e probe_perf:map__load_3 -aR sleep 1
Changes from previous version:
- Add examples in the patch description.
- Use .text section start address and dwarf symbol address
for calculating the offset of given symbol, instead of
searching the symbol in symtab again.
With this change, we can safely handle multiple local
function instances (e.g. scnprintf in perf).
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: David A. Long <dave.long@linaro.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: systemtap@sourceware.org
Cc: yrl.pp-manager.tt@hitachi.com
Link: http://lkml.kernel.org/r/20131226054152.22364.47021.stgit@kbuild-fedora.novalocal
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2013-12-26 13:41:53 +08:00
|
|
|
unsigned long address; /* Actual address of the trace point */
|
2010-03-17 06:06:12 +08:00
|
|
|
bool retprobe; /* Return probe flag */
|
|
|
|
};
|
|
|
|
|
2010-07-29 22:13:51 +08:00
|
|
|
/* probe-tracer tracing argument referencing offset */
|
|
|
|
struct probe_trace_arg_ref {
|
|
|
|
struct probe_trace_arg_ref *next; /* Next reference */
|
2010-03-17 06:06:12 +08:00
|
|
|
long offset; /* Offset value */
|
|
|
|
};
|
|
|
|
|
2012-04-16 20:09:09 +08:00
|
|
|
/* kprobe-tracer and uprobe-tracer tracing argument */
|
2010-07-29 22:13:51 +08:00
|
|
|
struct probe_trace_arg {
|
2010-03-17 06:06:12 +08:00
|
|
|
char *name; /* Argument name */
|
|
|
|
char *value; /* Base value */
|
2010-04-13 01:17:15 +08:00
|
|
|
char *type; /* Type name */
|
2010-07-29 22:13:51 +08:00
|
|
|
struct probe_trace_arg_ref *ref; /* Referencing offset */
|
2010-03-17 06:06:12 +08:00
|
|
|
};
|
|
|
|
|
2012-04-16 20:09:09 +08:00
|
|
|
/* kprobe-tracer and uprobe-tracer tracing event (point + arg) */
|
2010-07-29 22:13:51 +08:00
|
|
|
struct probe_trace_event {
|
2010-03-17 06:06:12 +08:00
|
|
|
char *event; /* Event name */
|
|
|
|
char *group; /* Group name */
|
2010-07-29 22:13:51 +08:00
|
|
|
struct probe_trace_point point; /* Trace point */
|
2010-03-17 06:06:12 +08:00
|
|
|
int nargs; /* Number of args */
|
2012-04-16 20:09:09 +08:00
|
|
|
bool uprobes; /* uprobes only */
|
2010-07-29 22:13:51 +08:00
|
|
|
struct probe_trace_arg *args; /* Arguments */
|
2010-03-17 06:06:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Perf probe probing point */
|
|
|
|
struct perf_probe_point {
|
|
|
|
char *file; /* File path */
|
|
|
|
char *function; /* Function name */
|
|
|
|
int line; /* Line number */
|
perf tools: Reorganize some structs to save space
Using 'pahole --packable' I found some structs that could be reorganized
to eliminate alignment holes, in some cases getting them to be cacheline
multiples.
[acme@doppio linux-2.6-tip]$ codiff perf.old ~/bin/perf
builtin-annotate.c:
struct perf_session | -8
struct perf_header | -8
2 structs changed
builtin-diff.c:
struct sample_data | -8
1 struct changed
diff__process_sample_event | -8
1 function changed, 8 bytes removed, diff: -8
builtin-sched.c:
struct sched_atom | -8
1 struct changed
builtin-timechart.c:
struct per_pid | -8
1 struct changed
cmd_timechart | -16
1 function changed, 16 bytes removed, diff: -16
builtin-probe.c:
struct perf_probe_point | -8
struct perf_probe_event | -8
2 structs changed
opt_add_probe_event | -3
1 function changed, 3 bytes removed, diff: -3
util/probe-finder.c:
struct probe_finder | -8
1 struct changed
find_kprobe_trace_events | -16
1 function changed, 16 bytes removed, diff: -16
/home/acme/bin/perf:
4 functions changed, 43 bytes removed, diff: -43
[acme@doppio linux-2.6-tip]$
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-04-05 23:53:45 +08:00
|
|
|
bool retprobe; /* Return probe flag */
|
2010-03-17 06:06:12 +08:00
|
|
|
char *lazy_line; /* Lazy matching pattern */
|
|
|
|
unsigned long offset; /* Offset from function entry */
|
2015-08-26 18:57:45 +08:00
|
|
|
unsigned long abs_address; /* Absolute address of the point */
|
2010-03-17 06:06:12 +08:00
|
|
|
};
|
|
|
|
|
2010-03-17 06:06:26 +08:00
|
|
|
/* Perf probe probing argument field chain */
|
|
|
|
struct perf_probe_arg_field {
|
|
|
|
struct perf_probe_arg_field *next; /* Next field */
|
|
|
|
char *name; /* Name of the field */
|
2010-05-20 03:57:42 +08:00
|
|
|
long index; /* Array index number */
|
2010-03-17 06:06:26 +08:00
|
|
|
bool ref; /* Referencing flag */
|
|
|
|
};
|
|
|
|
|
2010-03-17 06:06:12 +08:00
|
|
|
/* Perf probe probing argument */
|
|
|
|
struct perf_probe_arg {
|
2010-03-17 06:06:26 +08:00
|
|
|
char *name; /* Argument name */
|
2010-04-13 01:16:53 +08:00
|
|
|
char *var; /* Variable name */
|
2010-04-13 01:17:22 +08:00
|
|
|
char *type; /* Type name */
|
2010-03-17 06:06:26 +08:00
|
|
|
struct perf_probe_arg_field *field; /* Structure fields */
|
2010-03-17 06:06:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Perf probe probing event (point + arg) */
|
|
|
|
struct perf_probe_event {
|
|
|
|
char *event; /* Event name */
|
|
|
|
char *group; /* Group name */
|
|
|
|
struct perf_probe_point point; /* Probe point */
|
|
|
|
int nargs; /* Number of arguments */
|
2016-07-12 18:04:43 +08:00
|
|
|
bool sdt; /* SDT/cached event flag */
|
2015-04-01 18:25:39 +08:00
|
|
|
bool uprobes; /* Uprobe event flag */
|
|
|
|
char *target; /* Target binary */
|
2010-03-17 06:06:12 +08:00
|
|
|
struct perf_probe_arg *args; /* Arguments */
|
2015-09-04 20:16:00 +08:00
|
|
|
struct probe_trace_event *tevs;
|
|
|
|
int ntevs;
|
2010-03-17 06:06:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Line range */
|
|
|
|
struct line_range {
|
|
|
|
char *file; /* File name */
|
|
|
|
char *function; /* Function name */
|
2010-04-15 06:39:42 +08:00
|
|
|
int start; /* Start line number */
|
|
|
|
int end; /* End line number */
|
2010-03-17 06:06:12 +08:00
|
|
|
int offset; /* Start line offset */
|
|
|
|
char *path; /* Real path name */
|
2010-07-09 17:29:11 +08:00
|
|
|
char *comp_dir; /* Compile directory */
|
2014-02-06 13:32:09 +08:00
|
|
|
struct intlist *line_list; /* Visible lines */
|
2010-03-17 06:06:12 +08:00
|
|
|
};
|
|
|
|
|
2010-10-21 18:13:23 +08:00
|
|
|
/* List of variables */
|
|
|
|
struct variable_list {
|
|
|
|
struct probe_trace_point point; /* Actual probepoint */
|
|
|
|
struct strlist *vars; /* Available variables */
|
|
|
|
};
|
|
|
|
|
2015-06-19 16:42:48 +08:00
|
|
|
struct map;
|
2015-09-10 10:27:05 +08:00
|
|
|
int init_probe_symbol_maps(bool user_only);
|
|
|
|
void exit_probe_symbol_maps(void);
|
2015-06-19 16:42:48 +08:00
|
|
|
|
2010-03-17 06:06:12 +08:00
|
|
|
/* Command string to events */
|
2016-03-24 02:06:35 +08:00
|
|
|
int parse_perf_probe_command(const char *cmd, struct perf_probe_event *pev);
|
|
|
|
int parse_probe_trace_command(const char *cmd, struct probe_trace_event *tev);
|
2010-03-17 06:06:12 +08:00
|
|
|
|
|
|
|
/* Events to command string */
|
2016-03-24 02:06:35 +08:00
|
|
|
char *synthesize_perf_probe_command(struct perf_probe_event *pev);
|
|
|
|
char *synthesize_probe_trace_command(struct probe_trace_event *tev);
|
2016-04-28 02:37:14 +08:00
|
|
|
char *synthesize_perf_probe_arg(struct perf_probe_arg *pa);
|
2016-06-08 17:29:50 +08:00
|
|
|
char *synthesize_perf_probe_point(struct perf_probe_point *pp);
|
2010-03-17 06:06:12 +08:00
|
|
|
|
2016-06-08 17:29:40 +08:00
|
|
|
int perf_probe_event__copy(struct perf_probe_event *dst,
|
|
|
|
struct perf_probe_event *src);
|
|
|
|
|
2016-08-03 16:58:44 +08:00
|
|
|
bool perf_probe_with_var(struct perf_probe_event *pev);
|
|
|
|
|
2010-03-17 06:06:12 +08:00
|
|
|
/* Check the perf_probe_event needs debuginfo */
|
2016-03-24 02:06:35 +08:00
|
|
|
bool perf_probe_event_need_dwarf(struct perf_probe_event *pev);
|
2010-03-17 06:06:12 +08:00
|
|
|
|
|
|
|
/* Release event contents */
|
2016-03-24 02:06:35 +08:00
|
|
|
void clear_perf_probe_event(struct perf_probe_event *pev);
|
|
|
|
void clear_probe_trace_event(struct probe_trace_event *tev);
|
2010-03-17 06:06:12 +08:00
|
|
|
|
|
|
|
/* Command string to line-range */
|
2016-03-24 02:06:35 +08:00
|
|
|
int parse_line_range_desc(const char *cmd, struct line_range *lr);
|
2010-03-17 06:06:12 +08:00
|
|
|
|
2014-01-16 17:39:47 +08:00
|
|
|
/* Release line range members */
|
2016-03-24 02:06:35 +08:00
|
|
|
void line_range__clear(struct line_range *lr);
|
2014-01-16 17:39:47 +08:00
|
|
|
|
|
|
|
/* Initialize line range */
|
2016-03-24 02:06:35 +08:00
|
|
|
int line_range__init(struct line_range *lr);
|
|
|
|
|
|
|
|
int add_perf_probe_events(struct perf_probe_event *pevs, int npevs);
|
|
|
|
int convert_perf_probe_events(struct perf_probe_event *pevs, int npevs);
|
|
|
|
int apply_perf_probe_events(struct perf_probe_event *pevs, int npevs);
|
2016-08-26 00:24:27 +08:00
|
|
|
int show_probe_trace_events(struct perf_probe_event *pevs, int npevs);
|
2016-03-24 02:06:35 +08:00
|
|
|
void cleanup_perf_probe_events(struct perf_probe_event *pevs, int npevs);
|
|
|
|
int del_perf_probe_events(struct strfilter *filter);
|
|
|
|
|
|
|
|
int show_perf_probe_event(const char *group, const char *event,
|
|
|
|
struct perf_probe_event *pev,
|
|
|
|
const char *module, bool use_stdout);
|
|
|
|
int show_perf_probe_events(struct strfilter *filter);
|
|
|
|
int show_line_range(struct line_range *lr, const char *module, bool user);
|
|
|
|
int show_available_vars(struct perf_probe_event *pevs, int npevs,
|
|
|
|
struct strfilter *filter);
|
|
|
|
int show_available_funcs(const char *module, struct strfilter *filter, bool user);
|
2015-04-28 20:05:40 +08:00
|
|
|
void arch__fix_tev_from_maps(struct perf_probe_event *pev,
|
2016-04-12 17:10:50 +08:00
|
|
|
struct probe_trace_event *tev, struct map *map,
|
|
|
|
struct symbol *sym);
|
2010-03-17 06:06:12 +08:00
|
|
|
|
2015-07-15 17:14:07 +08:00
|
|
|
/* If there is no space to write, returns -E2BIG. */
|
|
|
|
int e_snprintf(char *str, size_t size, const char *format, ...)
|
|
|
|
__attribute__((format(printf, 3, 4)));
|
|
|
|
|
2009-12-01 08:20:25 +08:00
|
|
|
/* Maximum index number of event-name postfix */
|
|
|
|
#define MAX_EVENT_INDEX 1024
|
|
|
|
|
2015-08-26 18:57:45 +08:00
|
|
|
int copy_to_probe_trace_arg(struct probe_trace_arg *tvar,
|
|
|
|
struct perf_probe_arg *pvar);
|
|
|
|
|
perf probe ppc64le: Fix probe location when using DWARF
Powerpc has Global Entry Point and Local Entry Point for functions. LEP
catches call from both the GEP and the LEP. Symbol table of ELF contains
GEP and Offset from which we can calculate LEP, but debuginfo does not
have LEP info.
Currently, perf prioritize symbol table over dwarf to probe on LEP for
ppc64le. But when user tries to probe with function parameter, we fall
back to using dwarf(i.e. GEP) and when function called via LEP, probe
will never hit.
For example:
$ objdump -d vmlinux
...
do_sys_open():
c0000000002eb4a0: e8 00 4c 3c addis r2,r12,232
c0000000002eb4a4: 60 00 42 38 addi r2,r2,96
c0000000002eb4a8: a6 02 08 7c mflr r0
c0000000002eb4ac: d0 ff 41 fb std r26,-48(r1)
$ sudo ./perf probe do_sys_open
$ sudo cat /sys/kernel/debug/tracing/kprobe_events
p:probe/do_sys_open _text+3060904
$ sudo ./perf probe 'do_sys_open filename:string'
$ sudo cat /sys/kernel/debug/tracing/kprobe_events
p:probe/do_sys_open _text+3060896 filename_string=+0(%gpr4):string
For second case, perf probed on GEP. So when function will be called via
LEP, probe won't hit.
$ sudo ./perf record -a -e probe:do_sys_open ls
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.195 MB perf.data ]
To resolve this issue, let's not prioritize symbol table, let perf
decide what it wants to use. Perf is already converting GEP to LEP when
it uses symbol table. When perf uses debuginfo, let it find LEP offset
form symbol table. This way we fall back to probe on LEP for all cases.
After patch:
$ sudo ./perf probe 'do_sys_open filename:string'
$ sudo cat /sys/kernel/debug/tracing/kprobe_events
p:probe/do_sys_open _text+3060904 filename_string=+0(%gpr4):string
$ sudo ./perf record -a -e probe:do_sys_open ls
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.197 MB perf.data (11 samples) ]
Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Balbir Singh <bsingharora@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1470723805-5081-2-git-send-email-ravi.bangoria@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-08-09 14:23:25 +08:00
|
|
|
struct map *get_target_map(const char *target, bool user);
|
|
|
|
|
|
|
|
void arch__post_process_probe_trace_events(struct perf_probe_event *pev,
|
|
|
|
int ntevs);
|
|
|
|
|
2009-12-01 08:19:58 +08:00
|
|
|
#endif /*_PROBE_EVENT_H */
|