Android 中的 perfboot工具

背景

开机首先加载bootloader,由bootloader启动kernel,然后运行init程序,有init启动Zygote,Zygote进程启动SystemServ进程,在SystemServer进程启动系统服务:PMS,AMS等,最后在AMS中启动Launcher ,此时整个Android系统完毕。在整个启动过程需要加载相关资源和Java类,首次启动还要安装应用等,如果不做好优化,开机时间可能就非常不理想,下面的工具对优化开机时间有很大的帮助。

https://blog.csdn.net/u011139711/article/details/80933143

https://blog.csdn.net/manjianchao/article/details/80515191

介绍

perfboot工具是个Python的脚本,在AOSP/system/core/init/目录下,通过运行./perfboot.py -h 可以看到相关参数。

运行perfboot需要在编译环境下,因为perfboot的运行需要依赖AOSP/development/python-packages/adb/目录下的相关模块。

获取记录开机时间点的文件:./perfboot.py --iterations=2 --interval=30 -v --output=/tmp/J5D_UE.tsv,相关参数的意思可以参考说明,脚本执行结束后,可以在Excel里直接打开文件进行分析。

执行命令。

cd system/core/init/
./perfboot.py  --iterations=5 --interval=30 -v --output=/tmp/bf.tsv

报错记录: No module named adb

Traceback (most recent call last):
  File "./perfboot.py", line 55, in <module>
    import adb
ImportError: No module named adb

这个报错找不到adb模块,此时在AOSP/system/core/init/目录下执行命令无法找到AOSP/development/python-packages/adb/目录的依赖

解决办法:使拷贝adb目录和perfboot.py放到同级目录下(这个部分涉及Python的包管理,简单的做法使用下面的就可以了)

cp development/python-packages/adb/ system/core/init/ -vr

附录:遇到的问题

没有adb设备:

$ ./perfboot.py  --iterations=5 --interval=30 -v --output=/tmp/bf.tsv
Traceback (most recent call last):
  File "./perfboot.py", line 462, in <module>
    main()
  File "./perfboot.py", line 432, in main
    device = adb.get_device(args.serial)
  File "/home/schips/work/qdm507/SC20_Android7.1_R06_r00049.1/system/core/init/adb/device.py", line 112, in get_device
    return _get_unique_device(product, adb_path=adb_path)
  File "/home/schips/work/qdm507/SC20_Android7.1_R06_r00049.1/system/core/init/adb/device.py", line 71, in _get_unique_device
    devices = get_devices(adb_path=adb_path)
  File "/home/schips/work/qdm507/SC20_Android7.1_R06_r00049.1/system/core/init/adb/device.py", line 53, in get_devices
    stderr=devnull)
  File "/usr/lib/python2.7/subprocess.py", line 185, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib/python2.7/subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

解决:找不到adb设备,参考在Ubuntu 18.04 安装 adb 中 的附录。

卡住:INFO:root:adb -s (no wait-for-device,未解决。

$ ./perfboot.py --iterations=5 --interval=30 -v --output=/tmp/J5D_UE.tsv
INFO:root:adb -s (no wait-for-device
^CTraceback (most recent call last):
  File "./perfboot.py", line 462, in <module>
    main()
  File "./perfboot.py", line 439, in main
    check_dm_verity_settings(device)
  File "./perfboot.py", line 213, in check_dm_verity_settings
    device.wait()
  File "/home/schips/work/qdm507/SC20_Android7.1_R06_r00049.1/system/core/init/adb/device.py", line 449, in wait
    return self._simple_call(['wait-for-device'])
  File "/home/schips/work/qdm507/SC20_Android7.1_R06_r00049.1/system/core/init/adb/device.py", line 292, in _simple_call
    self.adb_cmd + cmd, stderr=subprocess.STDOUT)
  File "/home/schips/work/qdm507/SC20_Android7.1_R06_r00049.1/system/core/init/adb/device.py", line 197, in _subprocess_check_output
    return subprocess.check_output(*_get_subprocess_args(args), **kwargs)
  File "/usr/lib/python2.7/subprocess.py", line 217, in check_output
    output, unused_err = process.communicate()
  File "/usr/lib/python2.7/subprocess.py", line 475, in communicate
    stdout = _eintr_retry_call(self.stdout.read)
  File "/usr/lib/python2.7/subprocess.py", line 125, in _eintr_retry_call
    return func(*args)
KeyboardInterrupt
posted @ 2021-02-22 09:00  schips  阅读(1060)  评论(1编辑  收藏  举报