zoukankan      html  css  js  c++  java
  • python+dump安卓专项测试

    主要是进行cpu、内存、冷启动、热启动、流量、电量的监测

    可获取到相关数据,同竞类产品对比,或者同版本对比

    cpustatus

    adb命令:adb shell "dumpsys cpuinfo | grep com.person.buddy"

    # coding=utf-8#/usr/bin/python
    #encoding:utf-8
    import csv
    import os
    import time

    #控制类
    class Controller(object):
    def __init__(self, count):
    self.counter = count
    self.alldata = [("timestamp", "cpustatus")]


    #单次测试过程
    def testprocess(self):
    cmd = 'adb shell "dumpsys cpu|grep com.person.buddy"'
    # cmd='adb shell "dumpsys cpuinfo | grep com.person.buddy"'
    result = os.popen(cmd)
    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

    #数据的存储
    def SaveDataToCSV(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()

    launchtime
    # coding=utf-8
    # /usr/bin/python
    # encoding:utf-8
    import csv
    import os
    import time


    # 同QQ、微信等对比
    # 同上下版本进行对比
    class App(object):
    def __init__(self):
    self.content = ""
    self.startTime = 0

    # 启动App
    def LaunchApp(self):
    cmd = 'adb shell am start -W -n com.person.buddy/com.person.buddy.ui.app.LogoActivity'
    self.content = os.popen(cmd)

    # 热启动停止App
    def WarmStopApp(self):
    cmd = 'adb shell am force-stop com.person.buddy'
    # cmd = 'adb shell input keyevent 3'
    os.popen(cmd)

    # 冷启动停止APP
    def ColdStopApp(self):
    cmd = 'adb shell am force -stop com.person.buddy'
    os.open(cmd)

    # 获取启动时间
    def GetLaunchedTime(self):
    for line in self.content.readlines():
    if "ThisTime" in line:
    self.startTime = line.split(":")[1]
    break
    return self.startTime


    # 控制类
    class Controller(object):
    def __init__(self, count):
    self.app = App()
    self.counter = count
    self.alldata = [("timestamp", "elapsedtime")]

    # 单次测试过程
    def testprocess(self):
    self.app.LaunchApp()
    time.sleep(5)
    elpasedtime = self.app.GetLaunchedTime()
    self.app.WarmStopApp()
    time.sleep(3)
    currenttime = self.getCurrentTime()
    self.alldata.append((currenttime, elpasedtime))

    # 多次执行测试过程
    def run(self):
    while self.counter > 0:
    self.testprocess()
    self.counter = self.counter - 1

    # 获取当前的时间戳
    def getCurrentTime(self):
    currentTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    return currentTime

    # 数据的存储
    def SaveDataToCSV(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()

    men
    # coding=utf-8
    #/usr/bin/python
    #encoding:utf-8
    import csv
    import os
    import time

    #控制类
    class Controller(object):
    def __init__(self):
    #定义收集数据的数组
    self.alldata = [("id", "vss", "rss")]

    #分析数据
    def analyzedata(self):
    content = self.readfile()
    i = 0
    for line in content:
    if "com.person.buddy" in line:
    print line
    line = "#".join(line.split())
    vss = line.split("#")[5].strip("K")
    rss = line.split("#")[6].strip("K")

    #将获取到的数据存到数组中
    self.alldata.append((i, vss, rss))
    i = i + 1

    #数据的存储
    def SaveDataToCSV(self):
    csvfile = file('meminfo.csv', 'wb')
    writer = csv.writer(csvfile)
    writer.writerows(self.alldata)
    csvfile.close()

    #读取数据文件
    def readfile(self):
    mfile = file("meminfo", "r")
    content = mfile.readlines()
    mfile.close()
    return content

    if __name__ == "__main__":
    controller = Controller()
    controller.analyzedata()
    controller.SaveDataToCSV()

    power
    # coding=utf-8
    #/usr/bin/python
    #encoding:utf-8
    import csv
    import os
    import time

    #控制类
    class Controller(object):
    def __init__(self, count):
    #定义测试的次数
    self.counter = count
    #定义收集数据的数组
    self.alldata = [("timestamp", "power")]

    #单次测试过程
    def testprocess(self):
    #执行获取电量的命令
    result = os.popen("adb shell dumpsys battery")
    #获取电量的level
    for line in result:
    if "level" in line:
    power = line.split(":")[1]

    #获取当前时间
    currenttime = self.getCurrentTime()
    #将获取到的数据存到数组中
    self.alldata.append((currenttime, power))

    #多次测试过程控制
    def run(self):
    #设置手机进入非充电状态
    os.popen("adb shell dumpsys battery set status 1")
    while self.counter >0:
    self.testprocess()
    self.counter = self.counter - 1
    #每30秒钟采集一次数据
    time.sleep(30)

    #获取当前的时间戳
    def getCurrentTime(self):
    currentTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    return currentTime

    #数据的存储
    def SaveDataToCSV(self):
    csvfile = file('power.csv', 'wb')
    writer = csv.writer(csvfile)
    writer.writerows(self.alldata)
    csvfile.close()

    if __name__ == "__main__":
    controller = Controller(5)
    controller.run()
    controller.SaveDataToCSV()
    traffic
    # coding=utf-8
    #/usr/bin/python
    #encoding:utf-8
    import csv
    import os
    import string
    import time

    #控制类
    class Controller(object):
    def __init__(self, count):
    #定义测试的次数
    self.counter = count
    #定义收集数据的数组
    self.alldata = [("timestamp", "traffic")]

    #单次测试过程
    def testprocess(self):
    #执行获取进程的命令
    cmd = 'adb shell "ps|grep com.person.buddy"'
    result = os.popen(cmd)
    #获取进程ID
    pid = result.readlines()[0].split(" ")[5]

    #获取进程ID使用的流量
    traffic = os.popen("adb shell cat /proc/"+pid+"/net/dev")
    for line in traffic:
    if "eth0" in line:
    #将所有空行换成#
    line = "#".join(line.split())
    #按#号拆分,获取收到和发出的流量
    receive = line.split("#")[1]
    transmit = line.split("#")[9]
    elif "eth1" in line:
    # 将所有空行换成#
    line = "#".join(line.split())
    # 按#号拆分,获取收到和发出的流量
    receive2 = line.split("#")[1]
    transmit2 = line.split("#")[9]

    #计算所有流量的之和
    alltraffic = string .atoi(receive) + string .atoi(transmit) + string .atoi(receive2) + string .atoi(transmit2)
    #按KB计算流量值
    alltraffic = alltraffic/1024
    #获取当前时间
    currenttime = self.getCurrentTime()
    #将获取到的数据存到数组中
    self.alldata.append((currenttime, alltraffic))

    #多次测试过程控制
    def run(self):
    while self.counter >0:
    self.testprocess()
    self.counter = self.counter - 1
    #每5秒钟采集一次数据
    time.sleep(5)

    #获取当前的时间戳
    def getCurrentTime(self):
    currentTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    return currentTime

    #数据的存储
    def SaveDataToCSV(self):
    csvfile = file('traffic.csv', 'wb')
    writer = csv.writer(csvfile)
    writer.writerows(self.alldata)
    csvfile.close()

    if __name__ == "__main__":
    controller = Controller(5)
    controller.run()
    controller.SaveDataToCSV()

     







  • 相关阅读:
    图文并茂记录下重新配置Win10系统Flutter环境--内含Android Studio 下载安装教程
    图文并茂解决Client does not support authentication protocol requested by server; consider upgrading MySQL
    图文并茂基于阿里云linux服务器部署nodejs项目并添加pm2守护nodejs项目运行进程(Linux version 4.19.81-17.1.al7.x86_64)
    超简单的图文并茂Linux上使用yum安装Mysql(Aliyun Linux release 2.1903 LTS)
    使用linux命令直接在网上下载文件,解压,改名
    解决使用linux部署nodejs服务测试代码返回中文是乱码
    Echarts点击多组数据多个柱子中的一个柱子,获取当前点击的是第几组数据,并获取点击的是当前组别第几根柱子,以及对应横坐标,
    flutter 2.X报错 Bad state: Insecure HTTP is not allowed by platform:
    flutter 2.x运行flutter run 报错Cannot run with sound null safety, because the following dependenciesdon'
    flutter 1.升级2.X在模型类中序列化JSON报错Non-nullable instance field 'title' must be initialized.
  • 原文地址:https://www.cnblogs.com/LinxiHuang/p/9398403.html
Copyright © 2011-2022 走看看