当前位置:网站首页>App performance test: (I) startup time

App performance test: (I) startup time

2022-06-13 06:16:00 Ming ruoxiao River

app The performance test is mainly divided into :

Starting time ,CPU, Traffic , Electric quantity , Memory ,FPS, Over rendering

First, the startup time is analyzed :

app The startup of is divided into cold startup ( Create... For the first time ), Hot start ( Through the return key ,home Push the key to the background , Not completely killed )

First, the startup time is analyzed :

Cold start

  • start-up app command

     adb shell am start -W -n  Package name /Activity name 
    
  • stop it app command

     adb shell am force-stop  Package name 
    

Hot start

  • start-up app The command is the same as the cold start command

      adb shell am start -W -n  Package name /Activity name 
    
  • stop it app command

     adb shell input keyevent 3
    

obtain app Package name command (win10 Next )

adb logcat | findstr "START"

Then click Start app, Can cmp=(…/…) notice app The package name and app Start page of

Script code :

#/usr/bin/python
#encoding:utf-8
import csv
import os
import time

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

    # start-up App
    def LaunchApp(self):
        cmd = 'adb shell am start -W -n com.zahd.agriculturaltraceability.debug/com.zahd.agriculturaltraceability.ui.Activity.LoginActivity'
        self.content=os.popen(cmd)

    # stop it App
    def StopApp(self):
        #cmd = 'adb shell am force-stop com.zahd.agriculturaltraceability.debug'
        cmd = 'adb shell input keyevent 3'
        os.popen(cmd)

    # Get start time 
    def GetLaunchedTime(self):
        for line in self.content.readlines():
            if "ThisTime" in line:
                self.startTime = line.split(":")[1]
                break
        return self.startTime

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

    # Single test process 
    def testprocess(self):
        self.app.LaunchApp()
        print("1")
        time.sleep(5)
        elpasedtime = self.app.GetLaunchedTime()
        self.app.StopApp()
        time.sleep(3)
        currenttime = self.getCurrentTime()
        self.alldata.append((currenttime, elpasedtime))

    # Perform the test process multiple times 
    def run(self):
        while self.counter >0:
            self.testprocess()
            self.counter = self.counter - 1

    # Get the current timestamp 
    def getCurrentTime(self):
        currentTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        return currentTime

    # Data storage 
    def SaveDataToCSV(self):
        csvfile = open('startTime2.csv', mode='w')
        writer = csv.writer(csvfile)
        writer.writerows(self.alldata)
        csvfile.close()

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

Expand

 Power key : adb shell input keyevent 26

HOME  key : adb shell input keyevent 3

 Return key : adb shell input keyevent 4

 Light up the screen : adb shell input keyevent 224

 Turn off the screen : adb shell input keyevent 223

 Input text : adb shell input text xxxxx
原网站

版权声明
本文为[Ming ruoxiao River]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202270556300024.html