主要是进行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()

https://blog.csdn.net/Asaasa1/article/details/108868054

python adb 安卓app性能测试的更多相关文章

  1. 安卓APP性能测试的一些方面

    1. 启动速度 2. 点击/滑动等事件响应速度 3. 下载速度 4. 界面流畅程度,比较帧率 5. 耗电量测试 6. 流量测试 7. 内存泄漏 8. CPU 9. Monkey adb -s FJH5 ...

  2. 如何Python写一个安卓APP

    前言:用Python写安卓APP肯定不是最好的选择,但是肯定是一个很偷懒的选择,而且实在不想学习Java,再者,就编程而言已经会的就Python与Golang(注:Python,Golang水平都一般 ...

  3. 篇2 安卓app自动化测试-初识python调用appium

    篇2              安卓app自动化测试-初识python调用appium --lamecho辣么丑 1.1概要 大家好!我是lamecho(辣么丑),上一篇也是<安卓app自动化测 ...

  4. Ocr答题辅助神器 OcrAnswerer4.x,通过百度OCR识别手机文字,支持屏幕窗口截图和ADB安卓截图,支持四十个直播App,可保存题库

    http://www.cnblogs.com/Charltsing/p/OcrAnswerer.html 联系qq:564955427 最新版为v4.1版,开放一定概率的八窗口体验功能,请截图体验(多 ...

  5. Android app性能测试小结(7个性能指标)

    1.性能测试的几个指标:       2.性能测试环境准备: 3.启动时间 3.1,监控值的获取方法 启动分为冷启动和热启动,冷启动:应用程序首次启动,进程首次创建并加载资源的过程:热启动:应用程序启 ...

  6. Python appium搭建app自动化测试环境

    appium做app自动化测试,环境搭建是比较麻烦的. 也是很多初学者在学习app自动化之时,花很多时间都难跨越的坎. 但没有成功的环境,就没有办法继续后续的使用. 在app自动化测试当中,我们主要是 ...

  7. 史上最全的用Python操控手机APP攻略!建议收藏!

    ​最近经常看到用Python操作手机APP的项目,例如抖音.闲鱼之类的,看完后发现这些项目无一例外需要部署ADB环境.至于什么是ADB,很多大神都讲过,只是写得比较专业,我等菜鸟看完还是云里雾里. ​ ...

  8. App性能测试揭秘(Android篇)

    阿里云 云原生应用研发平台EMAS 李嘉华(千瞬) 简介: 性能测试在移动测试领域一直是一个大难题,它最直观的表现是用户在前台使用 App 时的主观体验,然而决定体验优劣的背后,涉及到了许许多多的技术 ...

  9. 安卓APP测试验证点总结

    最近较懒,加之闺女出生后记忆没完全恢复,总是忘东忘西,关于安卓APP测试的验证点还是总结一下,方便设计测试用例时查阅,也给各位博友参考! 1.除APP的正常功能点外,还有以下验证点: 安装/卸载(考虑 ...

  10. 篇3 安卓app自动化测试-搞定界面元素

    篇3                 安卓app自动化测试-搞定界面元素 --lamecho辣么丑 1.1概要 大家好! 我是lamecho(辣么丑),今天是<安卓app自动化测试>的第三 ...

随机推荐

  1. 微服务新体验之Aspire初体验

    安装aspire 查看vs版本 我这的版本是17.9.7,不支持aspire,所以需要升级 更新VS 点击 帮助->检查更新 点击更新 静等安装升级 创建aspire项目 项目创建成功,如下图 ...

  2. 公司es扩容kibana添加密码访问

    准备工作 基础优化[部署好的es无需操作,新server操作] setenforce 0 getenforce sed -i 's#^SELINUX=.*$#SELINUX=disabled#g' / ...

  3. C语言-使用malloc导致的奔溃问题

    在使用malloc.memset.free的过程中,出现了程序奔溃,大致现象如下. 程序的实现大致如下: #include <stdio.h> #include <stdlib.h& ...

  4. CF364E

    problem 算法1 我会暴力!!! 直接枚举右上角和左下角,然后计算答案,使用前缀和优化后时间复杂度为 \(O(n^4)\). 算法2 我会分治!!!. 我们知道答案就是左边+右边+两边都有的个数 ...

  5. Unity3D 内存管理非代码技巧

    在场景管理器新建 gameobjct 使用代码在类初始化时 NEW 普肉fai包(包)然后将相同的类NEW够挂载到 gameobjct子节点上 在操控列表中类的时候用for循环遍历操作移动还是怎么样( ...

  6. The remote name could not be resolved

    HTTP The remote name could not be resolved HTTP Status:NameResolutionFailure

  7. 记一次 React context 使用

    学习 React 之 Context 使用 记录一次React context 使用 React.createContext Api 新建文件 contexts.js 文件用来存放 context 对 ...

  8. Nuxt3 的生命周期和钩子函数(一)

    title: Nuxt3 的生命周期和钩子函数(一) date: 2024/6/25 updated: 2024/6/25 author: cmdragon excerpt: 摘要:本文是关于Nuxt ...

  9. 【基础计算】ESDF栅格距离图计算并行加速版

    前言与参考 这一部分仅为路径规划源码及论文GPIR的一个小部分,但是有代码实现,第一次看的时候有些懵,所以特此记录:主要是设置好了栅格地图后,添加了障碍物后,对其的欧式距离计算和梯度计算等.原代码中为 ...

  10. Go 如何对多个网络命令空间中的端口进行监听

    Go 如何对多个网络命令空间中的端口进行监听 需求为 对多个命名空间内的端口进行监听和代理. 刚开始对 netns 的理解不够深刻,以为必须存在一个新的线程然后调用 setns(2) 切换过去,如果有 ...