仓廪实则知礼节,衣食足则知荣辱。这篇文章主要讲述App性能测试之启动时间(安卓)相关的知识,希望能为你提供帮助。
这个测试可以使用adb工具,adb的安装方式
测试策略
- 安装后首次启动
- 常规冷启动
- 热启动(一般这个都很少测试)
针对1和2的测试方法
步骤1:在cmd中输入如下命令
adb logcat * > D:log.txt
步骤2:再在手机上打开将要测试的apk,apk启动完成后,cmd上按ctrl+c结束导入日志
步骤3:在D盘找到log.txt,ctrl+f,输入Displayed(搜索Displayed单词),Displayed后面有显示时间,有些app有多个Displayed,启动时间为所有Displayed时间的总和
文章图片
文章图片
此处的启动时间为609+738 (ms)
还有一个方法,可以获取到1,2,3的时间,如下步骤一:获取测试apk的包名(可以问开发要),可以通过adb获取,
1) 先启动apk
2) 在cmd中输入命令:
adb shell dumpsys window w | findstr / | findstr name =
得到如下,其中name后面的则是需要的包名/组件
mSurface=Surface(name=com.sina.weibo/com.sina.weibo.VisitorMainTabActivity)
【App性能测试之启动时间(安卓)】步骤二: 在cmd输入启动apk的命令,里面则有启动时间
adb shellam start -W -n com.sina.weibo/.VisitorMainTabActivity
输出如下,其中,ThisTime则为启动的总时间
Status: ok Activity: com.sina.weibo/.VisitorMainTabActivity ThisTime: 1326 TotalTime: 1326 WaitTime: 1354 Complete
#!/user/bin/python
# _*_ coding: utf-8 _*_
import csv
import re
import os
import timePackage_activity="com.sina.weibo/.VisitorMainTabActivity"
Packagename = "com.sina.weibo"
runnum = 10
class App():
def __init__(self):
self.content = ""
self.startTime = 0
self.flag = 1
def LauchApp(self):
cmd = "adb shell am start -W -n " + Package_activity
self.content = os.popen(cmd)
def StopApp(self):
if self.flag == 1:
cmd = "adb shell am force-stop " + Packagename
else:
cmd = "adb shell input keyevent 3"
os.popen(cmd)def GetLaunchedTime(self):
for line in self.content.readlines():
if "ThisTime" in line:
self.startTime = line.split(":")[1]
break
print (self.startTime)
return self.startTimeclass Controller(object):
def __init__(self):
self.app = App()
self.counter = 0
self.laughtime = [("timestamp","elapsedtime")]def testprocess(self):
self.app.LauchApp()
elpasedtime = self.app.GetLaunchedTime()
time.sleep(3)
self.app.StopApp()
currenttime = self.getCurrentTime()
self.laughtime.append((currenttime,elpasedtime))def run(self):
while self.counter >
0:
self.testprocess()
self.counter = self.counter - 1def getCurrentTime(self):
currentTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
return currentTimedef SaveDataToCSV(self):
if self.app.flag == 1:
csvfile = file("coldstart_Time.csv","wb")
else:
csvfile = file("hotstart_Time.csv", "wb")
writer = csv.writer(csvfile)
writer.writerows(self.laughtime)
csvfile.close()def coldLaugh_run():
controller = Controller()
controller.counter = runnum
controller.app.flag = 1
controller.run()
controller.SaveDataToCSV()def hotLaugh_run():
controller = Controller()
controller.counter = runnum
controller.app.flag = 0
controller.run()
controller.SaveDataToCSV()if __name__ == "__main__":
coldLaugh_run()
hotLaugh_run()
说明下:
其中def SaveDataToCSV(self)这个函数中的file("hotstart_Time.csv", "wb"),python3将file改为open
推荐阅读
- [git] -- warning: LF will be replaced by CRLF in app/app.iml. The file will have its original line e
- Abp.AutoMapper扩展 --static class AutoMapExtensions
- callapplybind
- Android gradle 相关配置
- AndroidStudio导入Eclipse项目报错Error:Could not determine the class-path for interface com.android.builder
- 抖音越狱版本App下载
- Android复习
- Android中通过typeface设置字体
- Deep Learnin 7: Setting up machine learning application