App performance test (CPU)

Source: Internet
Author: User

Get data: adb shell Dumpsys cpuinfo | grep PackageName

result = Os.popen ("adb Shell Dumpsys cpuinfo | grep com.android.browser ")

def testprocess (self):
result = Os.popen ("adb Shell Dumpsys cpuinfo | grep com.android.browser ")
For line in Result.readlines ():
Cpuvalue = line.split ("%") [0]

CurrentTime = Self.getcurrenttime ()
Self.alldata.append ((CurrentTime, Cpuvalue))
def run (self):
While Self.counter >0:
Self.testprocess ()
Self.counter = Self.counter-1
Time.sleep (3)

#获取当前的时间戳
def getcurrenttime (self):
CurrentTime = Time.strftime ("%y-%m-%d%h:%m:%s", Time.localtime ())
Return currenttime
#Encoding:utf-8ImportCSVImportOSImport Time#Control classclassController (object):def __init__(self, count): Self.counter=Count Self.alldata= [("timestamp","Cpustatus")]    #one-time test process    deftestprocess (self): result= Os.popen ("adb shell Dumpsys cpuinfo | grep com.android.browser")         forLineinchresult.readlines (): Cpuvalue= Line.split ("%") [0] CurrentTime=Self.getcurrenttime (Self.alldata.append) (CurrentTime, Cpuvalue)#perform the test process multiple times    defRun (self): whileSelf.counter >0:self.testprocess () self.counter= Self.counter-1Time.sleep (3)    #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 ('Cpustatus.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 (CPU)

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.