Bootchart (简体中文)
From ArchWiki
i18n |
---|
English |
简体中文 |
Contents |
简介
Bootchart是一种很方便的工具,可以用来分析Linux启动流程使系统启动更快。他由bootchartd服务和bootchart-render两部分组成,后者主要负责生成启动流程的分析结果图。
安装Bootchart
Bootchart安装非常简单,你只需要以管理员帐户运行下面的命令即可:
# pacman -Sy bootchart
运行Bootchart
In general, be extra careful with this step.
要使bootchart运行,你需要将他添加到引导器的初始化进程选项,或者手动在init脚本(通常是rc.sysinit)中手动添加。不过需要注意的是,如果你是手动添加到init脚本的,那么也要手动停止它,这种情况需要特别留意!
启动引导器设置
下面我们介绍常用的方法,即将原有引导选项复制一份,并在内核项后面添加'init=/sbin/bootchartd',然后通过启动引导器引导bootchart。这样bootchart会在登录提示符出现的时候自动停止。
Grub
打开/boot/grub/menu.lst, 复制粘贴原有的引导记录,并在kernel行后添加"init=/sbin/bootchartd"。如下例:
# (1) Arch Linux Bootchart title Arch Linux root (hd0,0) kernel /vmlinuz26 root=/dev/disk/by-uuid/d531ff5b-de65-499a-9942-d18682375163 ro vga=37C init=/sbin/bootchartd initrd /kernel26.img
Grub 2
打开/boot/grub/grub.cfg,复制原来的引导区域并按照下面的范例修改之:
# (0) Arch Linux menuentry "Arch Linux" { set root=(hd0,1) linux /boot/vmlinuz26 root=/dev/sda1 ro initrd /boot/kernel26.img } # (1) 带bootchartd的Arch Linux引导项 menuentry "Arch Linux with Bootchart" { set root=(hd0,1) linux /boot/vmlinuz26 root=/dev/sda1 ro init=/sbin/bootchartd initrd /boot/kernel26.img }
然后你就可以重启,并选择代bootchart选项的启动项了。
rc.sysinit脚本设置
这种方法有一定的危险性(可能导致原有系统无法启动),所以除非前一种方法失败,否则不要用这种方法。采用这种方式,不光是每次都要手动停止bootchart(否则很快就会占满硬件资源),而且每次开机都会运行一次,而且以后每次软件包升级 /etc/rc.sysinit的时候,这些设置都会被覆盖掉。
另一方面,这种方式是可以让你看到登录后所发生的一些东西的。
编辑/etc/rc.sysinit脚本
先将下面这一行添加到/etc/rc.sysinit
/sbin/bootchartd start
这一行不宜太靠前,否则这部分出问题会导致系统无法启动。当然也不宜太靠后,因为他之前的项目都无法观察得到。
我们推荐把他放在配置系统时钟行的前面。
找到如下行:
stat_busy "Configuring System Clock"
将下面这一行添加到其前面:
/sbin/bootchartd start
登录后关闭bootchartd服务
这种方式一定记住,在登录后停止bootchartd服务。 你可以以管理员帐户执行:
/sbin/bootchartd stop
也可以用sudo通过下面的命令来执行:
sudo /sbin/bootchartd stop
生成分析结果图表
你可以通过运行下面的命令来生成分析结果图:
bootchart-render
确保运行命令的目录有写权限,程序就会生成一个名为'bootchart.png'的图像,这就是分析结果图。
你需要事先安装Java运行环境并且在此之前设置正确。
bootcharts用户秀
5秒内启动完成的例子
LWN Article on fast booting netbooks
This article is really awesome and along with a bunch of bootcharts provides some tips on how to boot faster. Some of those improvements are beyond reach of the ordinary user though (patching X.org, kernel, etc.).
A fast system getting even faster
These bootcharts are from a system with proprietary NVidia drivers and KDE 4.2. It acts as a print server for everyone in the house and is set up to play music on boot using mpd.
Sevices start mostly in sequence, the kernel isn't tweaked in any way and there are no changes to the initscripts.
Services now start in parallel - netfs, network have been combined into a single script that also starts the music player daemon. KDM starts sooner, so less of the bootchart is visible.
Bootchartd is started from rc.sysinit, because the bootloader approach failed (bootchartd doesn't have enough time to initialize).
As you can see, there are hardly any latencies from HDD seek operations. The whole boot process is CPU-bound and is slowed down by poor nvidia drivers which can't properly accelerate 2D operations - KDE apps fight for the CPU. At the 4 second mark, the base system is ready for use in CLI. At ~10 seconds, mpd starts playing music from a samba share. System daemons - syslog-ng, dethnet, kdm, cups, hal and preload start in parallel. This is not exactly ideal, because preload and kdm/X use the SSD at the same time. A waiting state between preload and KDM could save an another second or two (maybe). KDM is set up to autologin and lock the session automatically. This starts the 'vermiculate' screensaver, which acts as a login window and hides the apps starting in background. The big red bar is when the login dialog appears.
Obviously, KDE isn't optimized at all. There's over-use of CPU resources and applications don't start in parallel.
Add yours here :)