Chapter 22. Analyzing system performance with BPF Compiler Collection
The BPF Compiler Collection (BCC) analyzes system performance by combining the capabilities of Berkeley Packet Filter (BPF). With BPF, you can safely run the custom programs within the kernel to access system events and data for performance monitoring, tracing, and debugging. BCC simplifies the development and deployment of BPF programs with tools and libraries for users to extract important insights from their systems.
22.1. Installing the bcc-tools package Copy linkLink copied to clipboard!
Install the bcc-tools
package to get the BPF Compiler Collection (BCC) library and related tools.
Procedure
Install bcc-tools.
dnf install bcc-tools
# dnf install bcc-tools
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The BCC tools are installed in the
/usr/share/bcc/tools/
directory.
Verification
Inspect the installed tools.
ls -l /usr/share/bcc/tools/
# ls -l /usr/share/bcc/tools/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow A list of tools installed appears. The
doc
directory in the listing provides documentation for each tool.
22.2. Examining the system processes with execsnoop Copy linkLink copied to clipboard!
The execsnoop
tool from the BCC suite captures and displays new process execution events in real time. It is useful for observing which commands or binaries are being executed on a system, helping with debugging, auditing, and security monitoring.
Procedure
Run the
execsnoop
program in one terminal:/usr/share/bcc/tools/execsnoop
# /usr/share/bcc/tools/execsnoop
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To create a short-lived process of the
ls
command, in another terminal, enter:ls /usr/share/bcc/tools/doc/
$ ls /usr/share/bcc/tools/doc/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The terminal running
execsnoop
shows the output similar to the following:PCOMM PID PPID RET ARGS ls 8382 8287 0 /usr/bin/ls --color=auto /usr/share/bcc/tools/doc/
PCOMM PID PPID RET ARGS ls 8382 8287 0 /usr/bin/ls --color=auto /usr/share/bcc/tools/doc/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
execsnoop
program prints a line of output for each new process that consumes system resources. It even detects processes of programs that run very shortly, such asls
, and most monitoring tools would not register them. Theexecsnoop
output displays the following fields:- PCOMM
-
The parent process name. (
ls
) - PID
- The process ID. (8382)
- PPID
- The parent process ID. (8287)
- RET
- The return value of the exec() system call (0), which loads program code into new processes.
- ARGS
The location of the started program with arguments.
For more information, see the
/usr/share/bcc/tools/doc/execsnoop_example.txt
file and theexec(3)
man page on your system.
22.3. Tracking files opened by a command with opensnoop Copy linkLink copied to clipboard!
You can use the opensnoop
tool from the BCC (BPF Compiler Collection) to monitor and log file access by a specific command in real time. This is useful for debugging, auditing, or understanding the runtime behavior of an application.
Procedure
In one terminal, run the
opensnoop
program to print the output for files opened only by the process of theuname
command:/usr/share/bcc/tools/opensnoop -n uname
# /usr/share/bcc/tools/opensnoop -n uname
Copy to Clipboard Copied! Toggle word wrap Toggle overflow In another terminal, enter the command to open certain files:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
opensnoop
program watches theopen()
system call across the whole system, and prints a line of output for each file thatuname
tries to open along the way. Theopensnoop
output displays the following fields:- PID
- The process ID. (8596)
- COMM
-
The process name. (
uname
) - FD
- The file descriptor - a value that open() returns to refer to the open file. (3)
- ERR
- Any errors.
- PATH
The location of files that
open()
tries to open.If a command tries to read a non-existent file, the FD column returns
-1
and the ERR column prints a value corresponding to the relevant error. By usingopensnoop
, you can identify an application that does not behave properly. For more information, see the/usr/share/bcc/tools/doc/opensnoop_example.txt
file andopen(2)
man page on your system.
22.4. Monitoring the top processes performing I/O operations on the disk with biotop Copy linkLink copied to clipboard!
The biotop
tool provides a real-time view of processes generating the most disk I/O activity. It identifies applications that are heavily reading from or writing to the disk, making it a valuable utility for performance monitoring and troubleshooting.
Procedure
Run the
biotop
program in one terminal with 30 as an argument to produce 30 second summary:/usr/share/bcc/tools/biotop 30
# /usr/share/bcc/tools/biotop 30
Copy to Clipboard Copied! Toggle word wrap Toggle overflow When you do not provide any argument, the output screen refreshes every 1 second by default.
In another terminal, enter command to read the content from the local hard disk device and write the output to the
/dev/zero
file:dd if=/dev/vda of=/dev/zero
# dd if=/dev/vda of=/dev/zero
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This step generates certain I/O traffic to illustrate
biotop
. The terminal runningbiotop
shows an output similar to the following:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
biotop
output displays the following fields:- PID
- The process ID. (9568)
- COMM
-
The process name. (
dd
) - DISK
- The disk performs the read operations. (vda)
- I/O
- The number of read operations performed. (16294)
- Kbytes
- The amount of Kbytes reached by the read operations. (14,440,636)
- AVGms
The average I/O time of read operations. (3.69)
For more information, see the
/usr/share/bcc/tools/doc/biotop_example.txt
file and thedd(1)
man page on your system.
22.5. Exposing unexpectedly slow file system operations with xfsslower Copy linkLink copied to clipboard!
The xfsslower
measures the time spent by the XFS file system in performing read, write, open or sync (fsync)
operations. The argument 1
ensures that the program shows only the operations that are slower than 1 ms.
Procedure
Run the
xfsslower
program in one terminal:/usr/share/bcc/tools/xfsslower 1
# /usr/share/bcc/tools/xfsslower 1
Copy to Clipboard Copied! Toggle word wrap Toggle overflow When you do not provide any arguments,
xfsslower
displays operations slower than 10 ms by default.In another terminal, enter the command to create a text file in the vim editor to start interaction with the XFS file system:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Each line represents an operation in the file system, which took more time than a certain threshold.
xfsslower
detects possible file system problems, which can take the form of unexpectedly slow operations. Thexfsslower
output displays the following fields:- COMM
-
The process name. (
b’bash'
) - T
The operation type. (
R
)- Read
- Write
- Open
- Sync
- OFF_KB
- The file offset in KB. (0)
- FILENAME
The file that is read, written, or synced.
For more information, see the
/usr/share/bcc/tools/doc/xfsslower_example.txt
file and thefsync(2)
man page on your system.