iOS performance testing method - get mobile phone memory data

Recently, I have been studying how to obtain iOS mobile phone performance data (mainly memory), and after looking around, there are mainly two mainstream methods: 1. Tidevice, an open-source iOS automated testing tool from Ali; 2. Instruments that comes with xcode;

1. Mobile terminal performance indicators

1.cpu

Normally, it is around 20%-40%, and more than 80% needs attention.

2. Memory

rss: private memory + all shared memory, pss: private memory + proportional allocation of shared memory, generally vss>=rss>=pss>=uss;

It is necessary to pay attention to whether the memory drops after exiting a page; whether the memory grows too fast after a certain operation is performed.

3.fps

It is more reasonable between 30-60. If it is lower than 30, there will be obvious lag. If it is higher than 70, it will not be perceived, and it will waste the graphics processor capacity.

4. Power consumption

Before the test, check the power consumption of the mobile phone in normal standby (standby after restart) within the specified time. Then start the APP to be tested to see how much the power consumption has increased and take the difference.

5.crash

<0.03% means excellent, <0.1% means good.

6. Startup time

7. Traffic

8.gpu over-rendering

Two, tidevice 

tidevice is an open-source iOS automated testing tool by Ali, which can provide screenshots, obtain mobile phone information, install and uninstall ipa packages, start and stop applications according to bundleID, obtain specified application performance data, simulate xcode to run xctest and other functions; taobao-iphone-device/README.md at main alibaba/taobao-iphone-device GitHub

install tidevice

pip3 install -U "tidevice[openssl]"

tidevice can use the command line or python script to obtain performance data.

1. Command line mode:

tidevice applist

Get the bundle id of the ipa file

view performance data

tidevice perf -B bundleID

The output data format is as follows, and the acquisition time uses the timestamp format.

fps {'fps': 46, 'value': 46, 'timestamp': 1655023837471}
gpu {'device': 22, 'renderer': 20, 'tiler': 22, 'value': 22, 'timestamp': 1655023837572}
cpu {'timestamp': 1655023837647, 'pid': 2734, 'value': 0.6984475878545683, 'sys_value': 83.33333333333331, 'count': 2}
memory {'pid': 979, 'timestamp': 1655023837647, 'value': 148.61046600341797}
network {'timestamp': 1655023837613, 'downFlow': 78.1064453125, 'upFlow': 0.7294921875}

2.python script method

import time
import tidevice
from tidevice._perf import DataType

t = tidevice.Device()
# perf = tidevice.Performance(t,[DataType.CPU, DataType.MEMORY, DataType.NETWORK, DataType.FPS, DataType.PAGE, DataType.SCREENSHOT, DataType.GPU])
perf = tidevice.Performance(t,DataType.MEMORY)

def callback(_type:tidevice.DataType,value:dict):
    print(_type.value,value)

perf.start('com.meituan.imerchantbiz.ep',callback = callback)
time.sleep(60)
perf.stop()


Real-time performance collection reports can be automatically generated with pyecharts. 

Install pyecharts

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ pyecharts
#绘图
x = [i for i in range(len(d))]
y = d
print(x)
print(y)

#创建对象,可以添加一些参数
line = Line(init_opts=options.InitOpts(width='800px',height='600px'))
#添加x轴y轴数据,注意添加y轴数据的时候必须设置series_name参数,表示图例的名称
line.add_xaxis(xaxis_data=x)
line.add_yaxis(series_name='memory', y_axis=y, is_symbol_show=True, label_opts=options.LabelOpts(is_show=False),
               #is_symbol_show=True显示点,label_opts=opts.LabelOpts(is_show=False)不显示值
               #设置展示最大值最小值
                markpoint_opts=options.MarkPointOpts(
                    data=[
                        options.MarkPointItem(type_="max",name="最大值", symbol="pin", symbol_size=[70,50]),
                        options.MarkPointItem(type_="min", name="最小值",symbol="pin", symbol_size=[70,50], itemstyle_opts={'color':'#3CB371'}),
                    ]
                ),
                #设置展示平均值
                markline_opts=options.MarkLineOpts(
                    data=[options.MarkLineItem(type_="average",name="平均值")]
                ))
line.render()
os.system('open render.html')

Effect example: You can see the maximum value, minimum value, and average value; move the mouse to a certain point, and you can see the value of that point.

  

 3. Problems encountered

(1) An error occurs: tideevice.exceptions.MuxError: ImageMountFailed

Solution: It may be because there is no device support, download the corresponding version of developer, and then reinstall wda with xcode

(2) An error occurs: sh: ./render.html: Permission denied

Solution: This is because there is no read and write permission assigned to the program, chmod 755 render.html

(3)报错:./render.html: line 1: syntax error near unexpected token `newline'

Not resolved yet, first change to open render.html;

三、xcode-instruments

1. Get memory data-leaks

xcode-open developer tool-打开instruments;

open leaks;

 Select the device under test and the application under test;  click Start, the project will run, and then you can observe;

When a red x appears, it means there is a memory leak;

Select the red x, find the leaks-call tree, find the call tree at the bottom, select invert call tree, hede system libraries, and then the class and leaked method will be displayed. Double-click to view the details to start modifying.

Invert Call Tree means to invert the call tree , which means that when we call a function, it is layer by layer. Calling the outer function will always enter the inner layer until the last layer, which is a bit recursive. When the Invert Call Tree option is selected, the inner function will be displayed directly, which is convenient for us to find. Reverse output call tree. Displaying the method with the deepest call level at the top makes it easier to find the most time-consuming operations.

Hide System Libraries: Hide system library files. Filter out various system calls and only display your own code calls. 

出现报错:Instruments could not acquire the necessary privileges to profile the target application.

Guess you like

Origin blog.csdn.net/Vermouth_00/article/details/130856490