標籤:sel pack timestamp lse self let 分享圖片 data tst
這個測試可以使用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)
步驟二: 在cmd輸入啟動apk的命令,裡面則有啟動時間
adb shell am start -W -n com.sina.weibo/.VisitorMainTabActivity
輸出如下,其中,ThisTime則為啟動的總時間
Status: okActivity: com.sina.weibo/.VisitorMainTabActivityThisTime: 1326TotalTime: 1326WaitTime: 1354Complete
畢竟手每次點要等待特別麻煩,那麼就用python指令碼來實現獲得每次的啟動時間吧。代碼如下
#!/user/bin/python# _*_ coding: utf-8 _*_import csvimport reimport osimport timePackage_activity="com.sina.weibo/.VisitorMainTabActivity"Packagename = "com.sina.weibo"runnum = 10class 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()
說明下:
其中def SaveDataToCSV(self)這個函數中的file("hotstart_Time.csv", "wb"),python3將file改為open
App效能測試之啟動時間(安卓)