使用Batterystats收集数据
1.将待测手机连接电脑(一次连接一个)
2.关闭正在运行的adb服务:
adb kill-server
3.确认设备已连接,同时获取到设备的device_id:
adb devices
4.设置无线连接(确保手机和电脑连接在同一局域网下)
4.1 设置连接端口:
adb -s {device_id} tcpip 5555 #也可设置为5556等,对于多个设备,应分别设置不同的端口
4.2 查看手机ip(如10.55.32.156)
4.3 连接:
adb connect 10.55.32.156:5555
5.断开手机与电脑的连接
6.设置Batterystats采集wake_lock数据:
adb -s {device_id} shell dumpsys batterystats --enable full-wake-history
7.重置电池数据:
adb -s {device_id} shell dumpsys batterystats --reset
8.执行想要自动执行的操作
如:滑动一次屏幕
adb -s {device_id} shell input swipe 540 1300 540 500
9.执行完成之后,收集数据报告,会在当前目录中生成报告文件
adb -s {device_id} bugreport
以上过程可用python脚本完成
import os
import time
device_id = "R5CN70FP42L"
ip = "10.55.32.201"
port = "5557"
os.system("adb -s " + device_id + " tcpip " + port)
os.system("adb connect " + ip + ":" + port) # 会显示connected to 10.55.32.201:5555
time.sleep(10) # 此时拔线,点开app,进入视频页面
os.system("adb -s " + ip + ":" + port + " shell dumpsys batterystats --enable full-wake-history")
os.system("adb -s " + ip + ":" + port + " shell dumpsys batterystats --reset")
for i in range(180):
os.system("adb -s " + ip + ":" + port + " shell input swipe 540 1300 540 500")
time.sleep(10)
os.system("adb -s " + ip + ":" + port + " bugreport")