Android系统中启用bootchart

bootchart是用于记录开机时进程启动时间的工具

默认情况下是没有启用的,在init.rc中是有启动的,看如下代码

1     # Start bootcharting as soon as possible after the data partition is
2     # mounted to collect more data.
3     mkdir /data/bootchart 0755 shell shell
4     bootchart start

但是,查看了一下bootchart的源码(在system/core/init/bootchart.cpp中),它启动要判断另外一个条件,代码如下:

 1 static int do_bootchart_start() {
 2   // We don't care about the content, but we do care that /data/bootchart/enabled actually exists.
 3   std::string start;
 4   if (!android::base::ReadFileToString("/data/bootchart/enabled", &start)) {
 5     LOG(VERBOSE) << "Not bootcharting";
 6     return 0;
 7   }
 8  
 9   g_bootcharting_thread = new std::thread(bootchart_thread_main);
10   return 0;
11 }

也就是说检查/data/bootchart/enabled文件是否存在(不管文件是不是有内容),如果存在就启用bootchart,这样就好办了,我们在/data/bootchart中随便新建一个名字enabled的空文件就好了。

启动android后使用adb shell touch /data/bootchart/enabled命令在/data/bootchart文件下添加enable标记,但是在不需要手机数据的时候要删除这个标记

修改完后再重新启动安卓系统发现/data/bootchart目录下有了下面几个文件:

header

proc_diskstats.log

proc_ps.log

proc_stat.log

使用 tar -zcf boochart.tgz

然后使用adb pull 命令将文件拷贝出来

在linux PC机上生成bootchart图表

linux PC机安装bootchart工具

1 sudo apt-get install bootchart 
2 sudo apt-get install pybootchartgui
生成 bootchar 图表

拷贝 bootchart.tgz 到 PC 中,并执行下面的命令生成图表

1 bootchart bootchart.tgz
原文地址:https://www.cnblogs.com/zongfanstudy/p/13301122.html