1、bootchart工具简介:

        bootchart是一个用于linux启动过程性能分析的开源软件工具,在系统启动过程自动收集CPU占用率、进程等信息,并以图形方式显示分析结果,可用作指导优化系统启动过程。

2、bootchart在Android平台使用情况:

        Android系统中已有一份bootchart的c实现,位于system/core/init/bootchart.c中。bootchart对Android开机测量是通过内建在init进程中实现的,在后台执行测量。不过bootchart的测量时段是从bootchart被初始化之后到home screen出来之前,不包括bootloader和kernel的执行时间(bootchart的原理是取代init process或是内建在init process里,所以只能取得initial script的开机过程报告)。

3、bootchart在Android平台使用步骤:

       1) Ubuntu 12.04下bootchart工具安装

       2) bootchart在Android下编译

       3) bootchart在Android下的应用

       4) bootchart测量结果图形化显示 

      下面依次对上述4个步骤做详细说明

      网上很多教程说要安装下面两个工具,经个人验证最后在制作图形化显示时,出现bootchart无法正常解析android中生成的bootchart.tgz文件。

1. sudo apt-get install bootchart  
2. sudo apt-get install pybootchartgui

     异常情况如下,需要下载旧版本的bootchart工具,最终问题得到解决。     

android 如何判断boot完成 bootchart android p_Android

     下载bootchart_0.9-0ubuntu6_all.deb工具,下载地址:

     安装方法:sudo dpkg -i  bootchart_0.9-0ubuntu6_all.ded

         1、  vi  system/core/init/bootchart.h 修改define  BOOTCHART  0 为 define  BOOTCHART  1

1. *  
2.  * Copyright (C) 2008 The Android Open Source Project  
3.  *  
4. "License");  
5. this file except in compliance with the License.  
6.  * You may obtain a copy of the License at  
7.  *  
8. //www.apache.org/licenses/LICENSE-2.0  
9.  *  
10.  * Unless required by applicable law or agreed to in writing, software  
11. "AS IS" BASIS,  
12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
13. for the specific language governing permissions and  
14.  * limitations under the License.  
15.  */  
16.   
17. #ifndef _BOOTCHART_H  
18. #define _BOOTCHART_H  
19.   
20. #ifndef BOOTCHART  
21. # define  BOOTCHART  0   // 修改define  BOOTCHART  1  
22. #endif  
23.   
24. #if BOOTCHART  
25.   
26. extern int   bootchart_init(void);  
27. extern int   bootchart_step(void);  
28. extern void  bootchart_finish(void);  
29.   
30. # define BOOTCHART_POLLING_MS   200   /* polling period in ms */  
31. # define BOOTCHART_DEFAULT_TIME_SEC    (2*60)  /* default polling time in seconds */  
32. # define BOOTCHART_MAX_TIME_SEC        (10*60) /* max polling time in seconds */  
33.   
34. #endif /* BOOTCHART */  
35.   
36. #endif /* _BOOTCHART_H */

        2、添加bootchart进入系统中,执行如下命令:

1. touch system/core/init/init.c    
2. export INIT_BOOTCHART=true

       其中touch命令的作用就是将init.c文件的最后修改时间改为当前时间,这样保证init.c文件会被重新make,而bootchart就是在init.c中被调用的,从而保证bootchart会被编进系统中,重新编译固件编译生成新的可执行文件init,该文件在手机文件系统位于根/下,对应的flash image是boot.img,为此需重新烧写含有新的init的boot.img。

      1、将编译生成的带有bootchart工具的Android系统重新烧录到开发板上,并启动系统。

       2、在系统data目录创建文件/data/bootchart-start,其内容是bootchart的采样时间:

1. adb shell 'echo $TIMEOUT > /data/bootchart-start'

             其中$TIMEOUT是期望采样的时间,单位为秒,例如要采样两分钟,则执行:   

    1. adb shell 'echo 120 > /data/bootchart-start'  
            3、在系统data目录创建/data/bootchart,执行
    1. adb shell 'mkdir /data/bootchart'

                  在开发板上系统的/data/目录下新建目录bootchart/用来存放bootchart的测量结果,后面要利用这些文件生成可视化图片。 

            4、重新启动开发板,在开发板的Android系统的/data/bootchart/目录下将看到以下5个文件组成: 

    android 如何判断boot完成 bootchart android p_Android_02

             到此为止,bootchart执行测量后生成的测量数据已经完成,看上面有3个.log文件,下面进行生成美观的图形化显示。

             需要注意,在开发板上运行bootchart采样完成后若不再使用bootchart则需手工删除文件/data/bootchart-start,否则开发板每次重启时都会运行bootchart。

           1、生成bootchart.tgz 在data/bootchart目录执行以下命令:   

    1. busybox tar -czf bootchart.tgz *

               或者使用android源码打包工具中提供的 grab-bootchart.sh文件进行打包,源码路径:system/core/init/grab-bootchart.sh 

           2、生成美观的图形化显示

                拷贝/data/bootchart下刚才生成的 bootchart.tgz到Linux环境下,执行:        

      1. java -jar /usr/share/bootchart/bootchart.jar  /path/bootchart.tgz

                  执行上面命名会在/path目录生成一个bootchart.svgz 问题,下面对其进行重命名

      1. sudo mv bootchart.svgz bootchart.svg.gz

                  重命名完成后执行

      1. sudo gzip -d bootchart.svg.gz

                  此时会发现在path目录生成名为bootchart.svg图片,到此大功告成,美观的图形化显示show出来了。

                

      android 如何判断boot完成 bootchart android p_Android_03