Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2311947
  • 博文数量: 318
  • 博客积分: 8752
  • 博客等级: 中将
  • 技术积分: 4944
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-23 07:56
文章分类

全部博文(318)

文章存档

2019年(1)

2017年(2)

2016年(12)

2015年(2)

2014年(1)

2013年(17)

2012年(22)

2011年(9)

2010年(37)

2009年(33)

2008年(44)

2007年(43)

2006年(95)

分类: LINUX

2010-08-10 11:10:12

Bootchart is an opensource project. But seemly it has been long time since its last update.
It is very useful to analyze the booting performance of a Linux device.
I have tried it, and it is still very cool for me.
You can find out more information about Bootchart at it's home page, at:
=========================================

To use Bootchart on an Android System, you need to perform the following steps:

  • install the bootchart tool on your host machine
  • build 'init' with bootchart support
  • install 'init' into your system image
  • trigger bootchart functionality on system boot
  • retrieve the collected data from the system
  • generate the graphic from the data
  • view the resulting graphic
  • interpret the results

Detailed Instructions

Installing the bootchart tool

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.)

Building 'init' with bootchart support

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

Installing 'init' into your system image

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

Triggering bootchart functionality on system boot

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 ' option for this.

  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=" on to the kernel command line. This is ignored by the kernel, but is read by 'init' from /proc/cmdline after the kernel boots. If your bootloader can pass user-specified kernel command line arguments, it can also trigger bootcharting with this option as well.

Retrieving the collected data from the system

'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.

Generating the graphic from the data

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

Viewing the resulting graphic

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).

Interpreting the results

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.

阅读(2010) | 评论(0) | 转发(0) |
0

上一篇:Linux poll机制分析

下一篇:asmlinkage

给主人留下些什么吧!~~