APP special test 2-CPU cmd command and script

retrieve data

adb shell "dumpsys meminfo | grep com.example.shineapp"

 

 

Import OS
 Import Time
 Import CSV 

# control class 
class the Controller (Object): 

    DEF  the __init__ (Self, COUNT): 
        self.counter = COUNT 
        self.alldata = [( " timestamp " , " cpustatus " )] 

    # single test 
    DEF testprocess (Self): 
        cpuvalue = 0 
        Result = os.popen, ( ' the adb the shell "dumpsys meminfo | grep com.example.shineapp" ' )    # double quotation marks can not be used
        for line in result.readlines (): 
            cpuvalue = line.split ( " : " ) [0] 

        currenttime = self.getCurrentTime () 
        self.alldata.append ((currenttime, cpuvalue)) 

    # execute 
    def run (self) multiple times :
         the while self.counter> 0: 
            self.testprocess () 
            self.counter =. 1-self.counter 
            the time.sleep ( . 5)    # collection interval 

    # Get the current timestamp 
    DEF getCurrentTime (Self): 
        currentTime = the time.strftime ( "%Y-%m-%d  %H:%M:%S")
        return currenttime

    #数据存储
    def SaveDataToCsv(self):
        csvfile = open("cpustatus.csv","wb")
        writer = csv.writer(csvfile)
        writer.writerows(self.alldata)
        csvfile.close()




if __name__ == '__main__':
    controller = Controller(10)
    controller.run()
    controller.SaveDataToCsv()

 

Guess you like

Origin www.cnblogs.com/lexus168/p/12690858.html