vieyahn2017 / iBlog

44 stars 0 forks source link

8.29 systemd-analyze blame查看各项服务启动所用的时间 #361

Closed vieyahn2017 closed 3 months ago

vieyahn2017 commented 3 years ago

systemd-analyze blame查看各项服务启动所用的时间

vieyahn2017 commented 3 years ago

systemd-analyze是一个分析启动性能的工具,用于分析启动时服务时间消耗。

默认显示启动是内核和用户空间的消耗时间:使用systemd-analyze plot > boot.svg生成一张启动详细信息矢量图,然后用图像浏览器或者网页浏览器打开查看 。

[root@localhost~]#systemd-analyze Startupfinishedin818ms(kernel)+6.240s(initrd)+32.979s(userspace)=40.038s
和使用systemd-analyzetime命令的效果一样。

(1)查看详细的每个服务消耗的启动时间

通过systemd-analyzeblame命令查看详细的每个服务消耗的启动时间:

[root@localhost~]#systemd-analyze blame
30.852siscsi.service
16.994skdump.service
10.871sboot.mount
...
103mssystemd-sysctl.service
101msdatapool.mount  

(2)查看严重消耗时间的服务树状表

systemd-analyze critical-chain命令打印严重消耗时间的服务树状表,按照启动消耗的时间进行排序,时间消耗越多,越排到前面。@之后是服务激活或者启动的时间,+号之后是服务启动消耗的时间。个人理解@是从系统引导到服务启动起来的时间,是一个相对时间消耗,+是服务启动消耗的时间,是一个绝对时间消耗。

[root@localhost~]#systemd-analyzecritical-chain
Thetimeaftertheunitisactiveorstartedisprintedafterthe"@"character.
Thetimetheunittakestostartisprintedafterthe"+"character.
multi-user.target@32.976s
└─kdump.service@15.981s+16.994s
└─network.target@15.980s
└─NetworkManager.service@15.069s+54ms
└─firewalld.service@14.532s+535ms
└─basic.target@14.532s
└─sockets.target@14.532s
└─dbus.socket@14.532s
└─sysinit.target@14.527s
└─systemd-update-utmp.service@14.524s+2ms
└─systemd-tmpfiles-setup.service@14.456s+67ms

(3)打印分析图及其他命令

systemd-analyze plot打印一个svg格式的服务消耗时间表,通过浏览器可以以图形的方式展示,非常直观:

[root@localhost~]#systemd-analyze plot>plot.svg

systemd-analyze dot用分隔符产生当前服务 systemd-analyze dump以友好方式显示当前服务状态 6systemd文件类型及存放位置 systemd配置文件被称为unit单元,根据类型不同,以不同的扩展名结尾。

.service系统服务; .target一组系统服务; .automount自动挂载点; .device能被内核识别的设备; .mount挂载点; .path文件系统的文件或者目录; .scope外部创建的进程; .slice一组分层次管理的系统进程; .snapshot系统服务状态管理; .socket进程间通讯套接字; .swap定义swap文件或者设备; .timer定义定时器。

最后再总结一下:

# 查看启动耗时
$ systemd-analyze

# 查看每个服务的启动耗时
$ systemd-analyze blame

# 显示瀑布状的启动过程流
$ systemd-analyze critical-chain

# 显示指定服务的启动流
$ systemd-analyze critical-chain atd.service

查看所有的服务
systemctl list-units --type=service
vieyahn2017 commented 3 years ago

系统启动超级慢?手把手教会你使用 Systemd-Analyze 优化系统速度! https://blog.csdn.net/easylife206/article/details/103790052