functrace(8)
β¨ functrace β it's giving kernel function tracing π
ok so bestie, welcome to functrace(8) from the System Manager's Manual. This is the one where we trace kernel function calls that match the wildcards you pick, and yeah β it runs on Linux ftrace. π
πΈ NAME πΈ
functrace β trace kernel function calls matching specified wildcards. Uses Linux ftrace. no cap, that's literally the whole job description.
π SYNOPSIS π
functrace [-hH] [-p PID] [-L TID] [-d secs] funcstring
π¦ DESCRIPTION π¦
This tool is your quick little main-character shortcut to capturing the execution of kernel functions. It shows you the basic details β the process ID, the timestamp, and the calling function. it's giving receipts, honestly.
β οΈ WARNING: This uses dynamic tracing of (what can be many) kernel functions, and could cause kernel panics or freezes. Test, and know what you are doing, before use. Likeβ¦ bestie, please know what you're doing. π
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. not the feedback loop sneaking up on you π
SEE ALSO: kprobe(8), which can dynamically trace a single function call or return, and examine CPU registers and return values. iconic of it tbh.
Since this uses ftrace, only the root user can use this tool. yes, root. the VIP section. π₯
β REQUIREMENTS β
FTRACE CONFIG, which you may already have enabled and available on recent kernels. check it, she's probably already there π«Ά
π OPTIONS π
-dseconds β Set the duration of tracing, in seconds. Trace output will be buffered and printed at the end. This also reduces overheads by buffering in-kernel, instead of printing events as they occur.
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. π
-hβ Print usage message. the classic cry for help (affectionate).-Hβ Print column headers. give the girl some labels π-pPID β Only trace kernel functions when this process ID is on-CPU.-LTID β Only trace kernel functions when this thread ID is on-CPU.funcstringβ A function name to trace, which may include file glob style wildcards ("*") at the beginning or ending of a string only. Eg,"vfs*"means match"vfs"followed by anything. beginning or ending ONLY, bestie β don't get creative with the middle π
π EXAMPLES π
Trace calls to do_nanosleep():
# functrace do_nanosleep
Trace calls to all kernel functions ending in "*sleep":
# functrace '*sleep'
Trace all "vfs*" kernel function calls for PID 198:
# functrace -p 198 'vfs*'
Trace all "tcp*" kernel function calls, and output to a file until Ctrl-C:
# functrace 'tcp*' > out
Trace all "tcp*" kernel function calls, output to a file, for 1 second (buffered):
# functrace -d 1 'tcp*' > out
π§ FIELDS π§
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:
- TASK-PID β The process name (which could include dashes), a dash, and the process ID.
- CPU# β The CPU ID, in brackets.
||||β Kernel state flags. For example, on Linux 3.16 these are for irqs-off, need-resched, hardirq/softirq, and preempt-depth.- TIMESTAMP β Time of event, in seconds.
- FUNCTION β Kernel function name.
π OVERHEAD π
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 functrace(8). do the cheap little vibe check before you commit, fr fr β¨
π SOURCE π
This is from the perf-tools collection:
https://github.com/brendangregg/perf-tools
Also look under the examples directory for a text file containing example usage, output, and commentary for this tool. yes there's commentary, we love a director's cut π
πΈ OS πΈ
Linux π§
π STABILITY π
Unstable β in development. she's still cooking, be nice to her π
π AUTHOR π
Brendan Gregg β the icon, the moment, the blueprint π«Ά
β SEE ALSO β
ok that's the whole page bestie, and just so you know this little beauty came out under USER COMMANDS β dated 2014-07-20 β and it's filed as functrace(8) in the manual. go trace something, love u, bye πβ¨π
π¦ where this page comes from
- nixos 26.05: perf-tools-unstable 2017-12-19
- nixpkgs unstable: perf-tools-unstable 2017-12-19
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms