A iOS APP Performance Testing Tool. 这是一款iOS性能监控工具,支持Mac以及Windows端运行,电脑通过USB连接手机后运行脚本即可。本项目基于jlintxia开源的iOS测试方案修改而来,增加动态建表,动态增加grafana面板以及docker打包环境等特性。其中iOS性能数据来源于开源工具tidevice和py-ios-device。

yanbo92, updated 🕥 2022-07-07 08:58:25

iOS-perf

READ IN ENGLISH

这是一款iOS性能监控工具,支持Mac以及Windows端运行,电脑通过USB连接手机后运行脚本即可。

当前支持获取的性能数据包括GPU、CPU、内存、FPS、功耗、网络、温度,以及一系列手机硬件数据,并将根据需求继续新增。

本项目基于jlintxia开源的iOS测试方案修改而来,增加动态建表,动态增加grafana面板以及docker打包环境等特性。其中iOS性能数据来源于开源工具tidevice和py-ios-device。

注意:本项目依赖MySQL进行性能数据存储,Grafana进行数据动态展示,也就是说需要在本机或者可达的网络(比如公司局域网) 上搭建MySQL+Grafana服务,我提供了一份docker-compose.yml文件,可以使用docker快速搭建一套环境。

效果展示

gif

准备工作

服务端搭建依赖docker以及docker-compose,安装指南:

https://dockerdocs.cn/get-docker/

https://dockerdocs.cn/get-started/08_using_compose/

运行测试依赖python3环境,安装指南:

https://www.python.org/downloads/

服务端搭建

命令行运行

docker -v && docker-compose -v

如果能正常输出版本,如下,则表示docker环境正常,可以继续

Docker version 20.10.8, build 3967b7d

docker-compose version 1.29.2, build 5becea4c

拉取镜像并启动服务:

docker-compose up -d 提示:初次打开Grafana时,系统会提示你修改密码,为了方便建议不修改,即保持账号密码均为admin,否则在python运行指令中将要进行对应的传参。

本地环境搭建

命令行执行

pip install -r requirements.txt

运行命令

命令行执行: shell python run.py --udid=00008110-001A4D483CF2801E \ --bundleid=com.apple.Preferences \ --grafana_host=localhost \ --grafana_port=30000 \ --grafana_user=admin \ --grafana_password=admin \ --mysql_host=localhost \ --mysql_port=33306 \ --mysql_username=root \ --mysql_password=admin \ --mysql_db=iOSPerformance

运行参数说明

建议修改参数

  • --bundleid:待测APP的包名,通过ideviceinstaller -l获取,默认值为com.apple.Preferences
  • --udid iPhone:手机的唯一标识符,通过 idevice_id -l 获取,客户端只连接一台手机时不用写

Grafana可选参数

  • --grafana_host:Grafana的主机地址,只写ip,不用写Scheme,也就是http://或者https//,默认值localhost
  • --grafana_port:Grafana的端口号,默认值30000
  • --grafana_user:Grafana的用户名,默认值admin
  • --grafana_password:Grafana的密码,默认值admin

MySQL可选参数

  • --mysql_host:MySQL的主机地址,不用写Scheme,也就是http://或者https//,默认值localhost
  • --mysql_port:MySQL的端口号,默认值33306
  • --mysql_user:MySQL的用户名,默认值root
  • --mysql_password:MySQL的密码,默认值admin

数据导出

命令行执行: shell python mysql.py --runid=iphone6_1008_1532 \ --mysql_host=localhost \ --mysql_port=33306 \ --mysql_username=root \ --mysql_password=admin \ --mysql_db=iOSPerformance

其中,--runid为必须参数,可以从显示测试数据的Grafana页面的左上角找到,通常为手机名称+月日+时分。其余Mysql参数均为可选参数,默认值与上方MySQL可选参数相同。

Issues

获取网络信息时报错

opened on 2023-03-21 07:13:43 by Sanmejie

MarketName: iPhone11

ProductVersion: 16.1.1

ProductType: iPhone12,1

网络打印 {'connection-detected': {'Local': '[fe80::b098:98ff:fe21:d2af]:58783', 'Remote': '[fe80::b098:98ff:fe21:d250]:64661', 'InterfaceIndex': 14, 'Pid': -2, 'RecvBufferSize': 131072, 'RecvBufferUsed': 0, 'SerialNumber': 99, 'Protocol': 'tcp6'}, 'timestamp': 1679382560416} Exception in thread perf: Traceback (most recent call last): File "/opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 1016, in _bootstrap_inner self.run() File "/opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 953, in run self._target(self._args, *self._kwargs) File "/Users/test/sonic/watch_dog/venv/lib/python3.10/site-packages/tidevice/_perf.py", line 281, in append_data callback(_type, data) File "/Users/test/sonic/watch_dog/ios/iOS-perf/run.py", line 125, in callback downFlow = value['downFlow'] KeyError: 'downFlow' DataType.SCREENSHOT {'value': , 'timestamp': 1679382561157} DataType.FPS {'fps': 60, 'value': 60, 'timestamp': 1679382561418}

偶尔出现 pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([Errno 8] nodename nor servname provided, or not known)")

opened on 2023-02-16 08:33:30 by KJC1999

@yanbo92 大佬,我在执行你这份代码的时候,偶尔就会在插入数据的时候触发这个异常,并且后续就不会继续获取相关的数据,请问你有遇到过吗 比如在insert_cpu函数中,一旦在数据库连接过程中出现这个,那后续就不会去获取cpu数据,整个线程就崩掉的,我应该怎么写兜底机制,或者有办法规避这个异常吗

It's great to integrate the functions of Android into this framework!

opened on 2022-08-02 16:32:16 by LRF520

You should integrate the functions of Android into this framework, so that everyone can test the performance data of IOS and Android at the same time, which is really great!

It doesn't work on the secondary process

opened on 2022-07-17 10:42:00 by LRF520

It just works on the main process, it doesn't work on the secondary process(subprocess), just like Wechat applet,maybe all of the data about the secondary process is wrong . so many apps have the secondary process now, it's better to support secondary process, it's better to show the total data of phone,so that we can avoid fatal mistakes.

运行run.py报错

opened on 2022-03-29 10:42:34 by kangleblue

D:\iOS-perf-master>python3 run.py --udid=38022be6377c4b10a6dfcb2d74a04832199230f2 --bundleid=com.pgdl Parameters list: udid 38022be6377c4b10a6dfcb2d74a04832199230f2 bundleid com.pgdl grafana_host localhost mysql_host localhost grafana_port 30000 mysql_port 33306 grafana_username admin mysql_username root grafana_password admin mysql_password admin mysql_db iOSPerformance runid export 0 Error Info: (1050, "Table 'TEMP' already exists") Maybe this database dont need initializing, just ignore the error Traceback (most recent call last): File "run.py", line 97, in start_test pid = t.app_start(app_bundle_id) File "D:\Python\Python38\lib\site-packages\tidevice_device.py", line 653, in app_start instruments = self.connect_instruments() File "D:\Python\Python38\lib\site-packages\tidevice_device.py", line 781, in connect_instruments conn = self.start_service(LockdownService.InstrumentsRemoteServer) File "D:\Python\Python38\lib\site-packages\tidevice_device.py", line 448, in start_service return self._unsafe_start_service(name) File "D:\Python\Python38\lib\site-packages\tidevice_device.py", line 477, in _unsafe_start_service conn = self.create_inner_connection(data['Port'], _ssl=_ssl) File "D:\Python\Python38\lib\site-packages\tidevice_device.py", line 288, in create_inner_connection self._usbmux._check(data) File "D:\Python\Python38\lib\site-packages\tidevice_usbmux.py", line 94, in _check raise MuxReplyError(data['Number']) tidevice.exceptions.MuxReplyError: UsbmuxReplyCode.ConnectionRefused

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "run.py", line 230, in start_test() File "run.py", line 99, in start_test pid = get_pid(app_bundle_id) File "run.py", line 80, in get_pid app_infos = list(t.instruments.app_list()) File "D:\Python\Python38\lib\site-packages\tidevice_device.py", line 789, in instruments return self.connect_instruments() File "D:\Python\Python38\lib\site-packages\tidevice_device.py", line 781, in connect_instruments conn = self.start_service(LockdownService.InstrumentsRemoteServer) File "D:\Python\Python38\lib\site-packages\tidevice_device.py", line 448, in start_service return self._unsafe_start_service(name) File "D:\Python\Python38\lib\site-packages\tidevice_device.py", line 477, in _unsafe_start_service conn = self.create_inner_connection(data['Port'], _ssl=_ssl) File "D:\Python\Python38\lib\site-packages\tidevice_device.py", line 288, in create_inner_connection self._usbmux._check(data) File "D:\Python\Python38\lib\site-packages\tidevice_usbmux.py", line 94, in _check raise MuxReplyError(data['Number']) tidevice.exceptions.MuxReplyError: UsbmuxReplyCode.ConnectionRefused

大佬求助,导出时报错 而且运行时Grafana里面USE_CPU一直显示0,battery显示no data

opened on 2022-02-23 11:47:39 by Luftmenschh

E:\software\iOS-perf-master\iOS-perf-master>python mysql.py --runid=iPhone13Pro_0223_1741 --mysql_host=localhost --mysql_port=33306 --mysql_username=root --mysql_password=admin --mysql_db=iOSPerformance Parameters list: mysql_host localhost mysql_port 33306 mysql_username root mysql_password admin mysql_db iOSPerformance runid iPhone13Pro_0223_1741 Error Info: (1050, "Table 'TEMP' already exists") Maybe this database dont need initializing, just ignore the error Traceback (most recent call last): File "mysql.py", line 207, in mysql.export() File "mysql.py", line 156, in export cursor.scroll(0, mode='absolute') File "E:\software\anancoda\lib\site-packages\pymysql\cursors.py", line 303, in scroll raise IndexError("out of range") IndexError: out of range

20220223-194652

docker-compose python3 ios testing performance grafana