用systemd-analyze分析Linux系统的启动性能

用systemd-analyze分析Linux系统的启动性能

http://www.jb51.net/LINUXjishu/350235.html


这篇文章主要介绍了用systemd-analyze分析Linux系统的启动性能,systemd-analyze能够实现图形化的结果展示,非常强大,需要的朋友可以参考下


ystemd-analyze是一个分析启动性能的工具,用于分析启动时服务时间消耗。默认显示启动是内核和用户空间的消耗时间:
 

复制代码
代码如下:
[[email protected]~]#systemd-analyze
Startupfinishedin818ms(kernel)+6.240s(initrd)+32.979s(userspace)=40.038s
 

和使用systemd-analyzetime命令的效果一样。


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


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

复制代码
代码如下:

[[email protected]~]#systemd-analyzeblame
30.852siscsi.service
16.994skdump.service
10.871sboot.mount
...
103mssystemd-sysctl.service
101msdatapool.mount
 

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


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

复制代码
代码如下:

[[email protected]~]#systemd-analyzecritical-chain
Thetimeaftertheunitisactiveorstartedisprintedafterthe"@"character.
Thetimetheunittakestostartisprintedafterthe"+"character.
[email protected]
└─[email protected]+16.994s
└─[email protected]
└─[email protected]+54ms
└─[email protected]+535ms
└─[email protected]
└─[email protected]
└─[email protected]
└─[email protected]
└─[email protected]+2ms
└─[email protected]+67ms
└─[email protected]
└─[email protected]+10.871s
└─[email protected]\x2duuid-8c77568b\x2d7e51\x2d4e32\x2dbbdf\[email protected]+226ms
└─[email protected]+152ms
└─[email protected]+25ms
 

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


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

复制代码
代码如下:

[[email protected]~]#systemd-analyzeplot>plot.svg

用systemd-analyze分析Linux系统的启动性能


其他参数:
systemd-analyzedot用分隔符产生当前服务
systemd-analyzedump以友好方式显示当前服务状态
6systemd文件类型及存放位置
systemd配置文件被称为unit单元,根据类型不同,以不同的扩展名结尾。
.service系统服务;
.target一组系统服务;
.automount自动挂载点;
.device能被内核识别的设备;
.mount挂载点;
.path文件系统的文件或者目录;
.scope外部创建的进程;
.slice一组分层次管理的系统进程;
.snapshot系统服务状态管理;
.socket进程间通讯套接字;
.swap定义swap文件或者设备;
.timer定义定时器。