diff options
author | Masami Hiramatsu <mhiramat@redhat.com> | 2009-10-08 17:17:38 -0400 |
---|---|---|
committer | Frederic Weisbecker <fweisbec@gmail.com> | 2009-10-12 17:31:52 -0400 |
commit | 4ea42b181434bfc6a0a18d32214130a242d489bf (patch) | |
tree | 2c467d795d90440e0293951087c41caca8397584 /tools/perf/util/probe-finder.h | |
parent | e93f4d8539d5e9dd59f4af9d8ef4e9b62cfa1f81 (diff) |
perf: Add perf probe subcommand, a kprobe-event setup helper
Add perf probe subcommand that implements a kprobe-event setup helper
to the perf command.
This allows user to define kprobe events using C expressions (C line
numbers, C function names, and C local variables).
Usage
-----
perf probe [<options>] -P 'PROBEDEF' [-P 'PROBEDEF' ...]
-k, --vmlinux <file> vmlinux/module pathname
-P, --probe <p|r:[GRP/]NAME FUNC[+OFFS][@SRC]|@SRC:LINE [ARG ...]>
probe point definition, where
p: kprobe probe
r: kretprobe probe
GRP: Group name (optional)
NAME: Event name
FUNC: Function name
OFFS: Offset from function entry (in byte)
SRC: Source code path
LINE: Line number
ARG: Probe argument (local variable name or
kprobe-tracer argument format is supported.)
Changes in v4:
- Add _GNU_SOURCE macro for strndup().
Changes in v3:
- Remove -r option because perf always be used for online kernel.
- Check malloc/calloc results.
Changes in v2:
- Check synthesized string length.
- Rename perf kprobe to perf probe.
- Use spaces for separator and update usage comment.
- Check error paths in parse_probepoint().
- Check optimized-out variables.
Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Frank Ch. Eigler <fche@redhat.com>
LKML-Reference: <20091008211737.29299.14784.stgit@dhcp-100-2-132.bos.redhat.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Diffstat (limited to 'tools/perf/util/probe-finder.h')
-rw-r--r-- | tools/perf/util/probe-finder.h | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h new file mode 100644 index 000000000000..af920de64866 --- /dev/null +++ b/tools/perf/util/probe-finder.h | |||
@@ -0,0 +1,68 @@ | |||
1 | #ifndef _PROBE_FINDER_H | ||
2 | #define _PROBE_FINDER_H | ||
3 | |||
4 | #define _stringify(n) #n | ||
5 | #define stringify(n) _stringify(n) | ||
6 | |||
7 | #ifdef DEBUG | ||
8 | #define debug(fmt ...) \ | ||
9 | fprintf(stderr, "DBG(" __FILE__ ":" stringify(__LINE__) "): " fmt) | ||
10 | #else | ||
11 | #define debug(fmt ...) do {} while (0) | ||
12 | #endif | ||
13 | |||
14 | #define ERR_IF(cnd) \ | ||
15 | do { if (cnd) { \ | ||
16 | fprintf(stderr, "Error (" __FILE__ ":" stringify(__LINE__) \ | ||
17 | "): " stringify(cnd) "\n"); \ | ||
18 | exit(1); \ | ||
19 | } } while (0) | ||
20 | |||
21 | #define MAX_PATH_LEN 256 | ||
22 | #define MAX_PROBE_BUFFER 1024 | ||
23 | #define MAX_PROBES 128 | ||
24 | |||
25 | static inline int is_c_varname(const char *name) | ||
26 | { | ||
27 | /* TODO */ | ||
28 | return isalpha(name[0]) || name[0] == '_'; | ||
29 | } | ||
30 | |||
31 | struct probe_point { | ||
32 | /* Inputs */ | ||
33 | char *file; /* File name */ | ||
34 | int line; /* Line number */ | ||
35 | |||
36 | char *function; /* Function name */ | ||
37 | int offset; /* Offset bytes */ | ||
38 | |||
39 | int nr_args; /* Number of arguments */ | ||
40 | char **args; /* Arguments */ | ||
41 | |||
42 | /* Output */ | ||
43 | int found; /* Number of found probe points */ | ||
44 | char *probes[MAX_PROBES]; /* Output buffers (will be allocated)*/ | ||
45 | }; | ||
46 | |||
47 | extern int find_probepoint(int fd, struct probe_point *pp); | ||
48 | |||
49 | #include <libdwarf/dwarf.h> | ||
50 | #include <libdwarf/libdwarf.h> | ||
51 | |||
52 | struct probe_finder { | ||
53 | struct probe_point *pp; /* Target probe point */ | ||
54 | |||
55 | /* For function searching */ | ||
56 | Dwarf_Addr addr; /* Address */ | ||
57 | Dwarf_Unsigned fno; /* File number */ | ||
58 | Dwarf_Off inl_offs; /* Inline offset */ | ||
59 | |||
60 | /* For variable searching */ | ||
61 | Dwarf_Addr cu_base; /* Current CU base address */ | ||
62 | Dwarf_Locdesc fbloc; /* Location of Current Frame Base */ | ||
63 | const char *var; /* Current variable name */ | ||
64 | char *buf; /* Current output buffer */ | ||
65 | int len; /* Length of output buffer */ | ||
66 | }; | ||
67 | |||
68 | #endif /*_PROBE_FINDER_H */ | ||