xref: /linux/tools/perf/Documentation/perf-probe.txt (revision b3ac032b7a76fea678de225d26ae04d10e47f0ac)
1595c3649SMasami Hiramatsuperf-probe(1)
2595c3649SMasami Hiramatsu=============
3595c3649SMasami Hiramatsu
4595c3649SMasami HiramatsuNAME
5595c3649SMasami Hiramatsu----
6595c3649SMasami Hiramatsuperf-probe - Define new dynamic tracepoints
7595c3649SMasami Hiramatsu
8595c3649SMasami HiramatsuSYNOPSIS
9595c3649SMasami Hiramatsu--------
10595c3649SMasami Hiramatsu[verse]
11c937fe20SMasami Hiramatsu'perf probe' [options] --add='PROBE' [...]
12c43f9d1eSMasami Hiramatsuor
13c937fe20SMasami Hiramatsu'perf probe' [options] PROBE
14c937fe20SMasami Hiramatsuor
15c937fe20SMasami Hiramatsu'perf probe' [options] --del='[GROUP:]EVENT' [...]
16c937fe20SMasami Hiramatsuor
17c937fe20SMasami Hiramatsu'perf probe' --list
18631c9defSMasami Hiramatsuor
19e116dfa1SMasami Hiramatsu'perf probe' [options] --line='LINE'
20cf6eb489SMasami Hiramatsuor
21469b9b88SMasami Hiramatsu'perf probe' [options] --vars='PROBEPOINT'
22*b3ac032bSMasami Hiramatsuor
23*b3ac032bSMasami Hiramatsu'perf probe' [options] --funcs
24595c3649SMasami Hiramatsu
25595c3649SMasami HiramatsuDESCRIPTION
26595c3649SMasami Hiramatsu-----------
27595c3649SMasami HiramatsuThis command defines dynamic tracepoint events, by symbol and registers
28595c3649SMasami Hiramatsuwithout debuginfo, or by C expressions (C line numbers, C function names,
29595c3649SMasami Hiramatsuand C local variables) with debuginfo.
30595c3649SMasami Hiramatsu
31595c3649SMasami Hiramatsu
32595c3649SMasami HiramatsuOPTIONS
33595c3649SMasami Hiramatsu-------
34595c3649SMasami Hiramatsu-k::
35c43f9d1eSMasami Hiramatsu--vmlinux=PATH::
36595c3649SMasami Hiramatsu	Specify vmlinux path which has debuginfo (Dwarf binary).
37595c3649SMasami Hiramatsu
38469b9b88SMasami Hiramatsu-m::
3914a8fd7cSMasami Hiramatsu--module=MODNAME|PATH::
40469b9b88SMasami Hiramatsu	Specify module name in which perf-probe searches probe points
4114a8fd7cSMasami Hiramatsu	or lines. If a path of module file is passed, perf-probe
4214a8fd7cSMasami Hiramatsu	treat it as an offline module (this means you can add a probe on
4314a8fd7cSMasami Hiramatsu        a module which has not been loaded yet).
44469b9b88SMasami Hiramatsu
459ed7e1b8SChase Douglas-s::
469ed7e1b8SChase Douglas--source=PATH::
479ed7e1b8SChase Douglas	Specify path to kernel source.
489ed7e1b8SChase Douglas
49595c3649SMasami Hiramatsu-v::
50595c3649SMasami Hiramatsu--verbose::
51595c3649SMasami Hiramatsu        Be more verbose (show parsed arguments, etc).
528b72805fSMasami Hiramatsu	Can not use with -q.
538b72805fSMasami Hiramatsu
548b72805fSMasami Hiramatsu-q::
558b72805fSMasami Hiramatsu--quiet::
568b72805fSMasami Hiramatsu	Be quiet (do not show any messages including errors).
578b72805fSMasami Hiramatsu	Can not use with -v.
58595c3649SMasami Hiramatsu
59c43f9d1eSMasami Hiramatsu-a::
60c937fe20SMasami Hiramatsu--add=::
61c937fe20SMasami Hiramatsu	Define a probe event (see PROBE SYNTAX for detail).
62c937fe20SMasami Hiramatsu
63c937fe20SMasami Hiramatsu-d::
64c937fe20SMasami Hiramatsu--del=::
65ee391de8SMasami Hiramatsu	Delete probe events. This accepts glob wildcards('*', '?') and character
66ee391de8SMasami Hiramatsu	classes(e.g. [a-z], [!A-Z]).
67c937fe20SMasami Hiramatsu
68c937fe20SMasami Hiramatsu-l::
69c937fe20SMasami Hiramatsu--list::
70c937fe20SMasami Hiramatsu	List up current probe events.
71595c3649SMasami Hiramatsu
72631c9defSMasami Hiramatsu-L::
73631c9defSMasami Hiramatsu--line=::
74631c9defSMasami Hiramatsu	Show source code lines which can be probed. This needs an argument
75ee391de8SMasami Hiramatsu	which specifies a range of the source code. (see LINE SYNTAX for detail)
76ee391de8SMasami Hiramatsu
77cf6eb489SMasami Hiramatsu-V::
78cf6eb489SMasami Hiramatsu--vars=::
79cf6eb489SMasami Hiramatsu	Show available local variables at given probe point. The argument
80cf6eb489SMasami Hiramatsu	syntax is same as PROBE SYNTAX, but NO ARGs.
81cf6eb489SMasami Hiramatsu
82fb8c5a56SMasami Hiramatsu--externs::
83fb8c5a56SMasami Hiramatsu	(Only for --vars) Show external defined variables in addition to local
84fb8c5a56SMasami Hiramatsu	variables.
85fb8c5a56SMasami Hiramatsu
86e80711caSMasami Hiramatsu-F::
87e80711caSMasami Hiramatsu--funcs::
88225466f1SSrikar Dronamraju	Show available functions in given module or kernel. With -x/--exec,
89225466f1SSrikar Dronamraju	can also list functions in a user space executable / shared library.
90e80711caSMasami Hiramatsu
91bd09d7b5SMasami Hiramatsu--filter=FILTER::
923c42258cSMasami Hiramatsu	(Only for --vars and --funcs) Set filter. FILTER is a combination of glob
933c42258cSMasami Hiramatsu	pattern, see FILTER PATTERN for detail.
943c42258cSMasami Hiramatsu	Default FILTER is "!__k???tab_* & !__crc_*" for --vars, and "!_*"
953c42258cSMasami Hiramatsu	for --funcs.
963c42258cSMasami Hiramatsu	If several filters are specified, only the last filter is used.
97bd09d7b5SMasami Hiramatsu
98ee391de8SMasami Hiramatsu-f::
99ee391de8SMasami Hiramatsu--force::
100ee391de8SMasami Hiramatsu	Forcibly add events with existing name.
101631c9defSMasami Hiramatsu
102f4d7da49SMasami Hiramatsu-n::
103f4d7da49SMasami Hiramatsu--dry-run::
104f4d7da49SMasami Hiramatsu	Dry run. With this option, --add and --del doesn't execute actual
105f4d7da49SMasami Hiramatsu	adding and removal operations.
106f4d7da49SMasami Hiramatsu
1078b72805fSMasami Hiramatsu--max-probes=NUM::
108ef4a3565SMasami Hiramatsu	Set the maximum number of probe points for an event. Default is 128.
109ef4a3565SMasami Hiramatsu
110225466f1SSrikar Dronamraju-x::
111225466f1SSrikar Dronamraju--exec=PATH::
112225466f1SSrikar Dronamraju	Specify path to the executable or shared library file for user
113225466f1SSrikar Dronamraju	space tracing. Can also be used with --funcs option.
114225466f1SSrikar Dronamraju
1158b72805fSMasami Hiramatsu--demangle::
1168b72805fSMasami Hiramatsu	Demangle application symbols. --no-demangle is also available
1178b72805fSMasami Hiramatsu	for disabling demangling.
1188b72805fSMasami Hiramatsu
119763122adSAvi Kivity--demangle-kernel::
1208b72805fSMasami Hiramatsu	Demangle kernel symbols. --no-demangle-kernel is also available
1218b72805fSMasami Hiramatsu	for disabling kernel demangling.
122763122adSAvi Kivity
12373eff9f5SSrikar DronamrajuIn absence of -m/-x options, perf probe checks if the first argument after
12473eff9f5SSrikar Dronamrajuthe options is an absolute path name. If its an absolute path, perf probe
12573eff9f5SSrikar Dronamrajuuses it as a target module/target user space binary to probe.
12673eff9f5SSrikar Dronamraju
127595c3649SMasami HiramatsuPROBE SYNTAX
128595c3649SMasami Hiramatsu------------
129595c3649SMasami HiramatsuProbe points are defined by following syntax.
130595c3649SMasami Hiramatsu
1312a9c8c36SMasami Hiramatsu    1) Define event based on function name
1322a9c8c36SMasami Hiramatsu     [EVENT=]FUNC[@SRC][:RLN|+OFFS|%return|;PTN] [ARG ...]
1332a9c8c36SMasami Hiramatsu
1342a9c8c36SMasami Hiramatsu    2) Define event based on source file with line number
1352a9c8c36SMasami Hiramatsu     [EVENT=]SRC:ALN [ARG ...]
1362a9c8c36SMasami Hiramatsu
1372a9c8c36SMasami Hiramatsu    3) Define event based on source file with lazy pattern
1382a9c8c36SMasami Hiramatsu     [EVENT=]SRC;PTN [ARG ...]
1392a9c8c36SMasami Hiramatsu
140595c3649SMasami Hiramatsu
141af663d75SMasami Hiramatsu'EVENT' specifies the name of new event, if omitted, it will be set the name of the probed function. Currently, event group name is set as 'probe'.
1422a9c8c36SMasami Hiramatsu'FUNC' specifies a probed function name, and it may have one of the following options; '+OFFS' is the offset from function entry address in bytes, ':RLN' is the relative-line number from function entry line, and '%return' means that it probes function return. And ';PTN' means lazy matching pattern (see LAZY MATCHING). Note that ';PTN' must be the end of the probe point definition.  In addition, '@SRC' specifies a source file which has that function.
1432a9c8c36SMasami HiramatsuIt is also possible to specify a probe point by the source line number or lazy matching by using 'SRC:ALN' or 'SRC;PTN' syntax, where 'SRC' is the source file path, ':ALN' is the line number and ';PTN' is the lazy matching pattern.
14448481938SMasami Hiramatsu'ARG' specifies the arguments of this probe point, (see PROBE ARGUMENT).
14548481938SMasami Hiramatsu
14648481938SMasami HiramatsuPROBE ARGUMENT
14748481938SMasami Hiramatsu--------------
14848481938SMasami HiramatsuEach probe argument follows below syntax.
14948481938SMasami Hiramatsu
15011a1ca35SMasami Hiramatsu [NAME=]LOCALVAR|$retval|%REG|@SYMBOL[:TYPE]
15148481938SMasami Hiramatsu
152b2a3c12bSMasami Hiramatsu'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), local array with fixed index (e.g. array[1], var->array[0], var->pointer[2]), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.)
1538b72805fSMasami Hiramatsu'$vars' special argument is also available for NAME, it is expanded to the local variables which can access at given probe point.
15473317b95SMasami Hiramatsu'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. You can specify 'string' type only for the local variable or structure member which is an array of or a pointer to 'char' or 'unsigned char' type.
155595c3649SMasami Hiramatsu
1565b439820SAndi KleenOn x86 systems %REG is always the short form of the register: for example %AX. %RAX or %EAX is not valid.
1575b439820SAndi Kleen
158631c9defSMasami HiramatsuLINE SYNTAX
159631c9defSMasami Hiramatsu-----------
1609d5b7f5bSShawn BohrerLine range is described by following syntax.
161631c9defSMasami Hiramatsu
162e116dfa1SMasami Hiramatsu "FUNC[@SRC][:RLN[+NUM|-RLN2]]|SRC[:ALN[+NUM|-ALN2]]"
163631c9defSMasami Hiramatsu
164631c9defSMasami HiramatsuFUNC specifies the function name of showing lines. 'RLN' is the start line
165631c9defSMasami Hiramatsunumber from function entry line, and 'RLN2' is the end line number. As same as
166631c9defSMasami Hiramatsuprobe syntax, 'SRC' means the source file path, 'ALN' is start line number,
167631c9defSMasami Hiramatsuand 'ALN2' is end line number in the file. It is also possible to specify how
168e116dfa1SMasami Hiramatsumany lines to show by using 'NUM'. Moreover, 'FUNC@SRC' combination is good
169e116dfa1SMasami Hiramatsufor searching a specific function when several functions share same name.
170631c9defSMasami HiramatsuSo, "source.c:100-120" shows lines between 100th to l20th in source.c file. And "func:10+20" shows 20 lines from 10th line of func function.
171631c9defSMasami Hiramatsu
1722a9c8c36SMasami HiramatsuLAZY MATCHING
1732a9c8c36SMasami Hiramatsu-------------
1742a9c8c36SMasami Hiramatsu The lazy line matching is similar to glob matching but ignoring spaces in both of pattern and target. So this accepts wildcards('*', '?') and character classes(e.g. [a-z], [!A-Z]).
1752a9c8c36SMasami Hiramatsu
1762a9c8c36SMasami Hiramatsue.g.
1772a9c8c36SMasami Hiramatsu 'a=*' can matches 'a=b', 'a = b', 'a == b' and so on.
1782a9c8c36SMasami Hiramatsu
1792a9c8c36SMasami HiramatsuThis provides some sort of flexibility and robustness to probe point definitions against minor code changes. For example, actual 10th line of schedule() can be moved easily by modifying schedule(), but the same line matching 'rq=cpu_rq*' may still exist in the function.)
1802a9c8c36SMasami Hiramatsu
181bd09d7b5SMasami HiramatsuFILTER PATTERN
182bd09d7b5SMasami Hiramatsu--------------
183bd09d7b5SMasami Hiramatsu The filter pattern is a glob matching pattern(s) to filter variables.
184bd09d7b5SMasami Hiramatsu In addition, you can use "!" for specifying filter-out rule. You also can give several rules combined with "&" or "|", and fold those rules as one rule by using "(" ")".
185bd09d7b5SMasami Hiramatsu
186bd09d7b5SMasami Hiramatsue.g.
187bd09d7b5SMasami Hiramatsu With --filter "foo* | bar*", perf probe -V shows variables which start with "foo" or "bar".
188bd09d7b5SMasami Hiramatsu With --filter "!foo* & *bar", perf probe -V shows variables which don't start with "foo" and end with "bar", like "fizzbar". But "foobar" is filtered out.
1892a9c8c36SMasami Hiramatsu
190ee391de8SMasami HiramatsuEXAMPLES
191ee391de8SMasami Hiramatsu--------
192ee391de8SMasami HiramatsuDisplay which lines in schedule() can be probed:
193ee391de8SMasami Hiramatsu
194ee391de8SMasami Hiramatsu ./perf probe --line schedule
195ee391de8SMasami Hiramatsu
196ee391de8SMasami HiramatsuAdd a probe on schedule() function 12th line with recording cpu local variable:
197ee391de8SMasami Hiramatsu
198ee391de8SMasami Hiramatsu ./perf probe schedule:12 cpu
199ee391de8SMasami Hiramatsu or
200ee391de8SMasami Hiramatsu ./perf probe --add='schedule:12 cpu'
201ee391de8SMasami Hiramatsu
202ee391de8SMasami Hiramatsu this will add one or more probes which has the name start with "schedule".
203ee391de8SMasami Hiramatsu
2042a9c8c36SMasami Hiramatsu Add probes on lines in schedule() function which calls update_rq_clock().
2052a9c8c36SMasami Hiramatsu
2062a9c8c36SMasami Hiramatsu ./perf probe 'schedule;update_rq_clock*'
2072a9c8c36SMasami Hiramatsu or
2082a9c8c36SMasami Hiramatsu ./perf probe --add='schedule;update_rq_clock*'
2092a9c8c36SMasami Hiramatsu
210ee391de8SMasami HiramatsuDelete all probes on schedule().
211ee391de8SMasami Hiramatsu
212ee391de8SMasami Hiramatsu ./perf probe --del='schedule*'
213ee391de8SMasami Hiramatsu
214225466f1SSrikar DronamrajuAdd probes at zfree() function on /bin/zsh
215225466f1SSrikar Dronamraju
21673eff9f5SSrikar Dronamraju ./perf probe -x /bin/zsh zfree or ./perf probe /bin/zsh zfree
217225466f1SSrikar Dronamraju
218225466f1SSrikar DronamrajuAdd probes at malloc() function on libc
219225466f1SSrikar Dronamraju
22073eff9f5SSrikar Dronamraju ./perf probe -x /lib/libc.so.6 malloc or ./perf probe /lib/libc.so.6 malloc
221ee391de8SMasami Hiramatsu
222595c3649SMasami HiramatsuSEE ALSO
223595c3649SMasami Hiramatsu--------
224595c3649SMasami Hiramatsulinkperf:perf-trace[1], linkperf:perf-record[1]
225