关键因素: ---- Instrument 性能分析神器网络
1. 启动时间 session
应用启动时间长短对用户第一次体验相当重要,同时系统对应用的启动、恢复等状态的运行时间也有严格的要求,在应用超时的状况下系统会直接关闭应用。如下是几个常见场景下系统对app运行时间的要求: * Launch 20秒 Resume 10秒 Suspend 10秒 Quit 6秒Background Task 10分钟app
要获取准确的app启动所需时间,最简单的方法时首先在main.c中添加以下代码:async
1
2 3 |
CFAbsoluteTime StartTime; int main(int argc, char **argv) { StartTime = CFAbsoluteTimeGetCurrent(); |
而后在AppDelegate的回调方法application:didFinishLaunchingWithOptions
中添加:ide
dispatch_async(dispatch_get_main_queue(), ^{ NSLog(@”Lauched in %f seconds.”, (CFAbsoluteTimeGetCurrent() – StartTime)); });可能你会以为为何这样可拿到系统启动的时间,由于这个dispatch_async中提交的工做会在app主线程启动后的下一个run lopp中运行,此时app已经完成了载入而且将要显示第一帧画面,也就是系统会运行到`-[UIApplication _reportAppLaunchFinished]`以前。下图是用Instruments工具Time Profiler跑的调用栈,Instruments的使用方法建议看WWDC中与performance相关的[session录像](https://developer.apple.com/videos/wwdc),文字写起来太单薄不够直观哈。
2. 用户响应工具
3. 内存性能
4. 图形图画ui
5. 文件spa
6. 网络线程