kprobe(8) | System Manager's Manual | kprobe(8) |
kprobe - trace a given kprobe definition. Kernel dynamic tracing. Uses Linux ftrace.
kprobe [-FhHsv] [-d secs] [-p PID] [-L TID] kprobe_definition [filter]
This will create, trace, then destroy a given kprobe definition. See Documentation/trace/kprobetrace.txt in the Linux kernel source for the syntax of a kprobe definition, and "kprobe -h" for examples. With this tool, the probe alias is optional (it will become to kprobe:<funcname> if not specified).
WARNING: This uses dynamic tracing of kernel functions, and could cause kernel panics or freezes, depending on the function traced. Test in a lab environment, and know what you are doing, before use.
Also beware of feedback loops: tracing tcp functions over an ssh session, or writing ext4 functions to an ext4 file system. For the former, tcp trace data could be redirected to a file (as in the usage message). For the latter, trace to the screen or a different file system.
SEE ALSO: functrace(8), which can perform basic tracing (event only) of multiple kernel functions using wildcards.
Since this uses ftrace, only the root user can use this tool.
FTRACE and KPROBES CONFIG, which you may already have enabled and available on recent kernels.
The ftrace buffer has a fixed size per-CPU (see /sys/kernel/debug/tracing/buffer_size_kb). If you think events are missing, try increasing that size.
These examples may need modification to match your kernel version's function names and platform's register usage. If using platform specific registers becomes too painful in practice, consider a kernel debuginfo-based tracer, which can trace variables names instead. For example, perf_events.
The output format depends on the kernel version, and headings can be printed using -H. The format is the same as the ftrace function trace format, described in the kernel source under Documentation/trace/ftrace.txt.
Typical fields are:
This can generate a lot of trace data quickly, depending on the frequency of the traced events. Such data will cause performance overheads. This also works without buffering by default, printing function events as they happen (uses trace_pipe), context switching and consuming CPU to do so. If needed, you can try the "-d secs" option, which buffers events instead, reducing overhead. If you think the buffer option is losing events, try increasing the buffer size (buffer_size_kb).
It's a good idea to use funccount(8) first, which is lower overhead, to help you select which functions you may want to trace using kprobe(8).
This is from the perf-tools collection:
Also look under the examples directory for a text file containing example usage, output, and commentary for this tool.
Linux
Unstable - in development.
Brendan Gregg
2014-07-20 | USER COMMANDS |