diff options
Diffstat (limited to 'Documentation/trace/uprobetracer.txt')
-rw-r--r-- | Documentation/trace/uprobetracer.txt | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/Documentation/trace/uprobetracer.txt b/Documentation/trace/uprobetracer.txt new file mode 100644 index 000000000000..24ce6823a09e --- /dev/null +++ b/Documentation/trace/uprobetracer.txt | |||
@@ -0,0 +1,113 @@ | |||
1 | Uprobe-tracer: Uprobe-based Event Tracing | ||
2 | ========================================= | ||
3 | Documentation written by Srikar Dronamraju | ||
4 | |||
5 | Overview | ||
6 | -------- | ||
7 | Uprobe based trace events are similar to kprobe based trace events. | ||
8 | To enable this feature, build your kernel with CONFIG_UPROBE_EVENT=y. | ||
9 | |||
10 | Similar to the kprobe-event tracer, this doesn't need to be activated via | ||
11 | current_tracer. Instead of that, add probe points via | ||
12 | /sys/kernel/debug/tracing/uprobe_events, and enable it via | ||
13 | /sys/kernel/debug/tracing/events/uprobes/<EVENT>/enabled. | ||
14 | |||
15 | However unlike kprobe-event tracer, the uprobe event interface expects the | ||
16 | user to calculate the offset of the probepoint in the object | ||
17 | |||
18 | Synopsis of uprobe_tracer | ||
19 | ------------------------- | ||
20 | p[:[GRP/]EVENT] PATH:SYMBOL[+offs] [FETCHARGS] : Set a probe | ||
21 | |||
22 | GRP : Group name. If omitted, use "uprobes" for it. | ||
23 | EVENT : Event name. If omitted, the event name is generated | ||
24 | based on SYMBOL+offs. | ||
25 | PATH : path to an executable or a library. | ||
26 | SYMBOL[+offs] : Symbol+offset where the probe is inserted. | ||
27 | |||
28 | FETCHARGS : Arguments. Each probe can have up to 128 args. | ||
29 | %REG : Fetch register REG | ||
30 | |||
31 | Event Profiling | ||
32 | --------------- | ||
33 | You can check the total number of probe hits and probe miss-hits via | ||
34 | /sys/kernel/debug/tracing/uprobe_profile. | ||
35 | The first column is event name, the second is the number of probe hits, | ||
36 | the third is the number of probe miss-hits. | ||
37 | |||
38 | Usage examples | ||
39 | -------------- | ||
40 | To add a probe as a new event, write a new definition to uprobe_events | ||
41 | as below. | ||
42 | |||
43 | echo 'p: /bin/bash:0x4245c0' > /sys/kernel/debug/tracing/uprobe_events | ||
44 | |||
45 | This sets a uprobe at an offset of 0x4245c0 in the executable /bin/bash | ||
46 | |||
47 | echo > /sys/kernel/debug/tracing/uprobe_events | ||
48 | |||
49 | This clears all probe points. | ||
50 | |||
51 | The following example shows how to dump the instruction pointer and %ax | ||
52 | a register at the probed text address. Here we are trying to probe | ||
53 | function zfree in /bin/zsh | ||
54 | |||
55 | # cd /sys/kernel/debug/tracing/ | ||
56 | # cat /proc/`pgrep zsh`/maps | grep /bin/zsh | grep r-xp | ||
57 | 00400000-0048a000 r-xp 00000000 08:03 130904 /bin/zsh | ||
58 | # objdump -T /bin/zsh | grep -w zfree | ||
59 | 0000000000446420 g DF .text 0000000000000012 Base zfree | ||
60 | |||
61 | 0x46420 is the offset of zfree in object /bin/zsh that is loaded at | ||
62 | 0x00400000. Hence the command to probe would be : | ||
63 | |||
64 | # echo 'p /bin/zsh:0x46420 %ip %ax' > uprobe_events | ||
65 | |||
66 | Please note: User has to explicitly calculate the offset of the probepoint | ||
67 | in the object. We can see the events that are registered by looking at the | ||
68 | uprobe_events file. | ||
69 | |||
70 | # cat uprobe_events | ||
71 | p:uprobes/p_zsh_0x46420 /bin/zsh:0x00046420 arg1=%ip arg2=%ax | ||
72 | |||
73 | The format of events can be seen by viewing the file events/uprobes/p_zsh_0x46420/format | ||
74 | |||
75 | # cat events/uprobes/p_zsh_0x46420/format | ||
76 | name: p_zsh_0x46420 | ||
77 | ID: 922 | ||
78 | format: | ||
79 | field:unsigned short common_type; offset:0; size:2; signed:0; | ||
80 | field:unsigned char common_flags; offset:2; size:1; signed:0; | ||
81 | field:unsigned char common_preempt_count; offset:3; size:1; signed:0; | ||
82 | field:int common_pid; offset:4; size:4; signed:1; | ||
83 | field:int common_padding; offset:8; size:4; signed:1; | ||
84 | |||
85 | field:unsigned long __probe_ip; offset:12; size:4; signed:0; | ||
86 | field:u32 arg1; offset:16; size:4; signed:0; | ||
87 | field:u32 arg2; offset:20; size:4; signed:0; | ||
88 | |||
89 | print fmt: "(%lx) arg1=%lx arg2=%lx", REC->__probe_ip, REC->arg1, REC->arg2 | ||
90 | |||
91 | Right after definition, each event is disabled by default. For tracing these | ||
92 | events, you need to enable it by: | ||
93 | |||
94 | # echo 1 > events/uprobes/enable | ||
95 | |||
96 | Lets disable the event after sleeping for some time. | ||
97 | # sleep 20 | ||
98 | # echo 0 > events/uprobes/enable | ||
99 | |||
100 | And you can see the traced information via /sys/kernel/debug/tracing/trace. | ||
101 | |||
102 | # cat trace | ||
103 | # tracer: nop | ||
104 | # | ||
105 | # TASK-PID CPU# TIMESTAMP FUNCTION | ||
106 | # | | | | | | ||
107 | zsh-24842 [006] 258544.995456: p_zsh_0x46420: (0x446420) arg1=446421 arg2=79 | ||
108 | zsh-24842 [007] 258545.000270: p_zsh_0x46420: (0x446420) arg1=446421 arg2=79 | ||
109 | zsh-24842 [002] 258545.043929: p_zsh_0x46420: (0x446420) arg1=446421 arg2=79 | ||
110 | zsh-24842 [004] 258547.046129: p_zsh_0x46420: (0x446420) arg1=446421 arg2=79 | ||
111 | |||
112 | Each line shows us probes were triggered for a pid 24842 with ip being | ||
113 | 0x446421 and contents of ax register being 79. | ||