162306a36Sopenharmony_ciperf-probe(1) 262306a36Sopenharmony_ci============= 362306a36Sopenharmony_ci 462306a36Sopenharmony_ciNAME 562306a36Sopenharmony_ci---- 662306a36Sopenharmony_ciperf-probe - Define new dynamic tracepoints 762306a36Sopenharmony_ci 862306a36Sopenharmony_ciSYNOPSIS 962306a36Sopenharmony_ci-------- 1062306a36Sopenharmony_ci[verse] 1162306a36Sopenharmony_ci'perf probe' [options] --add='PROBE' [...] 1262306a36Sopenharmony_cior 1362306a36Sopenharmony_ci'perf probe' [options] PROBE 1462306a36Sopenharmony_cior 1562306a36Sopenharmony_ci'perf probe' [options] --del='[GROUP:]EVENT' [...] 1662306a36Sopenharmony_cior 1762306a36Sopenharmony_ci'perf probe' --list[=[GROUP:]EVENT] 1862306a36Sopenharmony_cior 1962306a36Sopenharmony_ci'perf probe' [options] --line='LINE' 2062306a36Sopenharmony_cior 2162306a36Sopenharmony_ci'perf probe' [options] --vars='PROBEPOINT' 2262306a36Sopenharmony_cior 2362306a36Sopenharmony_ci'perf probe' [options] --funcs 2462306a36Sopenharmony_cior 2562306a36Sopenharmony_ci'perf probe' [options] --definition='PROBE' [...] 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ciDESCRIPTION 2862306a36Sopenharmony_ci----------- 2962306a36Sopenharmony_ciThis command defines dynamic tracepoint events, by symbol and registers 3062306a36Sopenharmony_ciwithout debuginfo, or by C expressions (C line numbers, C function names, 3162306a36Sopenharmony_ciand C local variables) with debuginfo. 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ciOPTIONS 3562306a36Sopenharmony_ci------- 3662306a36Sopenharmony_ci-k:: 3762306a36Sopenharmony_ci--vmlinux=PATH:: 3862306a36Sopenharmony_ci Specify vmlinux path which has debuginfo (Dwarf binary). 3962306a36Sopenharmony_ci Only when using this with --definition, you can give an offline 4062306a36Sopenharmony_ci vmlinux file. 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci-m:: 4362306a36Sopenharmony_ci--module=MODNAME|PATH:: 4462306a36Sopenharmony_ci Specify module name in which perf-probe searches probe points 4562306a36Sopenharmony_ci or lines. If a path of module file is passed, perf-probe 4662306a36Sopenharmony_ci treat it as an offline module (this means you can add a probe on 4762306a36Sopenharmony_ci a module which has not been loaded yet). 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci-s:: 5062306a36Sopenharmony_ci--source=PATH:: 5162306a36Sopenharmony_ci Specify path to kernel source. 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci-v:: 5462306a36Sopenharmony_ci--verbose:: 5562306a36Sopenharmony_ci Be more verbose (show parsed arguments, etc). 5662306a36Sopenharmony_ci Can not use with -q. 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci-q:: 5962306a36Sopenharmony_ci--quiet:: 6062306a36Sopenharmony_ci Do not show any warnings or messages. 6162306a36Sopenharmony_ci Can not use with -v. 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci-a:: 6462306a36Sopenharmony_ci--add=:: 6562306a36Sopenharmony_ci Define a probe event (see PROBE SYNTAX for detail). 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci-d:: 6862306a36Sopenharmony_ci--del=:: 6962306a36Sopenharmony_ci Delete probe events. This accepts glob wildcards('*', '?') and character 7062306a36Sopenharmony_ci classes(e.g. [a-z], [!A-Z]). 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci-l:: 7362306a36Sopenharmony_ci--list[=[GROUP:]EVENT]:: 7462306a36Sopenharmony_ci List up current probe events. This can also accept filtering patterns of 7562306a36Sopenharmony_ci event names. 7662306a36Sopenharmony_ci When this is used with --cache, perf shows all cached probes instead of 7762306a36Sopenharmony_ci the live probes. 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci-L:: 8062306a36Sopenharmony_ci--line=:: 8162306a36Sopenharmony_ci Show source code lines which can be probed. This needs an argument 8262306a36Sopenharmony_ci which specifies a range of the source code. (see LINE SYNTAX for detail) 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci-V:: 8562306a36Sopenharmony_ci--vars=:: 8662306a36Sopenharmony_ci Show available local variables at given probe point. The argument 8762306a36Sopenharmony_ci syntax is same as PROBE SYNTAX, but NO ARGs. 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci--externs:: 9062306a36Sopenharmony_ci (Only for --vars) Show external defined variables in addition to local 9162306a36Sopenharmony_ci variables. 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci--no-inlines:: 9462306a36Sopenharmony_ci (Only for --add) Search only for non-inlined functions. The functions 9562306a36Sopenharmony_ci which do not have instances are ignored. 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci-F:: 9862306a36Sopenharmony_ci--funcs[=FILTER]:: 9962306a36Sopenharmony_ci Show available functions in given module or kernel. With -x/--exec, 10062306a36Sopenharmony_ci can also list functions in a user space executable / shared library. 10162306a36Sopenharmony_ci This also can accept a FILTER rule argument. 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci-D:: 10462306a36Sopenharmony_ci--definition=:: 10562306a36Sopenharmony_ci Show trace-event definition converted from given probe-event instead 10662306a36Sopenharmony_ci of write it into tracing/[k,u]probe_events. 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci--filter=FILTER:: 10962306a36Sopenharmony_ci (Only for --vars and --funcs) Set filter. FILTER is a combination of glob 11062306a36Sopenharmony_ci pattern, see FILTER PATTERN for detail. 11162306a36Sopenharmony_ci Default FILTER is "!__k???tab_* & !__crc_*" for --vars, and "!_*" 11262306a36Sopenharmony_ci for --funcs. 11362306a36Sopenharmony_ci If several filters are specified, only the last filter is used. 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci-f:: 11662306a36Sopenharmony_ci--force:: 11762306a36Sopenharmony_ci Forcibly add events with existing name. 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci-n:: 12062306a36Sopenharmony_ci--dry-run:: 12162306a36Sopenharmony_ci Dry run. With this option, --add and --del doesn't execute actual 12262306a36Sopenharmony_ci adding and removal operations. 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci--cache:: 12562306a36Sopenharmony_ci (With --add) Cache the probes. Any events which successfully added 12662306a36Sopenharmony_ci are also stored in the cache file. 12762306a36Sopenharmony_ci (With --list) Show cached probes. 12862306a36Sopenharmony_ci (With --del) Remove cached probes. 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ci--max-probes=NUM:: 13162306a36Sopenharmony_ci Set the maximum number of probe points for an event. Default is 128. 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ci--target-ns=PID: 13462306a36Sopenharmony_ci Obtain mount namespace information from the target pid. This is 13562306a36Sopenharmony_ci used when creating a uprobe for a process that resides in a 13662306a36Sopenharmony_ci different mount namespace from the perf(1) utility. 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci-x:: 13962306a36Sopenharmony_ci--exec=PATH:: 14062306a36Sopenharmony_ci Specify path to the executable or shared library file for user 14162306a36Sopenharmony_ci space tracing. Can also be used with --funcs option. 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_ci--demangle:: 14462306a36Sopenharmony_ci Demangle application symbols. --no-demangle is also available 14562306a36Sopenharmony_ci for disabling demangling. 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ci--demangle-kernel:: 14862306a36Sopenharmony_ci Demangle kernel symbols. --no-demangle-kernel is also available 14962306a36Sopenharmony_ci for disabling kernel demangling. 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ciIn absence of -m/-x options, perf probe checks if the first argument after 15262306a36Sopenharmony_cithe options is an absolute path name. If its an absolute path, perf probe 15362306a36Sopenharmony_ciuses it as a target module/target user space binary to probe. 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ciPROBE SYNTAX 15662306a36Sopenharmony_ci------------ 15762306a36Sopenharmony_ciProbe points are defined by following syntax. 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ci 1) Define event based on function name 16062306a36Sopenharmony_ci [[GROUP:]EVENT=]FUNC[@SRC][:RLN|+OFFS|%return|;PTN] [ARG ...] 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci 2) Define event based on source file with line number 16362306a36Sopenharmony_ci [[GROUP:]EVENT=]SRC:ALN [ARG ...] 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_ci 3) Define event based on source file with lazy pattern 16662306a36Sopenharmony_ci [[GROUP:]EVENT=]SRC;PTN [ARG ...] 16762306a36Sopenharmony_ci 16862306a36Sopenharmony_ci 4) Pre-defined SDT events or cached event with name 16962306a36Sopenharmony_ci %[sdt_PROVIDER:]SDTEVENT 17062306a36Sopenharmony_ci or, 17162306a36Sopenharmony_ci sdt_PROVIDER:SDTEVENT 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_ci'EVENT' specifies the name of new event, if omitted, it will be set the name of the probed function, and for return probes, a "\_\_return" suffix is automatically added to the function name. You can also specify a group name by 'GROUP', if omitted, set 'probe' is used for kprobe and 'probe_<bin>' is used for uprobe. 17462306a36Sopenharmony_ciNote that using existing group name can conflict with other events. Especially, using the group name reserved for kernel modules can hide embedded events in the 17562306a36Sopenharmony_cimodules. 17662306a36Sopenharmony_ci'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. 17762306a36Sopenharmony_ciIt 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. 17862306a36Sopenharmony_ci'ARG' specifies the arguments of this probe point, (see PROBE ARGUMENT). 17962306a36Sopenharmony_ci'SDTEVENT' and 'PROVIDER' is the pre-defined event name which is defined by user SDT (Statically Defined Tracing) or the pre-cached probes with event name. 18062306a36Sopenharmony_ciNote that before using the SDT event, the target binary (on which SDT events are defined) must be scanned by linkperf:perf-buildid-cache[1] to make SDT events as cached events. 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ciFor details of the SDT, see below. 18362306a36Sopenharmony_cihttps://sourceware.org/gdb/onlinedocs/gdb/Static-Probe-Points.html 18462306a36Sopenharmony_ci 18562306a36Sopenharmony_ciESCAPED CHARACTER 18662306a36Sopenharmony_ci----------------- 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ciIn the probe syntax, '=', '@', '+', ':' and ';' are treated as a special character. You can use a backslash ('\') to escape the special characters. 18962306a36Sopenharmony_ciThis is useful if you need to probe on a specific versioned symbols, like @GLIBC_... suffixes, or also you need to specify a source file which includes the special characters. 19062306a36Sopenharmony_ciNote that usually single backslash is consumed by shell, so you might need to pass double backslash (\\) or wrapping with single quotes (\'AAA\@BBB'). 19162306a36Sopenharmony_ciSee EXAMPLES how it is used. 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ciPROBE ARGUMENT 19462306a36Sopenharmony_ci-------------- 19562306a36Sopenharmony_ciEach probe argument follows below syntax. 19662306a36Sopenharmony_ci 19762306a36Sopenharmony_ci [NAME=]LOCALVAR|$retval|%REG|@SYMBOL[:TYPE][@user] 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_ci'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'.) 20062306a36Sopenharmony_ci'$vars' and '$params' special arguments are also available for NAME, '$vars' is expanded to the local variables (including function parameters) which can access at given probe point. '$params' is expanded to only the function parameters. 20162306a36Sopenharmony_ci'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo (*). Currently, basic types (u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal integers (x/x8/x16/x32/x64), signedness casting (u/s), "string" and bitfield are supported. (see TYPES for detail) 20262306a36Sopenharmony_ciOn x86 systems %REG is always the short form of the register: for example %AX. %RAX or %EAX is not valid. 20362306a36Sopenharmony_ci"@user" is a special attribute which means the LOCALVAR will be treated as a user-space memory. This is only valid for kprobe event. 20462306a36Sopenharmony_ci 20562306a36Sopenharmony_ciTYPES 20662306a36Sopenharmony_ci----- 20762306a36Sopenharmony_ciBasic types (u8/u16/u32/u64/s8/s16/s32/s64) and hexadecimal integers (x8/x16/x32/x64) are integer types. Prefix 's' and 'u' means those types are signed and unsigned respectively, and 'x' means that is shown in hexadecimal format. Traced arguments are shown in decimal (sNN/uNN) or hex (xNN). You can also use 's' or 'u' to specify only signedness and leave its size auto-detected by perf probe. Moreover, you can use 'x' to explicitly specify to be shown in hexadecimal (the size is also auto-detected). 20862306a36Sopenharmony_ciString type is a special type, which fetches a "null-terminated" string from kernel space. This means it will fail and store NULL if the string container has been paged out. 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. 20962306a36Sopenharmony_ciBitfield is another special type, which takes 3 parameters, bit-width, bit-offset, and container-size (usually 32). The syntax is; 21062306a36Sopenharmony_ci 21162306a36Sopenharmony_ci b<bit-width>@<bit-offset>/<container-size> 21262306a36Sopenharmony_ci 21362306a36Sopenharmony_ciLINE SYNTAX 21462306a36Sopenharmony_ci----------- 21562306a36Sopenharmony_ciLine range is described by following syntax. 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_ci "FUNC[@SRC][:RLN[+NUM|-RLN2]]|SRC[:ALN[+NUM|-ALN2]]" 21862306a36Sopenharmony_ci 21962306a36Sopenharmony_ciFUNC specifies the function name of showing lines. 'RLN' is the start line 22062306a36Sopenharmony_cinumber from function entry line, and 'RLN2' is the end line number. As same as 22162306a36Sopenharmony_ciprobe syntax, 'SRC' means the source file path, 'ALN' is start line number, 22262306a36Sopenharmony_ciand 'ALN2' is end line number in the file. It is also possible to specify how 22362306a36Sopenharmony_cimany lines to show by using 'NUM'. Moreover, 'FUNC@SRC' combination is good 22462306a36Sopenharmony_cifor searching a specific function when several functions share same name. 22562306a36Sopenharmony_ciSo, "source.c:100-120" shows lines between 100th to 120th in source.c file. And "func:10+20" shows 20 lines from 10th line of func function. 22662306a36Sopenharmony_ci 22762306a36Sopenharmony_ciLAZY MATCHING 22862306a36Sopenharmony_ci------------- 22962306a36Sopenharmony_ciThe 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]). 23062306a36Sopenharmony_ci 23162306a36Sopenharmony_cie.g. 23262306a36Sopenharmony_ci 'a=*' can matches 'a=b', 'a = b', 'a == b' and so on. 23362306a36Sopenharmony_ci 23462306a36Sopenharmony_ciThis 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.) 23562306a36Sopenharmony_ci 23662306a36Sopenharmony_ciFILTER PATTERN 23762306a36Sopenharmony_ci-------------- 23862306a36Sopenharmony_ciThe filter pattern is a glob matching pattern(s) to filter variables. 23962306a36Sopenharmony_ciIn 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 "(" ")". 24062306a36Sopenharmony_ci 24162306a36Sopenharmony_cie.g. 24262306a36Sopenharmony_ci With --filter "foo* | bar*", perf probe -V shows variables which start with "foo" or "bar". 24362306a36Sopenharmony_ci 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. 24462306a36Sopenharmony_ci 24562306a36Sopenharmony_ciEXAMPLES 24662306a36Sopenharmony_ci-------- 24762306a36Sopenharmony_ciDisplay which lines in schedule() can be probed: 24862306a36Sopenharmony_ci 24962306a36Sopenharmony_ci ./perf probe --line schedule 25062306a36Sopenharmony_ci 25162306a36Sopenharmony_ciAdd a probe on schedule() function 12th line with recording cpu local variable: 25262306a36Sopenharmony_ci 25362306a36Sopenharmony_ci ./perf probe schedule:12 cpu 25462306a36Sopenharmony_ci or 25562306a36Sopenharmony_ci ./perf probe --add='schedule:12 cpu' 25662306a36Sopenharmony_ci 25762306a36Sopenharmony_ciAdd one or more probes which has the name start with "schedule". 25862306a36Sopenharmony_ci 25962306a36Sopenharmony_ci ./perf probe schedule* 26062306a36Sopenharmony_ci or 26162306a36Sopenharmony_ci ./perf probe --add='schedule*' 26262306a36Sopenharmony_ci 26362306a36Sopenharmony_ciAdd probes on lines in schedule() function which calls update_rq_clock(). 26462306a36Sopenharmony_ci 26562306a36Sopenharmony_ci ./perf probe 'schedule;update_rq_clock*' 26662306a36Sopenharmony_ci or 26762306a36Sopenharmony_ci ./perf probe --add='schedule;update_rq_clock*' 26862306a36Sopenharmony_ci 26962306a36Sopenharmony_ciDelete all probes on schedule(). 27062306a36Sopenharmony_ci 27162306a36Sopenharmony_ci ./perf probe --del='schedule*' 27262306a36Sopenharmony_ci 27362306a36Sopenharmony_ciAdd probes at zfree() function on /bin/zsh 27462306a36Sopenharmony_ci 27562306a36Sopenharmony_ci ./perf probe -x /bin/zsh zfree or ./perf probe /bin/zsh zfree 27662306a36Sopenharmony_ci 27762306a36Sopenharmony_ciAdd probes at malloc() function on libc 27862306a36Sopenharmony_ci 27962306a36Sopenharmony_ci ./perf probe -x /lib/libc.so.6 malloc or ./perf probe /lib/libc.so.6 malloc 28062306a36Sopenharmony_ci 28162306a36Sopenharmony_ciAdd a uprobe to a target process running in a different mount namespace 28262306a36Sopenharmony_ci 28362306a36Sopenharmony_ci ./perf probe --target-ns <target pid> -x /lib64/libc.so.6 malloc 28462306a36Sopenharmony_ci 28562306a36Sopenharmony_ciAdd a USDT probe to a target process running in a different mount namespace 28662306a36Sopenharmony_ci 28762306a36Sopenharmony_ci ./perf probe --target-ns <target pid> -x /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el7_3.x86_64/jre/lib/amd64/server/libjvm.so %sdt_hotspot:thread__sleep__end 28862306a36Sopenharmony_ci 28962306a36Sopenharmony_ciAdd a probe on specific versioned symbol by backslash escape 29062306a36Sopenharmony_ci 29162306a36Sopenharmony_ci ./perf probe -x /lib64/libc-2.25.so 'malloc_get_state\@GLIBC_2.2.5' 29262306a36Sopenharmony_ci 29362306a36Sopenharmony_ciAdd a probe in a source file using special characters by backslash escape 29462306a36Sopenharmony_ci 29562306a36Sopenharmony_ci ./perf probe -x /opt/test/a.out 'foo\+bar.c:4' 29662306a36Sopenharmony_ci 29762306a36Sopenharmony_ci 29862306a36Sopenharmony_ciPERMISSIONS AND SYSCTL 29962306a36Sopenharmony_ci---------------------- 30062306a36Sopenharmony_ciSince perf probe depends on ftrace (tracefs) and kallsyms (/proc/kallsyms), you have to care about the permission and some sysctl knobs. 30162306a36Sopenharmony_ci 30262306a36Sopenharmony_ci - Since tracefs and kallsyms requires root or privileged user to access it, the following perf probe commands also require it; --add, --del, --list (except for --cache option) 30362306a36Sopenharmony_ci 30462306a36Sopenharmony_ci - The system admin can remount the tracefs with 755 (`sudo mount -o remount,mode=755 /sys/kernel/tracing/`) to allow unprivileged user to run the perf probe --list command. 30562306a36Sopenharmony_ci 30662306a36Sopenharmony_ci - /proc/sys/kernel/kptr_restrict = 2 (restrict all users) also prevents perf probe to retrieve the important information from kallsyms. You also need to set to 1 (restrict non CAP_SYSLOG users) for the above commands. Since the user-space probe doesn't need to access kallsyms, this is only for probing the kernel function (kprobes). 30762306a36Sopenharmony_ci 30862306a36Sopenharmony_ci - Since the perf probe commands read the vmlinux (for kernel) and/or the debuginfo file (including user-space application), you need to ensure that you can read those files. 30962306a36Sopenharmony_ci 31062306a36Sopenharmony_ci 31162306a36Sopenharmony_ciSEE ALSO 31262306a36Sopenharmony_ci-------- 31362306a36Sopenharmony_cilinkperf:perf-trace[1], linkperf:perf-record[1], linkperf:perf-buildid-cache[1] 314