Products › lamco-dbus-tools › Docs

What a D-Bus monitor costs the bus, and how dbussee guards it

What a D-Bus monitor costs the bus, measured on dbus-daemon and dbus-broker, and how the recorder's guards keep a slow or stopped monitor from stalling it.

Describes version 0.4.1. Measured from 2026-11-27 to 12-01 on private buses and test machines. Each section names its measurement, and docs/measurements/stage-2/README.md has the first runs and how to repeat them.

A tool that watches a bus is a participant on it. These are the ways it can disturb what it watches, what was measured, and what the toolkit does about each.

Monitoring costs the calls being watched

When a program becomes a monitor, the bus copies messages to it. With dbussee record as the monitor, a caller making 5,000 small calls or 1,500 of 64 KiB, under no load and under 2,000 or 20,000 signals a second:

dbus-daemon 1.16.2 dbus-broker 37
The bus's CPU time, recording everything 16 to 45% higher 27 to 41% higher
The same with dbus-monitor or busctl capture 12 to 34% higher 22 to 53% higher
Recording a name nobody owns, with --service 1 to 7% higher 26 to 47% higher
The caller's median round trip At most 48 µs slower, on 64 KiB calls At most 41 µs slower

The cost is the copying, so it falls on any tool, and recording everything costs about what the standard tools cost. Narrow rules are where the two buses differ. On dbus-daemon a rule that matches little costs little. On dbus-broker any rule on a destination costs about a quarter more bus time under load, whether or not anything matches it, while rules on sender, interface or path cost only what they match. That was found by trying each rule alone. --service takes the calls to a service by destination, since nothing else in a header says where a call goes.

The guards: A recording asks for what its command needs, and everything only when asked: record, watch and pending refuse to run with no filter and no --all. On dbus-broker, a recording that has to be cheap uses --match "sender='NAME'" for what a service sends, or an interface rule for the calls to it, and the help says so.

A monitor that falls behind can hurt other programs

This was the most serious finding of the research.

  • A monitor reading slowly made both buses buffer for it without limit over the test. In 12 seconds dbus-daemon grew from 5 MB to 198 MB and dbus-broker from 3 MB to 440 MB.
  • A monitor that stopped reading, on dbus-daemon: The sending program stalled and never finished.
  • A monitor that stopped reading, on dbus-broker: The queue reached the per-user limit of 512 MiB. The broker then disconnected the monitor, the sender, and a third program of the same user that was in the middle of an unrelated call.

On a session bus every program belongs to one user, so a stalled monitor there can knock ordinary programs off the bus.

The guards, as built:

  • The monitoring connection has one job: A reader that reads, stamps the arrival and hands off. Decoding and writing happen on another thread. The library's own queue of 64 messages, which stops reading when it's full, is raised to 16,384.
  • The reader counts the bytes handed off and not yet written. Past a budget it closes its own connection. The budget is 16 MiB, or an eighth of the bus's own limit for one connection where it can be read: dbus-broker's --max-bytes from its command line, dbus-daemon's max_outgoing_bytes from its configuration and what that includes, or the daemon's built-in 127 MiB. --budget sets it.
  • A recording that was cut says so: Its monitor record says it detached, at which message and with how many bytes waiting, the most that was ever waiting, and the writer's longest lag. It's whole up to there, and the command exits 1.

Tested on both buses, with the writer slowed to 50 ms a message and 300 signals of 64 KiB sent at it: The recorder detached itself, never held more than its budget, the sender finished in about 1.2 s, and an unrelated service still answered. A slow disk, a full pipe or a terminal that stops reading (Ctrl-S) are all a slow writer, and all covered.

What the guard can't cover: It's inside the recorder, so it can't act while the whole recorder is stopped. Measured, with the recorder stopped while a sender sent 2,000 signals of 64 KiB a second:

  • With SIGTSTP, which Ctrl-Z sends, the recorder now ends, whole, instead of stopping. Neither bus was disturbed: The sender sent everything, and an unrelated service answered.
  • With SIGSTOP, which kill -STOP and a debugger use and no program can take, only the bus's limits act. dbus-daemon held 128 MiB for the recorder and stalled the sender. dbus-broker held 512 MiB, then cut the sender and the recorder off and refused a new call from the same user. The recorder saw it when it ran again, exited 1, and its capture says the bus closed the connection.

With --helper, dbussee-monitor covers this case: It keeps the monitor connection, reads and guards in a process of its own session and process group, and passes messages to the recorder through a pipe. A recorder stopped behind it stops only the pipe's far end, and the helper detaches. Measured on both buses, with the recorder held stopped by SIGSTOP while 300 signals of 64 KiB were sent: The helper detached, the sender was done in about 1.1 s, and an unrelated service still answered. The system bus always goes through the helper for an ordinary user, and the helper there can't be stopped by its caller. Without --helper, don't stop a recorder under a debugger on a bus that matters.

Many readers, one monitor

Every monitor costs the bus its copying, and two programs recording one bus cost it twice. dbuskeep is one monitor for every reader: Recordings read from it, each with its own rules applied by the service as the bus would apply them, and it keeps the last minutes, --window seconds and at most --held-cap MiB, the oldest let go first past either.

Measured (docs/measurements/stage-14/README.md), under 100,000 signals in 5 seconds: A rule that takes every message cost the bus 3 to 4% with a monitor of its own and nothing more through the service, which paid about 3.5 µs a message instead. A narrow rule cost nothing measurable either way. A reader that stops reading is cut off by the service as the recorder cuts itself off, and the service's own monitor reads on.

The kernel part

dbuskeep kernel sits below every bus, on the kernel's writes to and reads from local stream sockets, so it costs every such socket on the machine while it runs, not only the buses'. Measured (docs/measurements/stage-11/README.md), one byte written and read: 555 ns more on Debian 13 for a pair of unnamed sockets, 826 ns for a named socket that isn't a bus's, and 14 and 306 ns on Fedora 45. It needs only CAP_BPF and CAP_PERFMON, holds what it stamps in a ring of fixed size, and counts what it couldn't keep. --refuse changes behavior, refusing connections to a bus from one control group, and only where the kernel's security modules include bpf.

Many monitors at once, on dbus-broker

A recording's first act is a snapshot of who's on the bus. dbus-broker sends a process descriptor with every GetConnectionCredentials answer, and every monitor gets a copy, so many recorders starting at once went past the user's quota of 64 descriptors and the bus disconnected monitors, dbuskeep's among them. On dbus-broker the snapshot now asks GetConnectionUnixProcessID and GetConnectionUnixUser instead, which carry no descriptor, and the record says so (credentials_from). The test many_recorders_at_once starts 40 recorders beside 30 connections: 22 were cut off on dbus-broker before the change, and none after.

The recorder's own cost

What the recorder takes for itself, recording 30,000 messages: A capture written as one document holds every record until it ends, about 3.7 KiB a message at its peak, and 18 µs of CPU a message. A stream writes each record as it comes, holds 11 MiB however long it runs, and takes 10 µs a message. A ring holds each record as compact JSON, about 0.9 KiB a message.

The guards: A document stops at 20,000 messages unless told otherwise, about 75 MiB. A stream has no cap on messages but a size cap, 1 GiB unless told. A ring stops at 200,000 messages.

Asking can start things

See the layers. The guard: Every message a watching command sends carries the flag that forbids starting. A monitor sends nothing after it becomes one: The bus would cut it off if it did.

A known flaw in one version

dbus-daemon 1.16.4, released 2026-11-12, fixes a flaw by which an unprivileged user could crash the system bus while a privileged monitor was attached. Debian 13 ships 1.16.2.

The guard, as built: Before monitoring a system bus, the recorder reads the daemon's version from the snapshot it takes first. On a version older than 1.16.4 it refuses, says why, and sends nothing to the bus; --accept-known-flaw goes on. dbuskeep run for the system bus refuses the same way, with the same flag. A distribution may have patched the flaw without changing the version, which the version can't show.

A recording holds secrets

Passwords handed to the network service, items from the keyring and the text of notifications all cross the bus.

The guards: A body is recorded as its length unless more is asked for. --bodies hash adds a SHA-256, which tells two bodies apart and says nothing of either. --bodies decoded keeps the values and --bodies raw the bytes, and the help says both can hold secrets, as can a pcapng file written with --pcap, which holds every byte. The one exception is the bus's own owner changes, which are always decoded: They hold only names, and without them a reader can't follow who owned a name when a call was made. For a bug report, dbustell scrub writes a capture with the bodies removed and the host's name and users' names replaced, and dbustell bundle writes it with every report of it, each from the scrubbed capture. Read it before you post it.

The tool is visible

Its connections are announced like any other, and its questions to the bus are traffic. A recording uses two connections: One for the snapshot, closed before the second becomes the monitor. The monitor's own first messages, its name being given and taken back as it becomes a monitor, are in its recording, as dbus-monitor shows them and busctl doesn't.

The guard: Everything the tool does is in its own recording, as its own act: The snapshot's questions, the monitor's rules, its queue and budget and where the budget came from, how many messages it read and how it ended.