iOS test - how power consumption and performance indicators to quantify app XCTest Metrics

      For special test app side, Android end we can use adb or some party tools (such as itest) for real-time performance monitoring, iOS end, then you can use a number of tripartite tool, but it needs to be embedded into our project which, today apple under Xcode11 introduced to provide a new framework based on the app XCTest power consumption and performance.

Source: https://developer.apple.com/videos/play/wwdc2019/417/

app power consumption

  app consumption and its performance reflects are closely related, then the app in which items will affect the performance of the power consumption of it?

  • CPU
  • memory
  • storage
  • clock and OSSignpost
  • custom Metrics
  • network
  • Wi-Fi
  • Bluetooth
  • Location

 

IOS end of performance tuning tools

1. Xcode

  Xcode itself comes with a number of tools to monitor performance, for example, there is Debug Navigator in Xcode navigation area, we can see the situation the application of cpu, memory, disk, network as well as power consumption, the test the process can be monitored in real time, if the value of certain functional tests found abnormal, it can be reused Instruments depth study to test.

 

 

2. Instruments

  Instruments provides a number of basic templates, special test can be done in many ways by these templates, marked as the following figure is relatively common, specialized follow-up will write the next chapter describes blog can be a performance point for the following template test, can navigate to the code level may be where the problem.

 

 

XCTest in performance tests

  XCTest is iOS end unit testing framework, also introduced before, except it can do some unit tests and UI testing, in fact, can do a little performance testing. For example, FIG:

 

 

  Measure the increase in the code block to verify the performance of the code block, but few indicators and are fixed.

Xcode11 latest performance test

  现在,我们只需在调用 measure 时增加想要监测的指标作为参数,就可以从多个维度监测代码块的性能表现,十分简单

  

   

  而检测应用启动耗时,更是容易。不需要任何代码,创建 XCTest 的时候就已经自动生成:

 

 

  如果设置基准线(baseline),那么每次运行测试时,Xcode 都会自动对比 我们设定的基准线,如果启动耗时高于基准线,那么测试就不通过。

如何做性能测试

  苹果为我们提供了这些工具,如何真正的落地到项目中呢?我来分享下我们的做法。

  我们需要充分利用这些工具:

  - 在测试阶段,在进行功能测试的同时,需要关注Debug Navigator,但是不用太刻意,因为大多数的性能问题是在明显的用户感知下暴露的,而不是脱离用户的体验而定的性能的指标标准。

  - 当我们发现有可能存在性能问题,我们需要使用instruments工具对某一性能进行专项的测试,查看性能瓶颈问题出在哪个地方。

  - 我们对于可能会有性能问题,或者我们app中用户比较敏感的功能,都在XCTest中做单元测试,并使用measure进行性能测试。

 

性能指标的确立

  那么如何建立性能指标呢?指标或者量化的东西才能真正的说明问题,也才能让开发去进行优化修改。

  我们有以下两种方式来建立性能指标

  1. 竞品分析,对于与竞品中重叠的功能或公共指标(启动时间,加载时间等)进行性能指标分析,确立一个自己app指标

  2. follow first feeling,有些可能是本身app独有的或者没有竞品做对比的,我们如何确立性能指标呢?我们使用follow first feeling原则。怎么理解,测试在测试过程中发现有明显的性能问题或者产品在验收中发现有性能问题,例如页面加载慢,视频缓存速度慢,我们需要与开发形成共识,在第一时间进行判断是否需要进行性能调优,一旦通过测试或者产品验收,我们通过跑measure确认第一次的性能指标为标准指标,再次进行版本更迭测试的时候不能低于第一次的指标。类似于做a/b测试。

  

  我认为像app产品,如果有竞品还好,没有竞品是比较难做一些专项或性能相关的测试,app如果不是很大,功能不是很多,现在主流的机型都可以很顺畅的跑这些app。如果这样的app有一些性能问题,大多数都可以算作是开发bug,在对页面渲染啊,数据加载啊,线程处理啊上处理不当造成的,而这些问题如果细心一点或者关注debug navaigator都可以第一时间排查出来。而我们对于这种app指标的确立follow第一感觉就可以了,测试也是用户,为用户把好第一道关,往后的版本只能越做越好,而不能比第一感觉还差,这样的话对于用户体验,或者对于app的性能也能把好质量了。

 

  后续也会针对wwdc中的其它两项做介绍。

 

Guess you like

Origin www.cnblogs.com/dreamyu/p/11769003.html