Android 性能测试实践(二) 实时监控工具

本文涉及的产品
性能测试 PTS,5000 VUM额度
简介:
+关注继续查看

前言

各位 这个工具是本人写的非常简陋体验也非常一般,大家手下留情,不要吐槽!能用上的拿去用吧!

源码:
https://github.com/testly/Tools

这个工具问题估计很多,写的不是很好会有很多手机不支持所以有什么问题可以联系我!我能帮助你的尽力而为!

文件地址
64位!
http://yunpan.cn/cwWLitLZt7IJa 访问密码 2be0

32位!
http://yunpan.cn/cwWL4km7GW6tQ 访问密码 ccd7

工具说明

1,一定要是Root过的Android主流的手机
2,一定要有Adb 环境 (Android Debug Bridge)如果没有的话我文件里面放了

把这个文件夹 路径放到环境变量里面去,Path下面哦
放完后check一下:

这样环境就Ok了

工具的原理

Cpu取值:

adb shell top -n 1| grep"+PackageName

在代码怎么取呢?看下面

publicstaticdoubleCpu(StringPackageName)throwsIOException{doubleCpu=0;try{Runtimeruntime=Runtime.getRuntime();Processproc=runtime.exec("adb shell top -n 1| grep "+PackageName);try{if(proc.waitFor()!=0){System.err.println("exit value = "+proc.exitValue());}BufferedReaderin=newBufferedReader(newInputStreamReader(proc.getInputStream()));StringBufferstringBuffer=newStringBuffer();Stringline=null;while((line=in.readLine())!=null){stringBuffer.append(line+" ");}Stringstr1=stringBuffer.toString();Stringstr3=str1.substring(str1.indexOf(PackageName)-43,str1.indexOf(PackageName));//System.out.println(str3);Stringcpu=str3.substring(0,4);cpu=cpu.trim();Cpu=Double.parseDouble(cpu);}catch(InterruptedExceptione){System.err.println(e);}finally{try{proc.destroy();}catch(Exceptione2){}}}catch(ExceptionStringIndexOutOfBoundsException){System.out.print("请检查设备是否连接");}returnCpu;}

内存取值:

adb shell dumpsys meminfo"+PackageName
publicstaticdoubleGetFlow(StringPackageName)throwsIOException{doublestr3=0;StringPid=PID(PackageName);try{Runtimeruntime=Runtime.getRuntime();/*   Process proc2 = runtime.exec("");*/Processproc=runtime.exec("adb shell cat /proc/"+Pid+"/net/dev");try{if(proc.waitFor()!=0){System.err.println("exit value = "+proc.exitValue());//JOptionPane.showMessageDialog(new JFrame(), "哥们抱歉,好像出问题了!关掉重试吧!");}BufferedReaderin=newBufferedReader(newInputStreamReader(proc.getInputStream()));StringBufferstringBuffer=newStringBuffer();Stringline=null;while((line=in.readLine())!=null){stringBuffer.append(line+" ");}Stringstr1=stringBuffer.toString();Stringstr2=str1.substring(str1.indexOf("wlan0:"),str1.indexOf("wlan0:")+90);//接收字节:Stringstr4=str2.substring(7,16);str4=str4.trim();intb=Integer.parseInt(str4);str3=b/1024;//System.out.println(str3);}catch(InterruptedExceptione){System.err.println(e);}finally{try{proc.destroy();}catch(Exceptione2){}}}catch(ExceptionStringIndexOutOfBoundsException){//System.out.print("请检查设备是否连接");}returnstr3;}

流量取值:

adb shell cat /proc/Pid/net/dev
publicstaticdoubleGetFlow(StringPackageName)throwsIOException{doublestr3=0;StringPid=PID(PackageName);try{Runtimeruntime=Runtime.getRuntime();/*   Process proc2 = runtime.exec("");*/Processproc=runtime.exec("adb shell cat /proc/"+Pid+"/net/dev");try{if(proc.waitFor()!=0){System.err.println("exit value = "+proc.exitValue());//JOptionPane.showMessageDialog(new JFrame(), "哥们抱歉,好像出问题了!关掉重试吧!");}BufferedReaderin=newBufferedReader(newInputStreamReader(proc.getInputStream()));StringBufferstringBuffer=newStringBuffer();Stringline=null;while((line=in.readLine())!=null){stringBuffer.append(line+" ");}Stringstr1=stringBuffer.toString();Stringstr2=str1.substring(str1.indexOf("wlan0:"),str1.indexOf("wlan0:")+90);//接收字节:Stringstr4=str2.substring(7,16);str4=str4.trim();intb=Integer.parseInt(str4);str3=b/1024;//System.out.println(str3);}catch(InterruptedExceptione){System.err.println(e);}finally{try{proc.destroy();}catch(Exceptione2){}}}catch(ExceptionStringIndexOutOfBoundsException){//System.out.print("请检查设备是否连接");}returnstr3;}

取到流量后可以用步骤后的流量减去步骤前的流量得到步骤消耗流量!也可以用时间差来计算!

电量取值:

adb shell dumpsys battery

这里只是剩余电量!

java" style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, 'Courier New', monospace; font-size: 12px; display: block; padding: 5px; margin: 0px 0px 16px; line-height: 1.42857143; color: rgb(68, 68, 68); word-break: break-all; word-wrap: break-word; border: 0px; border-radius: 0px; backgroun
相关实践学习
通过性能测试PTS对云服务器ECS进行规格选择与性能压测
本文为您介绍如何利用性能测试PTS对云服务器ECS进行规格选择与性能压测。
相关文章
|
10天前
|
Cloud Native 测试技术
性能测试小工具 wrk 可以怎么用
性能测试小工具 wrk 可以怎么用
|
3月前
|
消息中间件 监控 测试技术
消息队列和应用工具产品体系-性能测试场景和工具
消息队列和应用工具产品体系-性能测试场景和工具
54 0
消息队列和应用工具产品体系-性能测试场景和工具
|
5月前
|
监控 前端开发 测试技术
前端工程化的前端性能的性能测试/监控工具之Performance工具
Performance 工具是一个非常强大的前端性能测试工具,因为它可以在不同的设备和浏览器上测试和监控网页的性能,从而帮助开发者了解网页的实际性能表现。
240 0
|
8月前
|
数据采集 缓存 数据可视化
APP性能测试方法&工具
APP性能测试方法&工具
|
11月前
|
安全 数据处理 Android开发
Android一次完美的跨进程服务共享实践
Android一次完美的跨进程服务共享实践
116 0
Android一次完美的跨进程服务共享实践
|
XML 编译器 Android开发
山川湖海 - Android无障碍功能优化实践
本文主要分享Android无障碍功能的一些优化经验,希望看完本篇,可以帮助到你,以及哪些特殊的用户。
253 0
山川湖海 - Android无障碍功能优化实践
|
Android开发 内存技术
嵌入式实践教程--Android音视频开发(二)-OpenSLES播放PCM数据
嵌入式实践教程--Android音视频开发(二)-OpenSLES播放PCM数据
|
SQL 监控 Oracle
性能测试--性能测试概念、性能测试主流工具
一般来说,性能是一种指标,表明软件系统或构件对其及时性要求的符合程度;其次,性能是软件产品的一种特性,可以用时间来进行度量。性能的及时性用响应时间或吞吐量来衡量。响应时间是指服务器对请求作出响应所需要的时间。
231 0
性能测试--性能测试概念、性能测试主流工具
|
测试技术 编译器 Python
性能专题:Locust工具实战之创建性能测试
性能专题:Locust工具实战之创建性能测试
159 0
性能专题:Locust工具实战之创建性能测试
|
自然语言处理 监控 数据可视化
微服务性能测试的方法和工具
微服务性能测试的方法和工具
467 0
微服务性能测试的方法和工具
相关产品
云迁移中心
推荐文章
更多