Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

BCC Best Linux Performance Monitoring Tools

· 6 min read · Home Tech

In this article
  1. What is BCC and Why Does It Matter?
  2. Key BCC Tools for Performance Monitoring
  3. How to Install and Get Started
  4. Choosing the Right Tool for Your Problem
  5. bpftrace: The Scripting Companion
  6. Common Pitfalls and How to Avoid Them
  7. BCC vs. Other Monitoring Tools
  8. Cost and Safety Considerations
  9. Frequently Asked Questions

The best Linux performance monitoring tools built on BPF Compiler Collection (BCC) are bcc-tools (a suite of over 100 individual utilities) and the bpftrace scripting language, which together let you trace kernel and application behavior in real time with minimal overhead. These tools are essential for diagnosing CPU, memory, I/O, and network issues that traditional monitoring tools can't see.

What is BCC and Why Does It Matter?

BCC (BPF Compiler Collection) is a toolkit for creating efficient kernel tracing and manipulation programs. It leverages eBPF (extended Berkeley Packet Filter), a kernel technology that allows sandboxed programs to run in kernel space without writing a kernel module. This means you can safely inspect what's happening inside your Linux system at a granular level—every system call, every function call, every packet—without the overhead of traditional tracing methods.

Traditional tools like top or vmstat give you aggregated counters. BCC tools dig deeper: they can show you which specific process is causing I/O, which file is being accessed, or why a particular function is slow. This makes BCC invaluable for performance debugging and capacity planning.

Key BCC Tools for Performance Monitoring

The BCC repository ships with dozens of ready-to-use tools. Here are the most important ones, grouped by subsystem:

  • CPU: profile (CPU sampling stack traces), cpuunclaimed (identify idle CPUs despite runnable threads), runqlat (scheduler run queue latency).
  • Memory: oomkill (trace out-of-memory killer), memleak (detect kernel memory leaks), ssllower (trace SSL/TLS operations).
  • Disk I/O: biotop (top disk I/O by process), biosnoop (trace block I/O with latency), fileslower (trace slow file reads/writes).
  • Network: tcplife (TCP session lifecycle), tcpconnect (trace outbound TCP connections), tcpdrop (trace kernel TCP packet drops).
  • File Systems: filetop (file reads/writes by process), cachestat (page cache hit/miss statistics).

Each tool is a standalone executable; you can run them directly from the command line. For example, sudo biotop shows a live updating view of disk I/O per process, similar to top but for block I/O.

How to Install and Get Started

Installation varies by distribution. On Ubuntu/Debian:

sudo apt-get install bpfcc-tools linux-headers-$(uname -r)

On RHEL/CentOS/Fedora:

sudo dnf install bcc-tools

After installation, the tools are usually in /usr/share/bcc/tools. Add that to your PATH or invoke them with the full path. Most tools require root privileges because they load eBPF programs into the kernel.

Start with a simple tool like execsnoop to see every new process:

sudo /usr/share/bcc/tools/execsnoop

This prints one line per process execution, showing the PID, parent PID, and command line. It's a great way to understand what's running on your system.

Choosing the Right Tool for Your Problem

With over 100 tools, knowing which one to use is half the battle. Here's a quick decision guide:

  • CPU is pegged at 100%? Use profile to sample stack traces and identify the exact code path.
  • Disk I/O is slow? Use biosnoop to see per-request latency and biotop to find the culprit process.
  • Network latency spikes? Use tcplife to see connection durations and tcpconnlat to measure connection establishment latency.
  • Application is slow but CPU/disk look fine? Use runqlat to check scheduler latency, or funclatency to measure a specific kernel function's latency.

If you're unsure, the tool command (yes, that's the name) provides a text-based menu to browse all tools by category.

bpftrace: The Scripting Companion

While the pre-built tools cover common scenarios, you'll often need custom tracing. bpftrace is a high-level language for eBPF that lets you write one-liners and scripts. For example, to trace all open system calls:

sudo bpftrace -e 'tracepoint:syscalls:sys_enter_openat { printf("%s %s\n", comm, str(args->filename)); }'

This prints the process name and file being opened. bpftrace syntax is similar to awk, making it approachable for system administrators. It's included with BCC or can be installed separately.

For complex tracing, bpftrace scripts can be saved to files. The BCC repository includes many examples, and the official documentation has a reference guide.

Common Pitfalls and How to Avoid Them

  • Running without root: Most BCC tools need root. Use sudo or configure capabilities.
  • Kernel version too old: eBPF features are constantly evolving. BCC requires a reasonably recent kernel (4.x+). Check your kernel with uname -r.
  • Missing kernel headers: Tools that attach to kernel functions need headers. Install the matching linux-headers package.
  • Overhead concerns: While BCC is low-overhead, running many tools simultaneously can add up. Use them for short diagnostic sessions, not permanent monitoring.
  • Misinterpreting output: Always read the tool's man page or --help output. For example, biosnoop shows timestamps in microseconds, not milliseconds.

BCC vs. Other Monitoring Tools

BCC is not a replacement for traditional monitoring like top, htop, or atop—it's a complement. Traditional tools give you a high-level overview; BCC gives you microscopic detail. For example, top shows that a process uses 90% CPU, but profile shows that it's spending all that time in a specific kernel function. Similarly, iostat shows disk utilization, but biosnoop shows which file and process caused each I/O.

BCC also differs from tools like perf and ftrace. perf is powerful for sampling and hardware events but has a steeper learning curve. ftrace is kernel-level but requires manual setup. BCC offers a middle ground: ready-to-use tools with the ability to customize.

For production environments, consider combining BCC with a time-series database and visualization tool like Prometheus and Grafana. BCC can export metrics via bcc-exporter or you can write custom bpftrace scripts to feed data into your monitoring stack.

Cost and Safety Considerations

BCC is open-source and free to use. There's no licensing cost, and it's included in most Linux distributions' package repositories. The main cost is the learning curve and the need for root access.

Safety is a key advantage of eBPF: programs are verified by the kernel before execution, preventing crashes or infinite loops. However, you should still be careful when writing custom bpftrace scripts—a logic error can produce misleading data or, in rare cases, affect system performance. Always test in a staging environment first.

One misconception is that BCC tools are only for kernel developers. In reality, they're designed for system administrators and DevOps engineers. The pre-built tools require no programming knowledge; you just run them and read the output.

Frequently Asked Questions

Do BCC tools work on all Linux distributions?

BCC works on any Linux distribution with a kernel version 4.1 or newer (though some tools need newer features). Most major distros package BCC in their repositories. If not, you can build from source, but that requires compilation tools and kernel headers.

How much overhead do BCC tools add?

Overhead is typically 1-5% depending on the tool and workload. Tools that sample (like profile) have lower overhead than those that trace every event (like biosnoop). For most diagnostic sessions, the overhead is negligible.

Can BCC monitor containers and Kubernetes?

Yes. BCC tools work at the kernel level, so they see all processes regardless of container boundaries. Some tools have container-aware options (e.g., --cgroupmap) to filter by cgroup. For Kubernetes, you can run BCC tools on the host or in privileged pods.

What's the difference between BCC and bpftrace?

BCC is a framework with pre-built tools and a Python API for writing custom programs. bpftrace is a separate, simpler scripting language that uses the same underlying eBPF mechanism. Use BCC tools for common tasks and bpftrace for quick, custom one-liners.

How do I update BCC tools?

Use your package manager (e.g., apt update && apt upgrade on Ubuntu). To get the latest features, you may need to install from the BCC GitHub repository or use distribution-specific backports. Always ensure your kernel is updated as well.