首页 技术 正文
技术 2022年11月8日
0 收藏 388 点赞 1,691 浏览 2582 个字

这个测试可以使用adb工具,adb的安装方式

测试策略

  1. 安装后首次启动
  2. 常规冷启动
  3. 热启动(一般这个都很少测试)

针对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)

步骤二: 在cmd输入启动apk的命令,里面则有启动时间

adb shell  am start -W -n com.sina.weibo/.VisitorMainTabActivity

输出如下,其中,ThisTime则为启动的总时间

Status: ok
Activity: com.sina.weibo/.VisitorMainTabActivity
ThisTime: 1326
TotalTime: 1326
WaitTime: 1354
Complete

毕竟手每次点要等待特别麻烦,那么就用python脚本来实现获得每次的启动时间吧。代码如下

#!/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 - 1 def getCurrentTime(self):
currentTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
return currentTime def 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()

说明下:

a. 其中def SaveDataToCSV(self)这个函数中的file("hotstart_Time.csv", "wb"),python3将file改为open

b. adb安装apk

前提:需要把手机给root

命令:adb install 路径名/包名.apk

数据分析:

  1. 在得到数据后,我们一般将第一行数据去掉,取后几次数据分析
  2. 得到数据,我们要先算出平均值,再者就是要画出取线图查看波动情况
  3. 可与竞品对比此数据,做参考用以判断好坏
  4. 版本之间对比数据
  5. 一般冷启动的时间都在3-5s内
  6. 热启动启动的时间比冷启动要少
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,556
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898