当前位置:网站首页>APP冷热启动专项测试
APP冷热启动专项测试
2022-06-28 13:18:00 【软件测试小小白】
一、冷热启动的概念
冷启动:当启动应用时,后台没有该应用的进程,这时系统会重新创建一个新的进程分配给该应用,这个启动方式就是冷启动。
热启动:当启动应用时,后台已有该应用的进程(例:按back键、home键,应用虽然会退出,但是该应用的进程是依然会保留在后台,可进入任务列表查看),所以在已有进程的情况下,这种启动会从已有的进程中来启动应用,这个启动方式就是热启动。
二、核心原理
APP启动时长,可以通过adb shell am start -W命令的TotalTime得到。
adb shell am start -W -n 包名/Activity名

ThisTime 该activity启动耗时
TotalTime 应用自身启动耗时=ThisTime+应用application等资源启动时间
WaitTime 系统启动应用耗时=TotalTime+系统资源启动时间
三、脚本化
import time
import os
def StartApp():
cmd="adb shell am start -W -n com.weitian.oa/.IndexActivity"
result=os.popen(cmd)
return result
def StopApp(mode):
if mode == 'hot':
cmd = "adb shell input keyevent 3"
result=os.popen(cmd)
if mode=='cold':
cmd="adb shell am force-stop com.weitian.oa"
os.popen(cmd)
def GetStartTime(result,count):
for one in result.read().splitlines():
if'TotalTime' in one:
one=one.split(":")[1]
one=one.strip()
one=int(one)
print(f"第{count}次启动{one}毫秒")
return one
if __name__ == "__main__":
mod=input("冷热启动测试,请输入模式:hot 热启动测试,cold 冷启动测试")
count=int(input("请输入测试次数"))
if mod=='hot':
input("热启动测试,请确保app已经打开并退到后台\n回车继续...")
if mod=='cold':
input("冷启动测试,请确保app没有打开\n回车继续...")
time_list = []
for i in range(count):
result=StartApp()
time_list.append(GetStartTime(result, i + 1))
time.sleep(3)
StopApp(mod)
time.sleep(3)
else:
print(f"平均启动时间{sum(time_list)/count}毫秒")

福利

边栏推荐
- 2022年中国运维安全产品市场规模及发展趋势预测分析
- 1015. picking flowers
- Vscode如何设置代码保存后自动格式化
- Centos7 - installing mysql5.7
- 同花顺上怎么进行开户啊, 安全吗
- pytorch模型调参、训练相关内容
- 恒生电子:金融分布式数据库LightDB通过中国信通院多项测评
- RK3399平台开发系列讲解(使用篇)Pinctrl子系统的介绍 - 视频介绍
- Tencent has confirmed that QQ has stolen numbers on a large scale, iphone14 has no chance of type-C, and 5g, the fourth largest operator, has officially released numbers. Today, more big news is here
- Tencent tangdaosheng: facing the new world of digital and real integration, developers are the most important "architects"
猜你喜欢

The counter attack story of Fu Jie, a young secondary school student: I spent 20 years from the second undergraduate to the ICLR outstanding Thesis Award

China Database Technology Conference (DTCC) specially invited experts from Kelan sundb database to share

Elastic box auto wrap demo

Solution to directory access of thinkphp6 multi-level controller

Arduino-ESP32闪存文件插件程序搭建和上传

移动Web实训DAY-2

StackOverflow 2022数据库年度调查

SHAREit實力出眾,登陸全球 IAP 實力榜 Top7

单元测试 CI/CD

Why do more and more users give up swagger and choose apifox
随机推荐
Google Earth engine (GEE) - Global organic soil area of FAO (1992-2018)
mysql数据库扫盲,你真的知道什么是数据库嘛
(original) [Maui] realize "floating action button" step by step
投资98万美元的Saas项目失败了
Matlab plotyy coordinate axis setting, [reprint] example of MATLAB plotyy drawing double ordinate graph [easy to understand]
Implementation of fruit and vegetable mall management system based on SSM
pytorch模型
How to find opportunities in a bear market?
Align content attribute in flex layout
移动Web实训DAY-1
Online JSON to plaintext tool
Flutter series part: detailed explanation of GridView layout commonly used in flutter
After failing in the college entrance examination, he entered Harbin Institute of technology, but stayed in the university after graduation to be an "Explorer". Ding Xiao: scientific research is accum
为什么越来越多的用户放弃 Swagger,选择Apifox
MySQL多表联合查询
Vscode如何设置代码保存后自动格式化
哈希竞猜游戏系统开发技术成熟案例及源码
SHAREit實力出眾,登陸全球 IAP 實力榜 Top7
4年用户数破亿,孙哥带领波场再创新高
Centos6.5 php+mysql MySQL library not found