Forrest logo
back to the bpftrace tool

bpftrace:tldr:b4dc3

bpftrace: Run a one-liner program (e.g. syscall count by program).
$ sudo bpftrace -e '${tracepoint:raw_syscalls:sys_enter { @[comm] = count(); }}'
try on your machine

This command uses the bpftrace tool with elevated privileges (sudo) to trace system calls being made by processes running on a Linux operating system.

Here is a breakdown of the command:

  • sudo: This allows the execution of the bpftrace command with root/administrator privileges. This is necessary because bpftrace relies on the extended Berkeley Packet Filter (eBPF) feature, which requires elevated privileges to access low-level system resources.

  • bpftrace: This is the command-line tool used for tracing and monitoring various aspects of a running Linux system. It leverages eBPF to dynamically inject tracepoints into the kernel and gather information.

  • -e: This flag specifies the trace program that should be executed by bpftrace. In this case, the program is enclosed within single quotes (') to ensure that the entire program is passed as a single argument to the bpftrace command.

  • ${tracepoint:raw_syscalls:sys_enter { @[comm] = count(); }}: This is the actual trace program written in the bpftrace language. It uses the tracepoint to specify that we want to trace raw system call events. More specifically, it traces the sys_enter event, which occurs right before a system call is about to start executing.

    Inside the program, we define an associative array or map @[comm] that counts the occurrences of each unique process name (comm). This means that for each system call made by a process, the program will increment the count associated with that process name in the @[comm] array.

In summary, this bpftrace command with the given trace program traces the entering of system calls and counts how many times each process makes a system call. The result will be a live display of process names along with the number of system calls made by each process.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the bpftrace tool