linux/tools/perf/util/probe-event.h

143 lines
4.4 KiB
C
Raw Normal View History

#ifndef _PROBE_EVENT_H
#define _PROBE_EVENT_H
#include <stdbool.h>
#include "intlist.h"
#include "strlist.h"
#include "strfilter.h"
extern bool probe_event_dry_run;
/* kprobe-tracer and uprobe-tracer tracing point */
struct probe_trace_point {
char *symbol; /* Base symbol */
char *module; /* Module name */
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 05:41:53 +00:00
unsigned long address; /* Actual address of the trace point */
bool retprobe; /* Return probe flag */
};
/* probe-tracer tracing argument referencing offset */
struct probe_trace_arg_ref {
struct probe_trace_arg_ref *next; /* Next reference */
long offset; /* Offset value */
};
/* kprobe-tracer and uprobe-tracer tracing argument */
struct probe_trace_arg {
char *name; /* Argument name */
char *value; /* Base value */
char *type; /* Type name */
struct probe_trace_arg_ref *ref; /* Referencing offset */
};
/* 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 */
};
/* Perf probe probing point */
struct perf_probe_point {
char *file; /* File path */
char *function; /* Function name */
int line; /* Line number */
bool retprobe; /* Return probe flag */
char *lazy_line; /* Lazy matching pattern */
unsigned long offset; /* Offset from function entry */
};
/* 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 */
long index; /* Array index number */
bool ref; /* Referencing flag */
};
/* Perf probe probing argument */
struct perf_probe_arg {
char *name; /* Argument name */
char *var; /* Variable name */
char *type; /* Type name */
struct perf_probe_arg_field *field; /* Structure fields */
};
/* 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 */
bool uprobes;
struct perf_probe_arg *args; /* Arguments */
};
/* Line range */
struct line_range {
char *file; /* File name */
char *function; /* Function name */
int start; /* Start line number */
int end; /* End line number */
int offset; /* Start line offset */
char *path; /* Real path name */
char *comp_dir; /* Compile directory */
struct intlist *line_list; /* Visible lines */
};
/* List of variables */
struct variable_list {
struct probe_trace_point point; /* Actual probepoint */
struct strlist *vars; /* Available variables */
};
/* Command string to events */
extern int parse_perf_probe_command(const char *cmd,
struct perf_probe_event *pev);
/* Events to command string */
extern char *synthesize_perf_probe_command(struct perf_probe_event *pev);
extern char *synthesize_probe_trace_command(struct probe_trace_event *tev);
extern int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf,
size_t len);
/* Check the perf_probe_event needs debuginfo */
extern bool perf_probe_event_need_dwarf(struct perf_probe_event *pev);
/* Release event contents */
extern void clear_perf_probe_event(struct perf_probe_event *pev);
/* Command string to line-range */
extern int parse_line_range_desc(const char *cmd, struct line_range *lr);
/* Release line range members */
extern void line_range__clear(struct line_range *lr);
/* Initialize line range */
extern int line_range__init(struct line_range *lr);
2010-10-21 10:13:41 +00:00
/* Internal use: Return kernel/module path */
extern const char *kernel_get_module_path(const char *module);
extern int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
2010-10-21 10:13:41 +00:00
int max_probe_points, const char *module,
bool force_add);
extern int del_perf_probe_events(struct strlist *dellist);
extern int show_perf_probe_events(void);
perf probe: Do not access kallsyms when analyzing user binaries Do not access kallsyms to show available variables and show source lines in user binaries. This behavior always requires the root privilege when sysctl sets kernel.kptr_restrict=1, but we don't need it just for analyzing user binaries. Without this patch (by normal user, kptr_restrict=1): ---- $ perf probe -x ./perf -V add_cmdname Failed to init vmlinux path. Error: Failed to show vars. $ perf probe -x ./perf -L add_cmdname Failed to init vmlinux path. Error: Failed to show lines. ---- With this patch: ---- $ perf probe -x ./perf -V add_cmdname Available variables at add_cmdname @<perf_unknown_cmd_config+144> (No matched variables) @<list_commands_in_dir+160> (No matched variables) @<add_cmdname+0> char* name size_t len struct cmdnames* cmds $ perf probe -x ./perf -L add_cmdname <add_cmdname@/home/fedora/ksrc/linux-3/tools/perf/util/help.c:0> 0 void add_cmdname(struct cmdnames *cmds, const char *name, size_t len) 1 { 2 struct cmdname *ent = malloc(sizeof(*ent) + len + 1); 4 ent->len = len; 5 memcpy(ent->name, name, len); 6 ent->name[len] = 0; ... ---- Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Cc: david lerner <dlernerdroid@gmail.com> Cc: linux-perf-user@vger.kernel.org Cc: yrl.pp-manager.tt@hitachi.com Link: http://lkml.kernel.org/r/20140917084054.3722.73975.stgit@kbuild-f20.novalocal [ Added missing 'bool user' argument to the !DWARF show_line_range() stub ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2014-09-17 08:40:54 +00:00
extern int show_line_range(struct line_range *lr, const char *module,
bool user);
extern int show_available_vars(struct perf_probe_event *pevs, int npevs,
2010-10-21 10:13:41 +00:00
int max_probe_points, const char *module,
struct strfilter *filter, bool externs);
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
#endif /*_PROBE_EVENT_H */