LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

bpftrace

High-level tracing language for Linux eBPF.

TLDR

List all available probes
$ sudo bpftrace -l
copy
Run a one-liner program
$ sudo bpftrace -e 'tracepoint:raw_syscalls:sys_enter { @[comm] = count(); }'
copy
Run a program from file
$ sudo bpftrace [path/to/file]
copy
Trace a program by PID
$ sudo bpftrace -e 'tracepoint:raw_syscalls:sys_enter /pid == 123/ { @[comm] = count(); }'
copy
Trace a child command until it exits
$ sudo bpftrace -c '[command]' -e 'tracepoint:raw_syscalls:sys_enter { @[comm] = count(); }'
copy
Dry run and display compiled eBPF
$ sudo bpftrace -d -e '[one_line_program]'
copy
Display version
$ bpftrace -V
copy

SYNOPSIS

bpftrace [options] [program|file]

DESCRIPTION

bpftrace is a high-level tracing language for Linux eBPF. It provides a powerful scripting interface for kernel and userspace tracing, similar to DTrace on other Unix systems.Programs can attach to tracepoints, kprobes, uprobes, and other probe types to collect and aggregate data about system behavior in real-time.

PARAMETERS

-l [SEARCH]

List probes matching a search pattern (supports wildcards)
-e program
Execute a one-liner program
-d
Dry run; show compiled eBPF without executing
-p PID
Attach to process or filter by PID
-c COMMAND
Run command as a child process; bpftrace exits when it terminates
-v
Verbose output
-q
Quiet mode; suppress non-error messages
-V, --version
Display version information
--unsafe
Allow unsafe operations like system() calls
--info
Print information about kernel features and bpftrace build

CAVEATS

Requires root privileges. Kernel must have eBPF and BTF support enabled. Some probes may not be available on all kernel versions. Performance impact varies by probe type and frequency.

HISTORY

bpftrace was created by Alastair Robertson and first released in 2018. It was inspired by DTrace and aimed to bring similar high-level tracing capabilities to Linux using eBPF.

SEE ALSO

bpftool(8), perf(1), strace(1)

Copied to clipboard
Kai