zoukankan      html  css  js  c++  java
  • APP专项测试2 -- CPU cmd命令及脚本

    获取数据

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

    import os
    import time
    import csv
    
    #控制类
    class Controller(object):
    
        def __init__(self,count):
            self.counter = count
            self.alldata = [("timestamp","cpustatus")]
    
        #单次测试过程
        def testprocess(self):
            cpuvalue = 0
            result = os.popen('adb shell "dumpsys meminfo | grep com.example.shineapp"')   #双引号不能同时使用
            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(5)   #采集的时间间隔
    
        #获取当前时间戳
        def getCurrentTime(self):
            currenttime = 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()
  • 相关阅读:
    C#创建ActiveX
    easy-ui 中的事件触发 (tree)
    程序目录
    微信公众平台开发
    Redis分片机制
    Redis主从切换
    Redis主从复制
    Redis持久化机制
    Redis缓存击穿、缓存穿透、缓存雪崩
    Redis与数据库数据一致性
  • 原文地址:https://www.cnblogs.com/lexus168/p/12690858.html
Copyright © 2011-2022 走看看