背景:
开机启动相关的详细信息,一般都是可以通过logcat中查看boot_progress相关查看,这种方式查看相对不那么方便,毕竟开机过程中涉及的进程较多,要查看也较多,而且还经常需要查看代码才可以对应起来,但有另一种方式可以通过看bootchart方式更加直观
ubuntu上相关方法
步骤1:
adb shell touch /data/bootchart/enabled
然后重启设备
重启后就会在对应的data/bootchart目录有如下文件
这些日志文件其实就是bootchart绘制图片的基础,下面这些步骤其实就是对这log转换成图表。
步骤2:
安装相关的bootchart的库
test@test:~/demos$ git clone https://gitee.com/wasdzy/bootchart
Cloning into 'bootchart'...
remote: Enumerating objects: 2614, done.
remote: Counting objects: 100% (2614/2614), done.
remote: Compressing objects: 100% (956/956), done.
Receiving objects: 43% (1125/2614), 868.00 KiB | 561.00 KiB/s
remote: Total 2614 (delta 1620), reused 2614 (delta 1620), pack-reused 0
Receiving objects: 100% (2614/2614), 1.85 MiB | 767.00 KiB/s, done.
Resolving deltas: 100% (1620/1620), done.
再进行编译
test@test:~/demos$ cd bootchart/
test@test:~/demos/bootchart$ make
可以看到已经编译出来了pybootchartgui.py文件
再进行安装
test@test:~/demos/bootchart$ sudo make install
[sudo] password for test:
install -d /usr/lib/python3.8/site-packages/pybootchartgui
cp pybootchartgui/*.py /usr/lib/python3.8/site-packages/pybootchartgui
install -D -m 755 pybootchartgui.py /usr/bin/pybootchartgui
[ -z "" ] && ( cd /usr/lib/python3.8/site-packages/pybootchartgui ; \
python3 /usr/lib/python3.8/py_compile.py *.py ; \
PYTHONOPTIMIZE=1 python3 /usr/lib/python3.8/py_compile.py *.py ); :
install -d /lib/bootchart/tmpfs
install -m 755 -D bootchartd /sbin/bootchartd
install -m 644 -D bootchartd.conf /etc/bootchartd.conf
install -m 755 -D bootchart-collector /lib/bootchart/bootchart-collector
mkdir -p /lib/systemd/system
install -m 0644 bootchart2.service \
bootchart2-done.service \
bootchart2-done.timer \
/lib/systemd/system
install -m 644 -D README /usr/share/docs/bootchart/README
install -m 644 -D README.pybootchart /usr/share/docs/bootchart/README.pybootchart
mkdir -p /usr/share/man/man1
gzip -c bootchart2.1 > /usr/share/man/man1/bootchart2.1.gz
gzip -c bootchartd.1 > /usr/share/man/man1/bootchartd.1.gz
gzip -c pybootchartgui.1 > /usr/share/man/man1/pybootchartgui.1.gz
步骤3:
执行aosp自带的grab-bootchart.sh
test@test:~/disk2/aosp14$ ./system/core/init/grab-bootchart.sh
adb server version (41) doesn't match this client (39); killing...
* daemon started successfully
Traceback (most recent call last):
File "/usr/bin/pybootchartgui", line 20, in <module>
from pybootchartgui.main import main
ModuleNotFoundError: No module named 'pybootchartgui'
gio: file:///home/test/disk2/aosp14/bootchart.png: Error when getting information for file “/home/test/disk2/aosp14/bootchart.png”: No such file or directory
Clean up /tmp/android-bootchart/ and ./bootchart.png when done
发现还是会传递报错找不到,干脆直接依赖编译出来的
手动修改init/grab-bootchart.sh文件
diff --git a/init/grab-bootchart.sh b/init/grab-bootchart.sh
index 2c56698a1..37c5a4eeb 100755
--- a/init/grab-bootchart.sh
+++ b/init/grab-bootchart.sh
@@ -17,6 +17,7 @@ for f in $FILES; do
adb "${@}" pull $LOGROOT/$f $TMPDIR/$f 2>&1 > /dev/null
done
(cd $TMPDIR && tar -czf $TARBALL $FILES)
-pybootchartgui ${TMPDIR}/${TARBALL}
+#pybootchartgui ${TMPDIR}/${TARBALL}
+~/demos/bootchart/pybootchartgui.py ${TMPDIR}/${TARBALL}
xdg-open ${TARBALL%.tgz}.png
echo "Clean up ${TMPDIR}/ and ./${TARBALL%.tgz}.png when done"
最重要就是把pybootchartgui直接变成~/demos/bootchart/pybootchartgui.py
再执行
test@test:~/disk2/aosp14$ ./system/core/init/grab-bootchart.sh
parsing '/tmp/android-bootchart/bootchart.tgz'
parsing 'header'
parsing 'proc_stat.log'
parsing 'proc_ps.log'
parsing 'proc_diskstats.log'
merged 0 logger processes
pruned 66 process, 0 exploders, 17 threads, and 0 runs
bootchart written to 'bootchart.png'
Clean up /tmp/android-bootchart/ and ./bootchart.png when done
注意如果有的机器有ImportError: No module named cairo报错,则需要sudo apt-get install python-cairo
执行后自动就打开了表格图:
windows上相关方法
上面是对于ubuntu系统上,也可以windows上使用,因为上面说过本质其实就是data/bootchart下面日志进行解析生成png
这里可以把日志打包,然后bootchart解析。
adb shell进入设备对日志进行打包:
emulator_x86_64:/data/bootchart # tar -czvf bcl.tar.gz *log
proc_diskstats.log
proc_ps.log
proc_stat.log
打包好成了 bcl.tar.gz文件,再进行导出用bootchart.jar进行解析生成图片
bootchart.jar下载地址:
https://share.weiyun.com/NdM2ZE4F
接下来在导出日志进行解析
test@test:~/Downloads$ adb pull /data/bootchart/bcl.tar.gz .
test@test:~/Downloads$ java -jar bootchart.jar bcl.tar.gz
Parsing bcl.tar.gz
Wrote image: ./bcl.png
bootchart前后对比法:
上面通过图形绘制绘制出开机启动的时间后,可以通过图形大概看出时间点,但是明显图形时间坐标不够精确,那么优化前后有没有什么方法可以可以精确对比出两次优化时间呢?这个android其实也是有自带相关的工具
具体可以参考如下py文件:
system/core/init/compare-bootcharts.py
具体原理可以看这个脚本,就是对比相关主要进程的log的time
具体的使用对比方式:
log文件打包成bootchart.tgz
然后使用如下命令:
test@test:~/Downloads$ ~/disk2/aosp14/system/core/init/compare-bootcharts.py bcl1 bcl
process: baseline experiment (delta)
- Unit is ms (a jiffy is 9 ms on the system)
------------------------------------
/system/bin/surfaceflinger: 6561 5628 (-933)
/system/bin/bootanimation: 7104 6104 (-1000)
zygote64: 6361 5438 (-923)
zygote: 6361 5447 (-914)
system_server: 17428 15723 (-1704)
bootanimation ends at: 31809 30142 (-1666)
上面就有对比出相关surfaceflinger,bootanimation,system_server时间等
具体详情试看方式:
投屏专题部分:
https://mp.weixin.qq.com/s/IGm6VHMiAOPejC_H3N_SNg
更多framework详细代码和资料参考如下链接
hal+perfetto+surfaceflinger
https://mp.weixin.qq.com/s/LbVLnu1udqExHVKxd74ILg
其他课程七件套专题:
点击这里
https://mp.weixin.qq.com/s/Qv8zjgQ0CkalKmvi8tMGaw
视频试看:
https://www.bilibili.com/video/BV1wc41117L4/
更多framework假威风耗:androidframework007