响应时间

响应时间----应用的冷热启动时间

 

硬件:

高速摄像头

选定起始帧和结束帧--自动算出时间

 

软件:

1.通过手动点击应用查看logcat日志的方式获取

  命令行adb logcat -c 看日志先adb logcat  -v threadtime  -b events在点击应用找到activity_lanch_time(包含响应时间和初始化时间)

 

2.python脚本+adb start命令抓取This time时间作为参考值

  核心就是:启动都是adb shell am start -W -n       冷启动停止 adb shell am force-stop com.android.contacts    热启动停止 adb shell input keyevent 3(返回键)

  取数据os.popen函数传入命令,遍历每一行找到thistime这行,:进行分割,取出第2个数据,就是下表为1,把取到的数据存在csv文件

       ThisTime:对应activity启动耗时
  TotalTime:应用自身启动耗时 = ThisTime + 应用application等资源启动时间
  WaitTime:系统启动应用耗时 = TotalTime + 系统资源启动时间

 

 

1:取值(踢出第一条数据)
每次的值做出曲线--看看波动情况
全部数据取平均值
2.测试策略
竞品分析 ---和别的应用对比平均值
横向对比 ---上下版本做为横向对比

 

  

 

  冷:

import csv
import os
import time
#启动时间-用的第一种
#一种:获取am start命令行的启动时间--ThisTime作为参考值
#二种:am start 命令行前后加时间戳,以它们的差值-作为参考值
#冷
#adb shell am force-stop com.android.contacts


class App(object):
def __init__(self):
self.content = ""
self.startTime = 0

#启动App
def LaunchApp(self):

cmd = 'adb shell am start -W -n com.android.contacts/.activities.PeopleActivity'

self.content=os.popen(cmd)

#停止App-冷
def StopApp(self):
cmd = 'adb shell am force-stop com.android.contacts'
os.popen(cmd)

#获取启动时间
def GetLaunchedTime(self):
for line in self.content.readlines():
if "ThisTime" in line:
self.startTime = line.split(":")[1]
break
return self.startTime

#控制类
class Controller(object):
def __init__(self, count):
self.app = App()
self.counter = count
self.alldata = [("timestamp", "elapsedtime")]

#单次测试过程
def testprocess(self):
self.app.LaunchApp()
time.sleep(5)
elpasedtime = self.app.GetLaunchedTime()
self.app.StopApp()
time.sleep(3)
currenttime = self.getCurrentTime()
self.alldata.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):
csvfile = open('coldtime.csv', 'w')
writer = csv.writer(csvfile)
writer.writerows(self.alldata)
csvfile.close()

if __name__ == "__main__":
controller = Controller(10)
controller.run()
controller.SaveDataToCSV()

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

热启动
import csv
import os
import time
#启动时间
#一种:获取am start命令行的启动时间--ThisTime作为参考值
#二种:am start 命令行前后加时间戳,以它们的差值-作为参考值
#热
#adb shell input keyevent 3

class App(object):
def __init__(self):
self.content = ""
self.startTime = 0

#启动App
def LaunchApp(self):

cmd = 'adb shell am start -W -n com.android.contacts/.activities.PeopleActivity'

self.content=os.popen(cmd)

#停止App-热
def StopApp(self):
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
return self.startTime

#控制类
class Controller(object):
def __init__(self, count):
self.app = App()
self.counter = count
self.alldata = [("timestamp", "elapsedtime")]

#单次测试过程
def testprocess(self):
self.app.LaunchApp()
time.sleep(5)
elpasedtime = self.app.GetLaunchedTime()
self.app.StopApp()
time.sleep(3)
currenttime = self.getCurrentTime()
self.alldata.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):
csvfile = open('heattime.csv', 'w')
writer = csv.writer(csvfile)
writer.writerows(self.alldata)
csvfile.close()

if __name__ == "__main__":
controller = Controller(10)
controller.run()
controller.SaveDataToCSV()

 

 

 

posted @ 2021-11-30 23:16  观呼吸  阅读(287)  评论(0)    收藏  举报