Instruments User Guide编程指南2-Common Tasks

本指南详细介绍了如何打开Instruments并开始使用File > Open功能,帮助开发者进行高效的应用程序性能分析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Launch Instruments 

Instruments app在Xcode app的内部,所以最直接的方式启动Instruments就是从Xcode中启动,当然也可以间接通过 Dock, Launchpad,  command line等工具启动。

Launch Instruments from Xcode

1:Open Xcode. 
2:Choose Xcode > Open Developer Tool > Instruments.


建议:也能够使用该方式启动更多有用的开发工具

To profile an opened Xcode project 

1:Launch Xcode and open your project.
2:Do one of the following:  
      1)Choose Product > Profile.


2) Click and hold the Run button in the Xcode toolbar and choose Profile.


3)Press Command-I. 

Xcode创建工程,启动 Instruments,提示选择性能分析模板(profiling template)。如果需要使用相同的模板定期分析自己的APP,我们能够设置Xcode工程自动使用该模板,无论什么时候使用性能分析。

To set up an Xcode project to use a specific Instruments profiling template 建立Xcode工程使用具体的分析模板

1:Launch Xcode and open your project.
2:Choose Product > Scheme > Edit Scheme.


Or, from the Scheme pop-up menu in the Xcode toolbar, choose Edit Scheme.


Or, press Command–Less Than (<).The scheme editor dialog appears.


3:Click Profile in the sidebar of the scheme editor dialog. 点击编辑对话框中的Profile


4:Under Info, click the Instrument pop-up menu and choose the desired profiling template. 在Info下面,点击Instrument将弹出选择性能模板列表


如果选择Ask on Launch,当启动的时候,Instruments 将显示性能分析模板选择对话框。

5:Click Close. 点击关闭 
6:Initiate profiling. See To profile an opened Xcode project.  开始性能分析,就是之前进行Podfile步骤

Launch Instruments from the Dock    使用Dock启动Instruments

To launch Instruments from the Xcode icon in the Dock   使用Dock中的Xcode启动Instruments

1:Open Xcode.
2:Control-click the Xcode icon in the Dock, and then choose Options > Open Developer Tool > Instruments from the shortcut menu.


也可以将 Instruments添加到Dock上,这是最快速的方式启动Instruments。

To permanently add Instruments to your Dock 永久显示Instruments在Dock上

1:Open Xcode.
2:Choose Xcode > Open Developer Tool > Instruments.


Instruments launches and its icon appears in your Dock.  Instruments启动之后,Instruments的图标将显示在Dock中


3:Control-click the Instruments icon in the Dock, and then choose Options > Keep in Dock from the shortcut menu. 

系统为英文:


系统中文:


Launch Instruments from Launchpad

Launchpad 自动显示APP在应用的目录中,因为Instruments 并不在应用目录中,所以并不会显示在Launchpad中。但是,我们可以添加Instruments到应用的目录,通过使用别名。

To add Instruments to Launchpad

1:Open Xcode.
2:Choose Xcode > Open Developer Tool > Instruments.


3:Control-click the Instruments icon in the Dock, and then choose Options > Show in Finder from the shortcut menu.


4:Option-Command-drag the Instruments app icon in the Finder to your Applications folder.  An alias of Instruments is created and added to your Applications folder.
 按住option + command 并拖动到应用目录下,我们就可以看到Instruments被创建了一个别名显示在应用目录中。

5: Remove the alias suffix from the filename of the Instruments alias.Instruments now appears in Launchpad.


Launch Instruments from the Command Line

使用命令行启动Instruments,能够使用终端下的open命令来启动OS X 中任意APP

To launch Instruments using the open command line tool

1:Launch Terminal (in /Applications/Utilities/).
2:Run the following command:
   open /Applications/Xcode.app/Contents/Applications/Instruments.app。

Getting Around Instruments  

Instruments有几个关键的窗口和对话框

Profiling Template Selection Dialog 性能分析选择

Instruments启动,我们将可以看到一个对话框,包含一系列预先配置的性能分析模板,对话框中包含了一些标准的模板和我们创建的自定义模板,如下图:

Figure 5-1The profiling template selection dialog



性能分析模板包含以下基本部分:

Target device list: Click this to select the device on which you wish to profile. 点击选择我们想进行分析的设备

Target process list: Click this to select the process or processes to profile. 点击选择程序进行分析

Filter buttons: Click these to filter down the list of templates to display just the standard templates, custom templates, or recently used templates. 点击按钮过滤模板列表,调节标准模板,自定义模板,近期使用模板

Search field: Enter some text to quickly find the template you need. This searches template titles and descriptions. 输入模板title、描述,快速搜索需要的模板

Template list: The list of profiling templates, which may be filtered if you clicked a filter button or entered search criteria.  列举分析模板

Template description: A short description of the currently selected profiling template, which can be helpful for determining whether the selected template meets your needs. 简单的描述我们当前选中的模板,能够帮助我们确定是否选中模板是我们所需要的

Choose button: Click this to create a new profile document, based on the currently selected template.
This button changes to Profile when you press the Option key. Click the Profile button to create a new document based on the currently selected template and immediately begin profiling the target process.  基于当前选中的模板,点击创建一个新的性能分析文件。当我们按钮Option建的时候,该按钮将title变为Profile,点击Profile将立马自动开始分析目标程序。

Open button: Click this to open a previously saved profile document, rather than starting with a fresh template. 点击打开之前存储的profile文件,而不是开始一个新的模板

Cancel button: Click this to close the template selection dialog. 关闭选择框

建议:我们可以在使用Instruments情况下,通过选择 File > New (or pressing Command-N).在任意时间显示性能分析模板

Trace Document 跟踪文件或轨迹记录

trace document(Figure 5-2)被用于组织和配置instruments来进行分析,初始化数据集合,view和分析结果。通过启动Instruments并且选择性能分析模板(profiling template)将创建一个新的 trace document,也可以通过Xcode,Dock,Command Lin来初始化Profile.我们也可以保存并重新打开已经配置过的instruments中的trace document,在trace document中包含了许多的详情信息,这些信息可以通过相关的模板和区域显示出来。

Figure 5-2 The trace document


Toolbar 工具栏
工具栏中允许我们开始(start),暂停(pause),停止数据分析,添加 instruments,隐藏和显示模板和更多相关操作。

Figure 5-3 The trace document toolbar



工具栏包括以下主要部分:

Profiling controls: Allow you to record, pause, and stop data collection 允许进行录制,暂停,停止数据的收集

Target device list: Allows you to select the device on which you wish to profile. 目标设备,允许我们选择我们想分析的设备

Target process list:Allows you to select the process or processes to profile   目标进程,允许我们选择对应的APP

Activity viewer:Shows the elapsed time of the current trace or the position of the inspection head in the timeline pane. If your trace document has multiple data runs associated with it, that’s shown here too.  活跃观察者,显示当前路径(trace)经过的时间或者监控头在时间轴面板( timeline pane)中的位置.如果trace document 有多部分数据相关联,都会显示。

Add Instrument button (+): Shows or hides the instruments Library palette, which contains a complete list of available instruments. From here, you can select individual instruments and add them to your trace document.   显示和隐藏工具库( instruments Library),包含了所有可使用的工具。这这里,可以选择独立的根据添加到当前的 trace document。

Strategy buttons: Control the type of information displayed in the timeline pane 策略按钮,控制在时间轴面板中的信息显示类型:
1)CPU (image: ../Art/instruments_icon_cpu_strategy_2x.png):Displays a list of CPU cores, along with their collected data, in the timeline pane. Only available when a trace document contains instruments that record CPU data 在时间轴面板中显示CPU的核心部分和收集的数据。仅仅是在当前trace document包含记录CPU数据工具的时候可以使用
2)Instruments (image: ../Art/instruments_icon_instruments_strategy_2x.png):Displays a list of instruments and their corresponding data in the timeline pane. 在时间轴面板中显示一 系列的工具和对应的数据
3)Threads (image: ../Art/instruments_icon_threads_strategy_2x.png):Displays a list of threads and their corresponding data in the timeline pane. Only available when a trace document contains instruments that record thread data 在时间轴面板中显示一些列的线程和对应的数据,仅仅是在当前trace document包含记录线程数据的根据才可以使用

View buttons: (image: ../Art/inline_instruments_view_buttons_2x.png):显示和隐藏详情面板和监控部分

Timeline Pane

时间轴面板显示了给定trace的数据记录图形概要。在面板中,每一个工具,CPU core,thread都有自己的轨道(track),提供了已收集数据对应的图表,可以点击strategy buttons来查看。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值