Instruments 使用指南阅读笔记

其他开发者使用Instrument分析得到的关于性能优化的建议:

NSDateFormatter/NSCalendar

使用懒加载的形式,用到的时候再创建,避免重复创建。

针对NSDateFormatter时间开销出了重用对象外,尽量避免采用其处理多个日期格式.当然针对日期格式处理如果需要提高更多速度,可以直接采用C,可以采用第三方库来规避这个问题..

UIImage缓存取舍

A:imagedNamed初始化-自动缓存到内存

B:imageWithContentsOfFile初始化-不会缓存

主线程处理I/O

在System Trace里面突然发现了CPU Time很低,但Wait Time很高的调用,说明在主线程处理I/O已经严重损害了app的性能,这个时候考虑把这个操作优化了.

viewWillAppear

针对单个view 尽量不要在viewWillAppear费时的操作,viewWillAppear在 view 显示之前被调用,出于效率考虑,在这个方法中不要处理复杂费时的事情

Instruments 的开启方式

1. 在应用程序文件夹选择Xcode,我电脑的路径如下: /Applications/Xcode.app/Contents/Applications ,找到Instruments开启。
2.运行Xcode,点击菜单栏:product/build for/profile。
3.open /Applications/Xcode.app/Contents/Applications/Instruments.app

根据界面提供的模版,创建一个跟踪文档

终端使用Instruments

➜  ~ instruments
instruments, version 8.0 (61187)
usage: instruments [-t template] [-D document] [-l timeLimit] [-i #] [-w device] [[-p pid] | [application [-e variable value] [argument ...]]]

例子

instruments -t "Allocations" -D ~/Desktop/
.trace 

使用iprofiler to measure an app’s performance without launching Instrument

➜  ~ iprofiler
iprofiler error: No instrument chosen
iprofiler, version 8.0 (61187)
Usage: iprofiler [-l] [-L] [-legacy] [-T duration] [-I interval] [-window period] [-d path] [-o basename] [-timestamp] [-activitymonitor] [-allocations] [-counters] [-leaks] [-systemtrace] [-timeprofiler] [-kernelstacks | -userandkernelstacks] [-allthreadstates] [-pmc PMC_MNEMONIC] [-listpmcs] [-a process/pid | executable [args...]]
	Refer to the man page for detailed information about each option.
➜  ~ 

例子

iprofiler -activitymonitor -T 5s -d ~/Desktop/ 

iprofiler -timeprofiler -activitymonitor

iprofiler -T 8s -d /temp -o YourApp_perf -	timeprofiler -a YourApp

iprofiler -T 2500ms -o YourApp_perf -leaks -activitymonitor -a 823

iprofiler -d /tmp -timeprofiler -allocations -a YourApp.app

iprofiler -T 15 -I 1000ms -window 2s -o YourApp_perf -timeprofiler -systemtrace /path/to/Your.app arg1

Timeline Pane

关联dsym

Measure CPU Use

最近的文章

MV(X)或者VIPER模式

MV(X)是在MVC、MVVM、MVP三种模式的集合。MVP 是指passive View、presenter、Model三大块组成的设计方案。VIPER 是指有View、Interactor、Presenter、Entity、Router 组成的开发模式划分。…

继续阅读
更早的文章

appium的使用

AppUI自动化实质:发送指令获取元素,计算元素坐标,自动化驱动程序根据指令对元素进行操作。了解个平台的自动化驱动框架,挑选一款成熟,合适的框架,学习API的使用。基础准备:adbUIAutomatorWebDriverAgentInstrumentsiOS自带的单元测试常见的UI自动化测试工具:Appium:多平台,支持多语言,开源,学习资料全Macaca:多平台,支持JS/Python,半开源MonkeyTalk:缺点是收费AppiumAppium不是一个自动化驱动程序,它是一个ser...…

继续阅读