Chrome on Android的开发调试技术

来源:互联网 发布:约瑟芬皇后知乎 编辑:程序博客网 时间:2024/06/03 21:07

本文介绍关于Chrome的一些开发调试技术,特别是Chrome on Adnroid的一些开发调试的技术,包括为content_shell / chrome_shell 添加启动参数,用content_shell / chrome_shell来跑测试,debug / profile / trace 某个测试,来fix bug或者找出性能瓶颈。


0. 为自行build的Chrome(或者系统安装的Chrome)添加命令行参数。

src/out/Debug/Chrome (或者opt/google/chrome/chrome) --ignore-certificate-errors --disable-web-security --no-sandbox --allow-file-access-from-files --ignore-gpu-blacklist --enable-unsafe-es3-apis --user-data-dir=./cookie --proxy-server=http://xxxxx.xxxx.xx:xxxx

关于命令行的意义,可以查找http://peter.sh/experiments/chromium-command-line-switches/ 


1. 让chrome_shell或者content_shell加启动参数

将以下内容,写到chrome-shell-command-line或者content-shell-command-line文件,adb push 到android device的 /data/local/temp下,就可以在chrome-shell/content-shell启动时激活这些命令行参数。

chrome_shell --show-fps-counter --enable-display-list-2d-canvas

chrome-shell --allow-file-access-from-files --disable-web-security --ignore-gpu-blacklist --js-flags="--trace-deopt --trace-opt --trace_gc --max-semi-space-size=128"

content_shell --show-fps-counter --enable-display-list-2d-canvas


2. 用chrome-shell测试某个benchmark:

2.1 将该benchmark push到android device, 然后可以测试:

adb push PATH/test.html /sdcard/

src/build/android/adb_run_chrome_shell file:///sdcard/test.html 

2.2 也可以将该benchmark放到host machine的/var/www/html/目录下,这样启动Apache, HTTPSimpleServer, 然后再运行chrome_shell 


当然,如果benchmark可以通过网络访问,则直接通过网络

src/build/android/adb_run_chrome_shell http://www.xxxxx.com/xxxxx


2.3 测试FPS可以用 ./build/android/surface_stats.py 


3. debugging:

如果要fix bug, 往往需要用gdb来调试:

debugging for x86 by gdb

./build/android/adb_gdb_chrome_shell --start --gdb-server=third_party/android_tools/ndk_experimental/prebuilt/android-x86/gdbserver/gdbserver --gdb=third_party/android_tools/ndk_experimental/toolschains/x86-4.8/prepbuilt/linux-x86_64/bin/i686-linux-android-gdb --target-arch=x86 --pid=? 


debugging for arm by gdb:

./build/android/adb_gdb_chrome_shell --start --gdbserver=third_party/android_tools/ndk/prebuilt/android-arm/gdbserver/gdbserver --gdb=third_party/android_tools/ndk/toolchains/arm-linux-androidabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gdb --target--arch=arm --pid=?


4. Tracing:

Tracing的数据可以用Chrome浏览器直接打开查看,包括各个进程的Trace信息,可以快速反应某个测试或benchmark下,哪里是性能瓶颈。

1) 运行程序: build/adnroid/adb_run_chrome_shell    http://www.xxxxxx   (或者/data/local/tmp/xxxx.html)

2) tracing: build/android/adb_profile_chrome --browser=chrome_shell --trace-gpu -t 2  (也可以添加其它参数,比如--trace-frame-viewer等等)

3) adb pull /data/local/tmp/xxx   ./   

4) 用浏览器打开查看。



5. 用perf来profiling chrome on Android:

perf / vtune / oprofile等工具能用来查看运行某个测试时,cpu的使用情况,可以具体到每个函数级别。perf是linux kernel自带的profiling工具,自2.6以后的linux kernel 都能支持它,而Android 也是基于Linux kernel, 也原生支持perf来做profiling.

4.1 设置环境,编译perf和Chrome for android:

1) 下载Linux kernel, 为Linux Desktop编译perf host

2) 从AOSP中编译perf client, 安装perf到android device中 

3) 添加"profiling=1"到GYP_DEFINES, 编译content_shell / chrome_shell

4) 用content_shell / chrome_shell 跑benchmarks.


4.2 profiling by perf:

1) 得到PID: adb shell ps | grep content  (或者chrome_shell)

2) 用perf client来profile:

adb shell perf record -g -a -o /data/local/tmp/speedreading.data sleep 5

adb shell perf record -g -p $PID -o /data/local/tmp/speedreading_render.data sleep 5 

3) 把perf data传到host, 用perf host来分析profile

adb pull /data/local/tmp/speedreading.data

./perf report -i ./speedreading.data --symfs ./symbols


对于某些设备,可能需要把src/content/public/android/java/src/org/chromium/content/browser/TracingControllerAndroid.java里的

File file = new File(

        dir, "chrome-profile-results-“ + ... 

dir换成/data/local/tmp



0 0
原创粉丝点击