iOS开发iOS乱炖iOS 优化

iOS instruments介绍

2016-03-30  本文已影响2621人  game3108

iOS instruments介绍

本文csdn地址:http://blog.csdn.net/game3108/article/details/51147909
写代码的时候,我们时常需要借助一些工具来帮我们分析问题、找到问题,来达到调适和优化代码的目的。在iOS开发方面,XCode提供了一系列工具来帮助我们解决问题,这就是instruments。

苹果文档这么介绍instruments:

Instruments is a powerful and flexible performance-analysis and testing tool that’s part of the Xcode tool set. It’s designed to help you profile your OS X and iOS apps, processes, and devices in order to better understand and optimize their behavior and performance. Incorporating Instruments into your workflow from the beginning of the app development process can save you time later by helping you find issues early in the development cycle.

本文主要介绍一下instruments,和其中几个常用的工具。

界面介绍

instruments工作流程图:


其中调试最主要的以下几个选项:

以下参考参考链接2:

比较重要的:

显示出被混合的图层Blended Layer(用红色标注),Blended Layer是因为这些Layer是透明的(Transparent),系统在渲染这些view时需要将该view和下层view混合(Blend)后才能计算出该像素点的实际颜色。所以红色越少越好

很多视图Layer由于Shadow、Mask和Gradient等原因渲染很高,因此UIKit提供了API用于缓存这些Layer:[layer setShouldRasterize:YES],系统会将这些Layer缓存成Bitmap位图供渲染使用,如果失效时便丢弃这些Bitmap重新生成。所以绿色越多,红色越少越好

Offscreen-Rendering离屏渲染意思是iOS要显示一个视图时,需要先在后台用CPU计算出视图的Bitmap,再交给GPU做Onscreen-Rendering显示在屏幕上,因为显示一个视图需要两次计算,所以这种Offscreen-Rendering会导致app的图形性能下降。所以黄色越少越好。

次要的:

Misaligned Image表示要绘制的点无法直接映射到频幕上的像素点,此时系统需要对相邻的像素点做anti-aliasing反锯齿计算,增加了图形负担,通常这种问题出在对某些View的Frame重新计算和设置时产生的。

对图形性能的分析意义较小,通常仅作为参考。

Timer Profiler

The Time Profiler instrument captures stack trace information at prescribed intervals. It can record information from a single process or from all processes running on the system.

对于Call Tree的设置参数解释:

以下参考参考链接4:

其中可以看到每一个方法的调用时间

双击相应方法,可以看到整个的运行时间:


Leaks

The Leaks instrument captures information about leaked memory. It can record information from a single process only.

Leaks那行出现的红色标签代表着有内存泄漏。
先在左上角暂停一下程序运行,切换详情的Leaks到Call Tree,
并且在设置界面勾选上"invert Call Tree"和"Hide System Libraries",就可以在看到相应的调用函数:

双击相关函数,就可以跳转到对应出问题的代码,进行修改:

参考链接

1.iOS developer library: Instruments User Guide
2.iOS App的性能关注点:iOS App的性能关注点
3.Designing for iOS: Graphics & Performance:Designing for iOS: Graphics & Performance
4.iOS系类教程之用instruments来检验你的app:iOS系类教程之用instruments来检验你的app
5.Instruments Tutorial with Swift: Getting Started:Instruments Tutorial with Swift: Getting Started

上一篇 下一篇

猜你喜欢

热点阅读