python adb 安卓app性能测试
主要是进行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性能测试的更多相关文章
- 安卓APP性能测试的一些方面
1. 启动速度 2. 点击/滑动等事件响应速度 3. 下载速度 4. 界面流畅程度,比较帧率 5. 耗电量测试 6. 流量测试 7. 内存泄漏 8. CPU 9. Monkey adb -s FJH5 ...
- 如何Python写一个安卓APP
前言:用Python写安卓APP肯定不是最好的选择,但是肯定是一个很偷懒的选择,而且实在不想学习Java,再者,就编程而言已经会的就Python与Golang(注:Python,Golang水平都一般 ...
- 篇2 安卓app自动化测试-初识python调用appium
篇2 安卓app自动化测试-初识python调用appium --lamecho辣么丑 1.1概要 大家好!我是lamecho(辣么丑),上一篇也是<安卓app自动化测 ...
- Ocr答题辅助神器 OcrAnswerer4.x,通过百度OCR识别手机文字,支持屏幕窗口截图和ADB安卓截图,支持四十个直播App,可保存题库
http://www.cnblogs.com/Charltsing/p/OcrAnswerer.html 联系qq:564955427 最新版为v4.1版,开放一定概率的八窗口体验功能,请截图体验(多 ...
- Android app性能测试小结(7个性能指标)
1.性能测试的几个指标: 2.性能测试环境准备: 3.启动时间 3.1,监控值的获取方法 启动分为冷启动和热启动,冷启动:应用程序首次启动,进程首次创建并加载资源的过程:热启动:应用程序启 ...
- Python appium搭建app自动化测试环境
appium做app自动化测试,环境搭建是比较麻烦的. 也是很多初学者在学习app自动化之时,花很多时间都难跨越的坎. 但没有成功的环境,就没有办法继续后续的使用. 在app自动化测试当中,我们主要是 ...
- 史上最全的用Python操控手机APP攻略!建议收藏!
最近经常看到用Python操作手机APP的项目,例如抖音.闲鱼之类的,看完后发现这些项目无一例外需要部署ADB环境.至于什么是ADB,很多大神都讲过,只是写得比较专业,我等菜鸟看完还是云里雾里. ...
- App性能测试揭秘(Android篇)
阿里云 云原生应用研发平台EMAS 李嘉华(千瞬) 简介: 性能测试在移动测试领域一直是一个大难题,它最直观的表现是用户在前台使用 App 时的主观体验,然而决定体验优劣的背后,涉及到了许许多多的技术 ...
- 安卓APP测试验证点总结
最近较懒,加之闺女出生后记忆没完全恢复,总是忘东忘西,关于安卓APP测试的验证点还是总结一下,方便设计测试用例时查阅,也给各位博友参考! 1.除APP的正常功能点外,还有以下验证点: 安装/卸载(考虑 ...
- 篇3 安卓app自动化测试-搞定界面元素
篇3 安卓app自动化测试-搞定界面元素 --lamecho辣么丑 1.1概要 大家好! 我是lamecho(辣么丑),今天是<安卓app自动化测试>的第三 ...
随机推荐
- Dockerfile-NGINX镜像制作
1 NGINX镜像制作: 1.1 NGINX-dockerfile FROM centos:7 LABEL maintainer www.chenleilei.net RUN useradd www ...
- Leetcode-916. Word Subsets-(Medium)
一.问题描述 We are given two arrays A and B of words. Each word is a string of lowercase letters. Now, s ...
- OpenTelemetry agent 对 Spring Boot 应用的影响:一次 SPI 失效的案例
背景 前段时间公司领导让我排查一个关于在 JDK21 环境中使用 Spring Boot 配合一个 JDK18 新增的一个 SPI(java.net.spi.InetAddressResolverPr ...
- SQL练习之打卡记录数据统计类问题
最近老婆的公司,关闭了OA系统中,各类打卡时间数据统计的功能,为了不麻烦老婆手算,就做了一个简单的打卡系统,方便自动统计老婆想要知道的各类数据. 做的过程中就遇到了几个还挺有意思的SQL,这里写成一篇 ...
- 使用线程池实现为多个客户端提供Echo服务
import java.io.*; import java.net.ServerSocket; import java.net.Socket; import java.util.Scanner; im ...
- maven常用命令大全(附详细解释)
1.常用打包命令 mvn clean package -Dmaven.test.skip=true -- 跳过单测打包mvn clean install -Dmaven.test.skip=true ...
- Spring扩展——BeanFactory和FactoryBean
BeanFactory和FactoryBean BeanFactory和FactoryBean长得很相似,也很容易让我们产生误解,特别是对于初学者而言,搞懂他俩关系非常有必要,因为这两个接口,是Spr ...
- STM32 CubeMX 学习:001-GPIO的使用
背景 在上一讲STM32 CubeMX 学习:搭建开发环境中,我们已经利用CubeMx搭建了可编译的工程. 今天就开始来介绍STM32 GPIO的有关知识,以及如何驱动它. HOST-OS : Win ...
- .NET周刊【6月第4期 2024-06-23】
国内文章 C#.Net筑基-集合知识全解 https://www.cnblogs.com/anding/p/18229596 .Net中提供了数组.列表.字典等多种集合类型,分为泛型和非泛型集合.泛型 ...
- WPF在.NET9中的重大更新:Windows 11 主题
在2023年的2月20日,在WPF的讨论区,WPF团队对路线的优先级发起了一次讨论. 对三个事项发起了投票. 第一个是Windows 11 主题 第二个是更新的控件 第三个是可空性注释 最终Windo ...