0

I want to monitor boot time (the time needed by the system to boot) compared to software version installed (kernel and other software) day by day in order to have a look at boot performance for my arch-linux computer.

I use the systemd command systemd-analyze time to get the boot time.

My idea is to have a log with:

[day]
.......Boot time [s]:  2.145 (kernel) + 13.675 (userspace)
.......with kernel version 4.11.2
.......gnome-shell version 3.24.1
[day+1]
.......Boot time [s]:  3.145 (kernel) + 21.665 (userspace)
.......with kernel version 4.17.11
.......gnome-shell version 3.28.3

How can I do?

1

Basic idea

I'd be tempted to do this as a systemd service that logs this to a file:

$ systemd-analyze time | sed 's/Startup finished in //;s/ +.*(initrd)//;s/ =.*$//'
442ms (kernel) + 10.224s (userspace)

This cuts the output of systemd-analyze time down to just the bits you want. The rest of the info you want is easy to come by via uname and gnome-shell command-lines' themselves:

$ systemd-analyze time | \
    sed 's/Startup finished in //;s/ +.*(initrd)//;s/ =.*$//'; \
    printf "kernel: %s\ngnome-shell: %s\n" "$(uname -r)" "$(gnome-shell --version)"
442ms (kernel) + 10.224s (userspace)
kernel: 3.10.0-693.21.1.el7.x86_64
gnome-shell: GNOME Shell 3.25.4

More refined

As a script the above:

$ cat ./boottime.bash
#!/bin/bash

printf "[%s]\n" "$(date)"
printf ".......Boot time [s]: %s\n" "$(systemd-analyze time | sed 's/Startup finished in //;s/ +.*(initrd)//;s/ =.*$//')"
printf ".......with kernel version: %s\n" "$(uname -r)"
printf ".......gnome-shell version: %s\n" "$(gnome-shell --version)"

#[day]
#.......Boot time [s]:  2.145 (kernel) + 13.675 (userspace)
#.......with kernel version 4.11.2
#.......gnome-shell version 3.24.1
#[day+1]
#.......Boot time [s]:  3.145 (kernel) + 21.665 (userspace)
#.......with kernel version 4.17.11
#.......gnome-shell version 3.28.3

The output:

$ ./boottime.bash
[Sat Aug  4 14:34:40 EDT 2018]
.......Boot time [s]: 442ms (kernel) + 10.224s (userspace)
.......with kernel version: 3.10.0-693.21.1.el7.x86_64
.......gnome-shell version: GNOME Shell 3.25.4

The unit file:

$ cat /etc/systemd/system/boottime.service
[Unit]
Description=Boottime Service
After=systend-user-sessions.service

[Service]
Type=simple
ExecStart=/opt/bin/boottime.bash

TLDR; parsing systemd-analyze time

The sed used above works as follows:

sed 's/Startup finished in //;s/ +.*(initrd)//;s/ =.*$//')"
  • s/Startup finished in // - removes everything from left up to the word in
  • s/ +.*(initrd)// - removes everything starting at + up to (initrd)
  • s/ =.*$// - removes everything at the end of string, starting with = to the end of the line $
  • It looks good! I am not an expert of sed, can you explain the complex part s/ +.*(initrd)//;s/ =.*$// ? – mattia.b89 Aug 5 '18 at 15:44
  • @mattia.b89 - see updated section at end that explains – slm Aug 5 '18 at 15:57
  • thank you, now it's clear! I don't have an initrd item... – mattia.b89 Aug 6 '18 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.