App效能測試之啟動時間(安卓)

來源:互聯網
上載者:User

標籤:sel   pack   timestamp   lse   self   let   分享圖片   data   tst   

這個測試可以使用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: 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效能測試之啟動時間(安卓)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.