systemd-analyze Command Examples in Linux

The systemd-analyze command is used to retrieve performance statistics for boot operations. The command takes one or more subcommands that determine what type of information to print, and how. For process management and troubleshooting, blame is the most relevant subcommand. This will print a list of all systemd units that were executed at boot, along with the time it took each unit to execute. You can use systemd-analyze blame to identify services and other units that make the system slow to boot.

Syntax

The syntax of the systemd-analyze command is:

# systemd-analyze [options] [subcommand]

systemd-analyze command can be utilized to find out information about how much each service took to start. systemd-analyze time can provide overall information about how long it took system to start. Here is a command out which clearly shows the time taken by kernel, initrd and userspace while booting.

# systemd-analyze time
Startup finished in 1.267s (kernel) + 6.798s (initrd) + 1min 2.139s (userspace) = 1min 10.205s

To find out, how much time each unit took to start, run systemd-analyze blame.

# systemd-analyze blame
         24.728s dev-mapper-centosx2droot.device
         15.135s kdump.service
         14.670s plymouth-quit-wait.service
         14.210s firewalld.service
          9.835s accounts-daemon.service
          7.383s ModemManager.service
          7.259s libvirtd.service
          7.257s systemd-logind.service
          7.177s ksm.service
          7.081s gssproxy.service
          7.067s avahi-daemon.service
          7.062s rsyslog.service
          7.039s abrt-ccpp.service

As you see the output is sorted according to the time taken by each unit, you can easily find out which service is taking more time during booting and can dig down deeper to analyze the issue.

At certain steps, the boot cannot proceed until all dependencies for unit are satisfied. To see units at these critical points run systemd-analyze critical-chain.

# systemd-analyze critical-chain
The time after the unit is active or started is printed after the "@" character.
The time the unit takes to start is printed after the "+" character.

graphical.target @1min 2.102s
└─multi-user.target @1min 2.102s
  └─abrt-vmcore.service @1min 1.228s +872ms
    └─kdump.service @46.090s +15.135s
      └─remote-fs.target @46.086s
        └─remote-fs-pre.target @46.083s
          └─iscsi-shutdown.service @45.951s +99ms
            └─network.target @45.944s
              └─network.service @44.959s +975ms
                └─NetworkManager.service @38.653s +689ms
                  └─firewalld.service @24.439s +14.210s
                    └─basic.target @23.850s
                      └─sockets.target @23.849s
                        └─cups.socket @23.847s
                          └─sysinit.target @23.618s
                            └─systemd-update-utmp.service @23.603s +13ms
                              └─auditd.service @22.959s +643ms
                                └─systemd-tmpfiles-setup.service @22.726s +230ms
                                  └─rhel-import-state.service @22.431s +294ms
                                    └─local-fs.target @22.428s
                                      └─boot.mount @19.675s +2.126s
                                        └─dev-disk-byx2duuid-7de2053cx2d44d7x2d4f33x2db522x2d81dee2f6b69b.device @19.652s

SVG graphic image can be plot which contains detailing about system services start time, highlighting the time they spent on initialization. Make sure you have enabled graphical display mode or have x-windows enabled in order to see the plot.

# systemd-analyze plot > plot.svg
# eog plot.svg

Here is a snip from sample plot on my CentOS 7 machine. Zoom in to check the waterfall clearly.

systemd-analyze Command Examples

1. List time of each unit to start up:

# systemd-analyze blame

2. Print a tree of the time-critical chain of units:

# systemd-analyze critical-chain

3. Create an SVG file showing when each system service started, highlighting the time that they spent on initialization:

# systemd-analyze plot > path/to/file.svg

4. Plot a dependency graph and convert it to an SVG file:

# systemd-analyze dot | dot -Tsvg > path/to/file.svg

5. Show security scores of running units:

# systemd-analyze security
Related Post