起動時間を記録する方法は?

起動時間を記録する方法は?

私のArch-Linuxシステムの起動パフォーマンスに関するアイデアを得るために、毎日インストールされているソフトウェアバージョン(カーネルや他のソフトウェア)と比較して、起動時間(システムの起動にかかる時間)を監視したいと思います。

systemd-analyze time起動時間を取得するにはsystemdコマンドを使用します。

私の考えはログを持つことです。

[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

どうですか?

ベストアンサー1

基本的なアイデア

私はこれをシステムサービスとして実行し、ファイルに記録したいと思います。

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

systemd-analyze timeこれにより、必要なビットに出力が減少します。必要な残りの情報は、unameコマンドgnome-shellライン自体を介して簡単に使用できます。

$ 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

もっと洗練された

上記のスクリプトのように:

$ 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

出力:

$ ./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

ユニットファイル:

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

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

システムの解析が長すぎます。解析時間

上記で使用した動作原理sedは次のとおりです。

sed 's/Startup finished in //;s/ +.*(initrd)//;s/ =.*$//')"
  • s/Startup finished in //- 左から右にすべて削除in
  • s/ +.*(initrd)//-+次からすべて削除(initrd)
  • s/ =.*$//- 行の先頭から=最後まで文字列の終わりをすべて削除します。$

おすすめ記事