之前写过monkey方面的测试,这次刚好有项目用到,并且需要监控性能信息,所以重构了一次
- monkey 压力测试android
- python3
- 统计性能信息cpu,men,fps,battery,flow
- 支持wifi,gprs统计
- 统计crash信息
monkey.ini 配置文件
1 cmd=adb shell monkey -p com.jianshu.haruki --throttle 500 --ignore-timeouts --ignore-2 crashes --monitor-native-crashes -v -v -v 200 >
3 package_name=com.jianshu.haruki
4 activity = com.baiji.jianshu.account.SplashScreenActivity
5 net = wifi
- throttle 每次事件等待500毫秒
- net 支持gprs和wifi
代码分析
主要监控代码
def get_cpu(pkg_name):
cmd = "adb shell dumpsys cpuinfo | findstr " + pkg_name
print(cmd)
output = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.readlines()
for info in output:
if info.split()[1].decode().split("/")[1][:-1] == pkg_name: # 只有包名相等
# print("cpu=" + info.split()[2].decode())
cpu.append(float(info.split()[2].decode().split("%")[0]))
print("----cpu-----")
print(cpu)
return cpu
def get_men(pkg_name):
cmd = "adb shell dumpsys meminfo %s" % (pkg_name)
print(cmd)
men_s = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE