Products › lamco-dbus-tools › Interfaces
eBPF with CAP_BPF and CAP_PERFMON: Timing D-Bus at each socket
eBPF with CAP_BPF and CAP_PERFMON stamps every D-Bus message at each socket it crosses, which lamco-dbus-tools uses to split a call's time at each socket.
A monitor on the bus sees a call when the bus passes it on and the answer when the bus passes that on. It can't see how long the message sat in a socket, how long the bus took, or how long the service took. The kernel can, because every D-Bus message crosses a local stream socket twice on its way. lamco-dbus-tools has an optional kernel part, loaded by dbuskeep kernel with two capabilities, CAP_BPF and CAP_PERFMON, that stamps each message at every socket it crosses. With it, a call's time divides into the caller's, the sockets', the bus's and the service's.
What it is
eBPF lets a privileged process attach small verified programs to points in the kernel. The kernel part attaches fentry and fexit programs to unix_stream_sendmsg and unix_stream_recvmsg, the functions behind each write to and read from a local stream socket. The capabilities(7) manual describes the two capabilities this takes, both added in Linux 5.8 to split them out of CAP_SYS_ADMIN: CAP_BPF for privileged BPF operations, and CAP_PERFMON for performance monitoring, BPF operations among it.
A socket counts as a bus's when its address, or its peer's, is one the service was told of. For those, each message that starts in the bytes moved is reported with its serial, its reply serial, its type and flags, its length, the process and control group, and two stamps on CLOCK_MONOTONIC, the clock the recorder uses: When the write or read began and ended. Nothing of a message's content is kept, not its body, path, interface or member.
A call crosses four sockets and is followed through eight stamps: The caller writes, the bus reads, the bus writes to the service, the service reads, the service writes its answer, the bus reads it, the bus writes to the caller, and the caller reads. The seven gaps sum to the kernel's span of the call.
What it does with its privilege: Every write and read on every local stream socket of the machine passes the hooks while the service runs, including those of programs that have nothing to do with D-Bus. A bus's events go only to whoever may read that bus: The system bus's to root and the group lamco-dbus-monitor, any other's to the user whose socket it is and root. It stops on SIGINT or SIGTERM, and the hooks go with it: Nothing is pinned. It needs a kernel that describes its own types (/sys/kernel/btf/vmlinux), from 5.5 on x86_64 and 6.0 on 64-bit ARM, where the programs have run only under emulation.
How lamco-dbus-tools reads it
The kernel part is loaded first, as root or as a service given exactly the two capabilities, as the system unit does. dbussee record --kernel tells it of the bus and fetches that bus's events for the recording's span. dbusdo call --repeat makes the calls, each stamped at the caller. dbustell timing --caller --split joins the three and gives each call's time at the caller, at the bus and at each socket, split into the bus's, the service's, the sockets' and the caller's own. dbuskeep kernel-status says what it watches and holds.
dbuskeep kernel # load the hooks (CAP_BPF and CAP_PERFMON, or root)
dbuskeep kernel-status # buses watched, events held, and the hooks' own counts
dbussee record --kernel --all --duration 10 --out rec.json # a recording with the kernel's stamps
dbusdo --out acts.json call --repeat 100 org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.DBus.Peer.Ping # calls stamped at the caller
dbustell timing rec.json --caller acts.json --split # each call split at every socket
Only dbuskeep kernel loads anything into the kernel. Every other program works without it.
Where it has been run
The README's run record lists every call split at every socket, with every call's parts summing to the caller's figure, on Debian 13, Fedora 45 and Ubuntu 24.04 on x86_64 and Debian 13 on 64-bit ARM (2026-12-01). dbuskeep-kernel.service ran as root with exactly CAP_BPF and CAP_PERFMON on Debian 13, splitting 100 of 100 calls to logind on the system bus and 100 of 100 to each of two services on a desktop's session bus, and ran on Fedora 44 with SELinux enforcing, with no denial, and Ubuntu 24.04 (2026-12-02). On 64-bit ARM it ran on emulated Fedora 44 and Ubuntu 24.04 (2026-12-02). Every 64-bit ARM run was under emulation. No 64-bit ARM hardware has been run.
Related
- The bpf security module and refused connections, the kernel part's other hook.
- A slow call: The bus or the service?
- Enable the kernel part.
- capabilities(7), on
CAP_BPFandCAP_PERFMON.