分类: LINUX
2010-08-10 11:10:12
To use Bootchart on an Android System, you need to perform the following steps:
Most modern distributions seem to have bootchart packages available.
On a Fedora system, you can get bootchart with yum:
$ yum install bootchart
On Ubuntu, bootchart can be installed with apt-get.
$ sudo apt-get install bootchart
Note that the bootchart tool is written in Java, and will require a java runtime system in order to run the program. (This should not be a problem for any machine configured with the Android SDK.)
The first user-space program run on an Android system is called 'init' and it resides in the root directory (that is, at '/') of the Android file system. 'init' is executed by the Linux kernel, and it performs several initialization steps and starts all of the other user-space programs.
'init' operates by interpreting the configuration file /init.rc. This file has lists of commands to perform.
The 'init' program can be built with or without support for bootchart data collection. The default 'init' does not have support for data collection. In order to use bootchart with Android, you need to make sure you have an 'init' with bootchart support compiled into the program.
There are two ways to do this:
1. start from a clean build, and set the variable INIT_BOOTCHART=true
$ cd mydroid
$ export INIT_BOOTCHART=true
$ make clean
$ make
2. re-compile just 'init', specifying the variable INIT_BOOTCHART=true
$ touch system/core/init/init.c #this is used to change the timestamp of init.c and then make
$ m INIT_BOOTCHART=true
There are a few alternatives, depending on whether you are using a real device or the emulator.
Copy the init program from the build area to the root directory of your device If you have ssh running, you may be able to do something like this:
scp out/target/product/generic/root/init root@device:/
Note: This requires that the root filesystem be writable, which I don't think it is, normally.
Specify to use a new initramfs image, containing 'init', with your emulator:
emulator @emu2 -ramdisk out/target/product/generic/ramdisk.img
FIXME: need to verify this section
Even though 'init' is compiled with bootchart functionality built-in, you must tell it, at boot time, to actually collect the bootchart data.
This is done by specifying the amount of time that 'init' should collect bootchart data.
1. The default method of telling 'init' to collect data is to place a file with a timeout value in /data. The file is named 'bootchart-start', and contains a single value which is the number of seconds to collect data.
This can be created with the adb command:
adb shell 'echo 120 > /data/bootchart-start'
When you reboot your device, bootcharting will start when /init is run, and will end after the indicated period. (120 seconds = 2 minutes)
2. If you are using an emulator, you can specify it a timeout value on the emulator command line. You use the '-bootchart
emulator @emu2 -ramdisk out/target/product/generic/ramdisk.img -bootchart 120
This is handy when used with the -wipe-data option with the emulator, which starts the system with an empty /data partition.
Note that internally, when the emulator sees the -bootchart option, it places "androidboot.bootchart=
'init' stores the collected data into a directory on the target file system. When bootcharting is activated, 'init' periodically polls the /proc filesystem for process and system-related data, and stores the data into the directory /data/bootchart in a series of files.
A command is provided to retrieve this set of files, and place it into an archive (which is the format used by the bootchart program).
$ system/core/init/grab-bootchart.sh
This will generate a file named 'bootchart.tgz' in the current directory.
Note that this command uses 'adb pull' to retrieve the files from the target, and assumes that there is only one device for adb to pull from. If you have multiple devices and/or emulators running, make sure you are getting the data from the one you expect.
To generate a graphic image from the collected data, run the bootchart tool itself. Be sure to specify the file generated by the retrieval step above.
bootchart bootchart.tgz
On Ubuntu, the following command may be used to run bootchart:
$ java -jar /usr/share/bootchart/bootchart.jar ./bootchart.tgz
(Note: I failed to execute this command. Maybe I need to learn more knowledge about Java......)
By default, bootchart will produce a graphic in PNG format. You can specify other graphic formats if you wish. For printing, you may wish to produce an encapsulated Postscript (EPS) file. If you wish to zoom in for details, you may wish to use the scalable vector graphics (SVG) format.
NOTE:
会生成如下3个log文件:
proc_diskstats.log
proc_ps.log
proc_stat.log
把这3个文件取出后,在pc上运行如下命令:
tar czf bootchart.tgz *.log
bootchart -f png bootchart.tgz
Use any image viewer to examine the graphic, if you created a png image.
If you output the graphic in SVG format, then you can open the file with an SVG-capable program (such as Inkscape or a web browser).
A bootchart graphic will have a few different sections that are of interest.
In general, there are CPU and disk utilization graphs at the top of the graphic. There is a timeline running from left to right in the image, with processes shown starting (and sometimes stopping) underneath it. The process utilization of CPU is indicated by coloration of it's process bar.
Things to look for are the start and top times of the various processes, and their CPU utilization. Long gaps with low utilization may indicate a timeout or some other problem.
Once you have identified the processes that are using time during the initialization, you can further analyze these by looking at system logs, using strace, and examining the system source code.