Bug Report 包含各种能够帮助我们修复Bug的设备日志,堆栈跟踪和其他一些诊断信息。可以通过命令adb bugreport
来获取bugreport文件信息:
对于Android 7.0及以上,生成bugreport文件到指定目录
adb bugreport <bug_report_path>
若不指定路径,则会生成到local目录
对于Android 7.0及以上,为指定设备生成bugreport
adb devices
adb -s <device_serial_number> bugreport
对于Android 6.0及以下
adb bugreport > <bugreport_name>.txt
通过adb命令生成的通常是一个ZIP文件,且该文件命名为bugreport-<BUILD_ID>-<DATE>.zip
,解压缩后,该文件夹中包含多个文件:
bugreport-<BUILD_ID>-<DATE>.txt
: 最重要的文件,输出的诊断信息,包含:系统服务(dumpsys),错误日志(dumpstate),和系统日志信息(logcat)version.txt
: Android 的发布号systrace.txt
: 如果系统systrace是可用的,则会包含这个文件,关于Systrace tool的介绍见官网FS 文件夹
:dumpstate
工具会将设备文件系统下的文件拷贝到FS文件夹下根据上面的内容可知,bugreport的生成非常简单,目录结构也很好理解,但问题是,这个生成的文件非常庞大,包含的信息量也很大,关于具体解析bug report的文件见官网,可以感受到其中的痛苦,因此Google针对Android5.0(API21)以上的系统开发了一个分析工具Battery Historian来解析bugreport文件,并用web图形的形式展示出来。
Battery Historian工具需要使用bugreport中的 Battery History数据,我们可以在bugreport.txt中找到Battery History 数据拦的信息:
DUMP OF SERVICE batterystats:
Battery History (0% used, 192 used of 256KB, 6 strings using 280):
0 (10) RESET:TIME: 2018-07-24-15-58-31
0 (2) 100 c41000e1 status=discharging health=good plug=none temp=300 volt=4326 charge=0 +running +wake_lock +wifi_radio +screen phone_state=off phone_signal_strength=great brightness=dim +wifi_running +wifi wifi_signal_strength=3 wifi_suppl=completed top=u0a1404:"com.thoughtworks.zion.host.demo"
0 (2) 100 c41000e1 user=0:"0"
0 (2) 100 c41000e1 userfg=0:"0"
+1s605ms (1) 100 c41000e1 wifi_signal_strength=2
+4s617ms (1) 100 c41000e1 wifi_signal_strength=3
+15s166ms (2) 100 c41000e1 -top=u0a1404:"com.thoughtworks.zion.host.demo"
+15s166ms (2) 100 cc1000e1 +wifi_scan +top=u0a58:"com.huawei.android.launcher"
+16s417ms (2) 100 c41000e1 -wifi_scan -top=u0a58:"com.huawei.android.launcher"
+16s660ms (2) 100 c41000e1 +top=u0a1403:"com.huawei.works"
+16s794ms (2) 100 c41000e1 pkgactive=u0a1403:"com.huawei.works"
+37s742ms (1) 100 cc1000e1 +wifi_scan
+38s275ms (1) 100 c41000e1 -wifi_scan
+52s773ms (1) 100 c41000e1 wifi_signal_strength=2
+57s744ms (1) 100 cc1000e1 +wifi_scan
+58s283ms (1) 100 c41000e1 -wifi_scan
+59s405ms (2) 100 c41000e1 stats=0:"remove-uid"
+59s990ms (2) 100 c41000e1 temp=310 volt=4280
+1m01s804ms (1) 100 c41000e1 wifi_signal_strength=3
+1m30s293ms (2) 100 c41000e1 stats=0:"battery-state"
+1m30s310ms (3) 100 c41800e1 status=full plug=usb temp=320 volt=4286 +plugged
这里主要使用Docker,具体步骤如下:
brew cask install docker
直接安装docker run -p <port>:9999 gcr.io/android-battery-historian/stable:3.0 --port 9999
http://localhost:<port>
,能看到如下页面,则安装成功http://123.456.78.90:<port>
访问Historianadb kill-server
adb devices
adb shell dumpsys batterystats --reset
adb shell dumpsys batterystats --enable full-wake-history
一般情况下,设备空闲,屏幕关闭,最后CPU停止运行,wake_lock可以阻止CPU休眠,比如后台持续下载.该维度只记录第一个使用wake_lock的app,如果需要记录所有的,使用上面命令
adb bugreport
命令生成bugreport文件,将该文件上传到localhost:<port>
界面中,就可以开始分析了,生成的图片类似如下:adb shell dumpsys batterystats --disable full-wake-history
Bugreport文件包含整个手机的运行情况,而不是针对某一个特定的App,因此使用Battery Historian查看的情况也如此,需要注意当前展示的数据是选中的App还是全部App的叠加信息。默认显示的图表是全部App的叠加信息,当选中某个App时,图表可能会有所不同,同时,图表左侧Y轴的指标字体会加粗,表示这几个数据在选中后,数据会变为选中App的数据,而其他数据仍然是全部数据。
Battery Historian 的图表显示了一段时间内与耗电量相关的事件,如图所示Battery Historian图表的一个例子:
其中标号的意义是:
Battery Historian除了能够提供宏观的系统层面的信息,还能够提供针对指定App的可视化数据和表格信息,这表格主要信息包括:
Battery Historian图表下为数据分析,包括三个Tab,如下图所示,可以查看App更多信息:
其中,标号所代表的意义是:
作者:sunnyaxin
链接:https://www.jianshu.com/p/a704e2268fe6
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
Android耗电量 - bugreport & Battery Historian
原文:https://www.cnblogs.com/wayne-zhang/p/10676300.html