1. 程式人生 > 實用技巧 >Android系統中啟用bootchart

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

接下來就可以用其他工具根據這些log生成圖片了,比如pybootchartgui工具