App performance test (startup time)

Source: Internet
Author: User

#Encoding:utf-8ImportCSVImportOSImport TimeclassApp (object):def __init__(self): self.content=""Self.starttime=0#Launch App    defLaunchapp (self): cmd='adb shell am start-w-n com.android.browser/. Browseractivity'self.content=os.popen (cmd)#Stop App    defStopapp (self):#cmd = ' adb shell am force-stop com.android.browser 'cmd ='adb shell input keyevent 3'os.popen (cmd)#Get start time    defGetlaunchedtime (self): forLineinchself.content.readlines ():if "Thistime" inchLine:self.startTime= Line.split (":") [1]                 Break        returnSelf.starttime#Control classclassController (object):def __init__(self, count): Self.app=App () self.counter=Count Self.alldata= [("timestamp","ElapsedTime")]    #one-time test process    deftestprocess (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)#perform the test process multiple times    defRun (self): whileSelf.counter >0:self.testprocess () self.counter= Self.counter-1#gets the current timestamp    defGetCurrentTime (self): CurrentTime= Time.strftime ("%y-%m-%d%h:%m:%s", Time.localtime ())returncurrenttime#Storage of Data    defsavedatatocsv (self): CSVFile= File ('Starttime2.csv','WB') Writer=Csv.writer (csvfile) writer.writerows (self.alldata) csvfile.close ()if __name__=="__main__": Controller= Controller (10) Controller.run () controller. Savedatatocsv ()

App performance test (startup time)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.