Products › lamco-dbus-tools › Use cases

A command that's slow the first time: D-Bus service activation

A command that's slow the first time, then fast: Time the D-Bus service activation behind timedatectl on the system bus as an ordinary user, with dbussee.

A command takes noticeably longer the first time after a while, then answers at once, and nothing in its answers is wrong. lamco-dbus-tools found the cause with dbussee, which recorded the system bus through its helper as an ordinary user, dbustell, whose activation showed the bus starting the service for the first call, and dbuskeep, which kept the bus so the start could be found after it happened.

A real run on 2026-12-02 on Debian 13 (a test VM, dbus-daemon 1.16.2 on the system bus), with a development build of lamco-dbus-tools, version 0.1.0, as an ordinary user. run.sh ran it, installing the helper and the system's dbuskeep for the run and taking both away after, and run.txt is its output as printed.

The symptom

timedatectl status takes noticeably longer the first time after a while, then answers at once, timed at the caller by the run's script:

timedatectl status: 77 ms
timedatectl status: 12 ms
timedatectl status: 12 ms

Six times as long, and on a slower or busier machine the first call is worse. Nothing is wrong with the answers. The question is where the time goes, asked of the system bus by someone who isn't root.

Recording the system bus as yourself

Only a privileged connection may listen to the system bus. The helper is the one piece that has the privilege, and only for the members of one group (recording the system bus):

$ sudo scripts/install-helper target/release/dbussee-monitor
Installed /usr/libexec/lamco-dbus-tools/dbussee-monitor, setuid root and executable by the group lamco-dbus-monitor.
$ sudo usermod -aG lamco-dbus-monitor "$USER"

The group counts from the next login; the run used sg lamco-dbus-monitor for it instead. Debian 13's dbus-daemon is 1.16.2, which has the flaw BUS-003 names, so a recording there needs --accept-known-flaw, given here for a recording of seconds. Recording the service behind timedatectl while it ran twice:

$ dbussee --quiet record --bus system --service org.freedesktop.timedate1 --duration 8 --accept-known-flaw --out first.json
$ dbustell activation first.json
1 activations. Request to name taken is on the recorder's clock, not known: The longest the bus took to answer a call to itself, which it answers at once. Request to started is to journald's receipt of the bus's or the service manager's line, on the same monotonic clock, and also holds however long journald took to receive it.

org.freedesktop.timedate1: started, requested by :1.437 with a call to org.freedesktop.DBus.Properties.GetAll
    name taken 73.89 ms after the request, not known

That's the first call's time: org.freedesktop.timedate1 wasn't running, the bus started it for the call, and it took its name 74 ms after the request, at the bus. The second call found it running. record ran the helper for itself, which became the monitor as dbussee-monitor listen and passed each message on. timing puts it in figures:

DESTINATION                METHOD                                   CALLS    ERR        MIN     MEDIAN       95TH       99TH        MAX
org.freedesktop.timedate1  org.freedesktop.DBus.Properties.GetAll       2      0    4.01 ms    4.01 ms   78.41 ms   78.41 ms   78.41 ms

Two calls to the service, at the bus: 78 ms with the start in it, 4 ms without. The "not known" beside the start says why: A recording of one service holds no call the bus answered itself, which is how the recorder measures its own lateness. A recording with --all would have one.

What isn't here is the service manager's side: Which unit ran and when it started. Those lines are in the system journal, which this user may not read; in the systemd-journal group, or as root, the recording holds them too and activation says when the unit started.

The helper by itself

dbussee-monitor listen can be run directly by any program that wants a guarded monitor of the system bus. Here it listened for two seconds to the bus's own signals while timedatectl ran, with a budget of 64 KiB waiting before it would detach itself:

$ ( sleep 2; timedatectl status > /dev/null ) | sg lamco-dbus-monitor -c "/usr/libexec/lamco-dbus-tools/dbussee-monitor listen --bus system --accept-known-flaw --match \"type='signal',sender='org.freedesktop.DBus'\" --budget-bytes 65536" > frames.bin

1,473 bytes, starting with LDTM1: The helper's frames (the helper).

After the fact, from the system's service

The first recording had to be running before the slow call. On a machine where the symptom comes and goes, the system's dbuskeep keeps the last minutes, so the recording can be asked for after:

$ sudo dbuskeep run --bus system --accept-known-flaw &
$ timedatectl status
$ dbussee --quiet --bus system record --all --ring 60 --now --after 0 --out after.json
$ dbuskeep --bus system status
dbuskeep 0.1.0 (process 6450) keeps bus 25a3d605432e5ed7943ff1776b0fbd81 (system), at /run/lamco-dbus-tools/keep/25a3d605432e5ed7943ff1776b0fbd81.sock: 709 messages, 193539 bytes, the oldest from 34.08 s ago; 709 read since it began, 0 readers now. It keeps 300 s.
$ dbustell activation after.json
1 activations. Request to name taken is on the recorder's clock, ± 204.23 µs: The longest the bus took to answer a call to itself, which it answers at once. Request to started is to journald's receipt of the bus's or the service manager's line, on the same monotonic clock, and also holds however long journald took to receive it.

org.freedesktop.timedate1: started, requested by :1.477 with a call to org.freedesktop.DBus.Properties.GetAll
    name taken 67.95 ms after the request, ± 204.23 µs

The same start, 68 ms at the bus, found three seconds after it happened, and now with its uncertainty: The whole bus was recorded, so the bus's own answers are in it. The service runs as root, which alone may monitor the system bus, and answers root and the group lamco-dbus-monitor; a process outside the group is told why:

dbuskeep status: the service at /run/lamco-dbus-tools/keep/25a3d605432e5ed7943ff1776b0fbd81.sock refused: the system service answers root and the group lamco-dbus-monitor, which this process isn't in

The cause, and what to do

systemd-timedated is started by the bus when it's first asked and leaves when it has been idle for a while. Every first call after that pays for its start, 68 to 74 ms at the bus here. That's by design, and for timedatectl it's harmless. For a program that calls such a service in a loop with pauses longer than its idle time, it isn't: Each call pays the start again. The cure is the caller's, to keep the service's name watched or the calls close together, or the service's, to stay longer.

Taken away

$ sudo scripts/install-helper --uninstall
$ sudo gpasswd -d "$USER" lamco-dbus-monitor
$ sudo groupdel lamco-dbus-monitor

The system's dbuskeep was stopped with SIGTERM, and its directory under /run removed. The run's last line: No process, helper or group left.

Related