最近再调试这个统计FPS的代码,发现代码在android N上可以正常运行,但在android O上却运行不了,拼了命的报错,给出的提示就是 ZeroDivisionError: division by zero,看这错误很明显就是除数不能为0,理论上来说这问题也比较好定位就一步一步找了,排查代码后发现获取除数这个值的逻辑有问题,重新把逻辑修改后获取到正确的值后,重新运行命令跑的时候有时候会有值,有时候还是继续报这个除数不能为零,再重新查看这个除数的来源,是当屏幕有刷新时才能获取到该值,再查看让屏幕刷新的代码,发现是通过monkey的命令来模拟拖动屏幕操作,但在实际测试过程中屏幕根本就没有动,接下来就看Monkey的命令 :adb shell monkey -f /sdcard/monkeyTest_UD.txt 10,发现是从sd卡中获取一个monkey脚本来运行的,打开monkey脚本后,看看格式也没有啥问题。如下
type = user count = 10 speed = 1.0 start data >> Drag(300.0, 307.2, 300.0, 819.2,122.8) Drag(300.0, 307.2, 300.0, 819.2,122.8) Drag(300.0, 819.2, 300.0, 307.2,122.8) Drag(300.0, 819.2, 300.0, 307.2,122.8)
给出monkey命令中drag的命令语法:
Drag(xStart,yStart,xEnd,yEnd,stepCount)
D:WorkSpace3Performance>python3 FPStest.py -o UD -c 10 通过gfxinfo取值, 测试开始... bash arg: -f bash arg: /sdcard/monkeyTest_UD.txt bash arg: 10 args: [-f, /sdcard/monkeyTest_UD.txt, 10] arg: "-f" arg: "/sdcard/monkeyTest_UD.txt" arg: "10" data="/sdcard/monkeyTest_UD.txt" ** Error: A RuntimeException occurred: java.lang.NumberFormatException: For input string: "122.8" at java.lang.Integer.parseInt(Integer.java:608) at java.lang.Integer.parseInt(Integer.java:643) at com.android.commands.monkey.MonkeySourceScript.handleEvent(MonkeySourceScr ipt.java:502) at com.android.commands.monkey.MonkeySourceScript.processLine(MonkeySourceScr ipt.java:793) at com.android.commands.monkey.MonkeySourceScript.readLines(MonkeySourceScrip t.java:249) at com.android.commands.monkey.MonkeySourceScript.readNextBatch(MonkeySourceS cript.java:835) at com.android.commands.monkey.MonkeySourceScript.getNextEvent(MonkeySourceSc ript.java:962) at com.android.commands.monkey.Monkey.runMonkeyCycles(Monkey.java:1199) at com.android.commands.monkey.Monkey.run(Monkey.java:697) at com.android.commands.monkey.Monkey.main(Monkey.java:557) at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method) at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:285) Events injected: 0 ## Network stats: elapsed time=18ms (0ms mobile, 0ms wifi, 18ms not connected) ** System appears to have crashed at event 0 of 10 using seed 1541262762069 Traceback (most recent call last): File "FPStest.py", line 196, in <module> monkey_run() File "FPStest.py", line 190, in monkey_run fps_avg = round(sum(fps_list) / len(fps_list), 2) ZeroDivisionError: division by zero
找到生成monkey脚本的代码,把它调整为整型并保存重新全跑一次所有代码,结果正常生成。