Systems Performance 2nd Ed.



BPF Performance Tools book

Recent posts:
Blog index
About
RSS

BPF Performance Tools (book)




New tools developed for
this book colored red.


eBook preview first 100 pages


Chinese edition


Chinese/English edition

This is the official site for the book BPF Performance Tools: Linux System and Application Observability, published by Addison Wesley (2019). This book can help you get the most out of your systems and applications, helping you improve performance, reduce costs, and solve software issues. Here I'll describe the book, link to related content, and list errata and updates.

The book is available on Amazon.com (paperback, kindle), InformIT (paperback, PDF, etc), and Safari (here and here). The paper book was released in December 2019 but sold out immediately. ISBN-13: 9780136554820. (If you purchase through the Amazon or InformIT links, the book's technical editor earns a commission.)

The Amazon Kindle preview shows the first 100 pages out of this 880 page book.

There is also a companion book, Systems Performance: 2nd Edition (2020), that provides balanced coverage of performance analysis and methodologies using all tool types.

On this page: BPF, Screenshots, OSes, Audience, Tools, TOC, Related, Errata, Updates.

What is BPF?

Berkeley Packet Filter (BPF) is an in-kernel execution engine that processes a virtual instruction set, and has been extended recently (aka eBPF) for providing a safe way to extend kernel functionality. In some ways, eBPF does to the kernel what JavaScript does to websites: it allows all sorts of new applications to be created. BPF is now used for software defined networking, observability (this book), security enforcement, and more. The main front-ends for BPF performance tools are BCC and bpftrace. BPF itself is also becoming a technology name, and no longer an abbreviation.

Screenshots

As an example new tool from the book, readahead.bt provides a new view of file system read ahead performance: the age of read-ahead pages when they are finally referenced, and unused read-ahead pages while tracing:

# readahead.bt
Attaching 5 probes...
^C
Readahead unused pages: 128

Readahead used page age (ms):
@age_ms: 
[1]             2455 |@@@@@@@@@@@@@@@                                     |
[2, 4)          8424 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[4, 8)          4417 |@@@@@@@@@@@@@@@@@@@@@@@@@@@                         |
[8, 16)         7680 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@     |
[16, 32)        4352 |@@@@@@@@@@@@@@@@@@@@@@@@@@                          |
[32, 64)           0 |                                                    |
[64, 128)          0 |                                                    |
[128, 256)       384 |@@                                                  |

The book covers many of the existing tools as well, for example, tcplife for efficiently logging TCP session details:

# tcplife
PID   COMM   LADDR          LPORT RADDR          RPORT TX_KB RX_KB MS
4169  java   100.1.111.231  40158 100.2.116.192  6001      7    33 3590.91
4169  java   100.1.111.231  56940 100.5.177.31   6101      0     0 2.48
4169  java   100.1.111.231  6001  100.2.176.45   49482     0     0 17.94
4169  java   100.1.111.231  18926 100.5.102.250  6101      0     0 0.90
4169  java   100.1.111.231  44530 100.2.31.140   6001      0     0 2.64
4169  java   100.1.111.231  44406 100.2.8.109    6001     11    28 3982.11
34781 sshd   100.1.111.231  22    100.2.17.121   41566     5     7 2317.30
[...]

Apart from kernel resources, applications are also analyzed. The following book tool counts Java JNI usage by stack trace:

# bpftrace --unsafe jnistacks.bt
Tracing jni_NewObject* calls... Ctrl-C to end.
^C
Running /usr/local/bin/jmaps to create Java symbol files in /tmp...
Fetching maps for all java processes...
Mapping PID 25522 (user bgregg):
wc(1):   8350  26012 518729 /tmp/perf-25522.map

[...]
@[
    jni_NewObject+0
    Lsun/awt/X11GraphicsConfig;::pGetBounds+171
    Ljava/awt/MouseInfo;::getPointerInfo+2048
    Lnet/sf/freecol/client/gui/plaf/FreeColButtonUI;::paint+1648
    Ljavax/swing/plaf/metal/MetalButtonUI;::update+232
    Ljavax/swing/JComponent;::paintComponent+672
    Ljavax/swing/JComponent;::paint+2208
[...]
    Ljavax/swing/RepaintManager;::prePaintDirtyRegions+1556
    Ljavax/swing/RepaintManager$ProcessingRunnable;::run+572
    Ljava/awt/EventQueue$4;::run+1100
    call_stub+138
    JavaCalls::call_helper(JavaValue*, methodHandle const&, JavaCallArguments*, Th...
]: 232

This book doesn't just show the tools, it also explains caveats and gotchas. In this case jnistacks.bt is a simple tool, but getting it to work in production can mean fixing stack traces and symbols. These real-world gotchas are explained with recommended fixes and workarounds.

The book explains these and over 150 other BPF tools, as well as summarizing over 30 traditional performance analysis tools (top, vmstat, iostat, perf, Ftrace, etc) so that you can use the right tool for the job.

Operating Systems

Extended BPF is a built-in Linux kernel technology, added in parts since 3.18. At least Linux 4.9 is necessary to utilize the tools in this book. All Linux distributions can use the BPF tools (Ubuntu, CentOS, Fedora, Red Hat, etc): although the status of BCC and bpftrace varies for each distribution. Some have packages, others still require a build from source. See the install instructions for BCC and bpftrace.

Other operating systems including BSD (where BPF originated) are not covered in this book. As extended BPF is being ported elsewhere, a future edition of this book may cover more than Linux.

Audience

This book is primarily for engineers, developers, and support staff in enterprise and cloud environments. No programming is required, unless you want to, as you can use this book as either:

This book is also useful for students as a way to learn system internals in an interactive way: you can run and develop tools to examine the workings of the system.

Tools

Over 150 BPF tools are covered in the book, for performance analysis, troubleshooting, and other uses (e.g., security forensics). These tools provide observability for CPUs, memory, disks, file systems, networking, languages, applications, containers, hypervisors, security, and the Linux kernel. To explain how to analyze different languages, three types of execution are studied: compiled, JIT-compiled, and interpreted, using C, Java, and the bash shell as examples. The same approaches can be applied to other languages, and a summary for Node.js, C++, and Golang are included.

To cover all these targets, many new tools needed to be developed for this book. The diagram on the top right shows these new tools colored red. The source to these is included in the book, and can also be found here:

The /originals directory contains an as-is snapshot of the published tools, and /updated contains those tools plus updated versions.

Table of Contents

PDF Download eBook EPUB

The Safari online book store features early drafts of books for feedback, called "rough cuts." I'd never published one before, but did this time to see if it helped. It did not. This happened:

  1. I received next to no feedback from the rough cut.
  2. A badly-formatted EPUB version immediately appeared on pirate sites, months before the book was finished.

This pirate version is missing bug fixes and content I later added. It is really frustrating as I've worked hard to give readers the best possible experience, but some of you may be studying this draft instead, thinking that it's the final book. There is also (obviously) no way for the publisher to ask the pirates to update their version. Please only read the finished book, preferably "second printing" or later (as the second printing should include the errata fixes, listed below). One tell-tale sign: the cover of the final book includes the text "Foreword by Alexei Starovoitov...," and the early draft versions did not.

Related Content

Errata

1st Printing

1st & 2nd Printing

Updates

These are updates to BPF and its front-ends, many of which were mentioned in the book as "planned" and have since been implemented:

Thanks to all the reviewers, and to Deirdré Straughan for editing another one of my books!


Last updated: 02-May-2021