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)