Tuesday, January 22, 2013

systemd-analyze


Arch 和很多 Linux 都開始逐漸改用 systemd 作為 service 管理,取代舊的 SysV rc scripts 。從 top 可以看到 pid 1 的程式就是 systemd (取代原本 Unix 的 init)

systemd 最大的好處就是可以平行的去把 service 叫起來,這篇要講的是在 optimize 時所使用的 profiling 工具:systemd-analyze

根據 man page :

       systemd-analyze blame prints a list of all running units, ordered by the time they took to initialize.This information may be used to optimize boot-up times. Note that the output might be misleading as the initialization of one service might be slow simply because it waits for the initialization of another service to complete.

       systemd-analyze plot prints an SVG graphic detailing which system services have been started at what time, highlighting the time they spent on initialization.

也就是說,主要用法非常簡單,只要兩個指令:

sudo systemd-analyze blame             # see the detail
sudo systemd-analyze plot > out.svg    # picture

blame 會印出花最多時間的服務。我這邊第一名是 dhcpcd@eth0.service

plot 顧名思義就是畫出精美的圖形:




阿!兇手現身了!


for optimization, you can mask/disable some thing 
sudo systemd mask/disable xxx.service     # mask is the stronger version of disable 


結語:systemd-analyze 是非常方便的 profiling 工具來幫助我們優化調整系統開機流程,以及關掉不必要的 service

No comments:

Post a Comment