iOS开发~Instruments使用(二)
来源:互联网 发布:成都宜高美 知乎 编辑:程序博客网 时间:2024/04/28 10:29
一、概要
前一篇介绍了使用Instruments来分析内存的方法及处理内存问题时候的局限性,这一篇来介绍Instruments的另一个工具Time Profiler。虽然程序内存上的问题解决了,但程序运行的还是很慢,性能很差,这时有必要查看下,是什么原因导致程序变慢的。Time Profiler可以帮你解决这个问题。
二、使用Instruments分析程序性能瓶颈
首先建立项目,添加代码:
@interface ViewController () { id aaa;}@end@implementation ViewController- (void) leakMethd{ for (int i = 0; i< 100; i++) { UIView *aView = [[[UIView alloc] init] autorelease]; }}- (void)viewDidLoad{ [super viewDidLoad]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(leakMethd) userInfo:nil repeats:YES]; aaa = [[UIView alloc] init];}
打开方式Instruments:Product -> Profiler,或者快捷键 Cmd + i,然后选择Time Profiler,然后点击Profile
可能会反应挺慢,等模拟器启动后,稍等会就会看到如下页面:
其中红色框处点击,弹出页面来设置分析的类别(这里选择Style为CPU Usage):
配置勾选蓝色框中的选项后:
这时可以看到包括私有方法的一些信息,如果为了看得更清晰,可以选择Hide System Libraries选项,这样就只会显示你自定义的方法:
上图蓝色框中显示的是耗时,红色框显示的为CPU的占用率。
同时,也可以点击具体方法,看方法中哪行代码在消耗系统资源:
关于CPU占用率建议:当你的程序工作的时候,可以消耗大量CPU资源来维持一个较高的帧率,但程序不在使用时,不应该占用大量CPU,最好是不占用而直接休眠。
注意:性能测试一定要在Release模式下进行才有意义,这样才能进行有效的优化处理,在未经过优化的Debug模式下没有意义。
0 0
- iOS开发~Instruments使用(二)
- iOS开发~Instruments使用(一)
- IOS 开发学习二十一 instruments使用 quick start
- iOS开发之性能调试Instruments(二)
- 【IOS】Instruments 使用教程
- IOS:Instruments 使用教程
- 【IOS】Instruments 使用教程 .
- 【IOS】Instruments 使用教程
- 【IOS】Instruments 使用教程
- ios Instruments 工具使用
- 【IOS】Instruments 使用教程
- IOS如何使用Instruments
- 【IOS】Instruments 使用教程
- 【IOS】Instruments 使用教程
- 【IOS】Instruments 使用教程
- 【IOS】Instruments 使用教程
- iOS-Instruments的使用
- iOS Instruments 使用教程
- Javascript 数组循环遍历之forEach
- 数据结构之线性表的顺序表示和实现
- 什么样的制氧机好用
- VS2010下生成dll的方法(更新)
- load average
- iOS开发~Instruments使用(二)
- NSFileHandle简单的读写文件
- adb shell input的用法
- UDP数据包
- visio 热身资料
- android查看已经保存的WIFI密码
- 解决表单重复提交问题
- UltraEdit使用技巧随记
- 如何学习HTML5?