主要是进行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. 7.14考试总结(NOIP模拟15)[夜莺与玫瑰·影子·玫瑰花精]

    梦总是有会醒来的时候,不会醒的梦总有一天会变成悲伤. 前言 这次考试的思维含量有一点大(此时距离考试还有 7min 而我的总结还没写完..) 但是对于以前的考试来讲还是有所进步的,毕竟在考试的时候还是 ...

  2. Matlab打印运行进度

      在运行matlab程序的过程中,有时候需要实时地掌握程序运行的进度,尤其对于一些耗时较长的循环操作,能够及时地输出运行进度,显得非常有必要.   打印进度条的实现方式就是不断地退格.输出.   退 ...

  3. Easysearch:语义搜索、知识图和向量数据库概述

    什么是语义搜索? 语义搜索是一种使用自然语言处理算法来理解单词和短语的含义和上下文以提供更准确的搜索结果的搜索技术.旨在更好地理解用户的意图和查询内容,而不仅仅是根据关键词匹配,还通过分析查询的语义和 ...

  4. filebeat实战

    1.打开filebeat支持nginx模块 [root@es-node1 /etc/filebeat]#ls fields.yml filebeat.reference.yml filebeat.ym ...

  5. vue动态页签

    效果图 前端 1 <template> 2 <!-- 总体情况 - 总览echarts --> 3 4 <div v-loading="loading" ...

  6. vitepress 如何更换 favicon.ico

    favicon.ico 它出现在浏览器标签页上,是网站的标识之一. 准备图标 首先,你需要准备一个符合您要求的图标.通常,favicon.ico 使用的是 .ico 格式的图标文件,大小为 16x16 ...

  7. 【IEEE 出版】 第三届能源与电力系统国际学术会议 (ICEEPS 2024)

    [连续2届会后4-5个月EI检索,检索稳定!特邀院士.Fellow 报告!]第三届能源与电力系统国际学术会议 (ICEEPS 2024)以"创造更加柔性.智能的能源电力系统"为主题 ...

  8. ansible(1)---师傅领进门

    背景 在企业里,运维需要配合开发进行产品上架,说白了就是把写好的代码上服务器.那么,就会出现这样的问题:需要运维人员配置好系统,配置好环境,配置好网络,配置好程序,配置好所有所有的依赖环境.     ...

  9. bs4解析-优美图库

    import requests from bs4 import BeautifulSoup url = 'http://www.umeituku.com/bizhitupian/meinvbizhi/ ...

  10. k8s livenessprobe和readinessprobe详解

    一.为什么需要容器探针 如何保持Pod健康 只要将pod调度到某个节点,Kubelet就会运行pod的容器,如果该pod的容器有一个或者所有的都终止运行(容器的主进程崩溃),Kubelet将重启容器, ...