analyze: do not print timestamps before "start of userspace"
commit1d640a044f30d824d19e647ecf477fbd1bc95602
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 20 May 2024 13:10:32 +0000 (20 15:10 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 20 May 2024 16:31:32 +0000 (20 18:31 +0200)
tree1a6cee6a256469e2c0c67516be0c542d0d069011
parenta56ffe2ca97c8ee6ab1166a3e0ba5bf420c24b26
analyze: do not print timestamps before "start of userspace"

We have the following timestamp status:

  $ systemctl show systemd-fsck-root.service | grep InactiveExitTimestamp
  InactiveExitTimestamp=Thu 2023-11-02 12:27:24 CET
  InactiveExitTimestampMonotonic=15143158

  $ systemctl show | grep UserspaceTimestamp
  UserspaceTimestamp=Thu 2023-11-02 12:27:25 CET
  UserspaceTimestampMonotonic=15804273

i.e. UserspaceTimestamp is before InactiveExit of systemd-fsck-root.service.
This is fine, but on display, we'd subtract those values and print a huge
negative value bogusly:

  $ build/systemd-analyze critical-chain systemd-remount-fs.service
  The time when unit became active or started is printed after the "@" character.
  The time the unit took to start is printed after the "+" character.

  systemd-remount-fs.service +137ms
  └─systemd-fsck-root.service @584542y 2w 2d 20h 1min 48.890s +45ms
    └─systemd-journald.socket
      └─system.slice
        └─-.slice

In fact, list_dependencies_print() already had a branch where the check that
'times->activating > boot->userspace_time', but it didn't cover all cases. So
make it cover both branches, and also change to '>=', since it's fine if
something happened with the same timestamp.

With the patch:

  $ build/systemd-analyze critical-chain systemd-remount-fs.service
  The time when unit became active or started is printed after the "@" character.
  The time the unit took to start is printed after the "+" character.

  systemd-remount-fs.service +42ms
  └─systemd-fsck-root.service
    └─systemd-journald.socket
      └─system.slice
        └─-.slice

Fixes https://github.com/systemd/systemd/issues/17191.
src/analyze/analyze-critical-chain.c