Target Devices and Processes
Target Devices and Processes
为了使用跟踪文档对某些内容进行配置,需要对其进行目标定位。也就是说,您需要告诉仪器您想要什么样的配置文件,以及您想要对它进行什么样的配置,例如在设备上或模拟器中。In order to profile something with a trace document, you need to target it. That is, you need to tell Instruments what you want to profile and where you want to profile it, such as on a device or in a simulator.
创建新跟踪文档时,工具会显示分析模板选择对话框。该对话框顶部包括一个目标设备列表和一个目标进程列表(图7-1),它允许你指定目标时,当你选择一个模板。这些列表包括配置或连接到Mac的任何设备,包括模拟器,以及用于对这些设备进行分析的任何流程。最近有针对性的进程、应用程序扩展、活动进程和系统进程也被列出。When you create a new trace document, Instruments displays the profiling template selection dialog. The top of this dialog includes a target device list and a target process list (Figure 7-1), which allow you to specify the desired target when when you choose a template. These lists include any devices that are configured or connected to your Mac, including simulators, as well as any processes available for profiling on those devices. Recently targeted processes, app extensions, active processes, and system processes are also listed.
Figure 7-1剖析模板选择对话框中的目标设备和进程列表Target device and process lists in the profiling template selection dialog
IMPORTANT
一些与iOS相关的仪器,如OpenGL ES分析仪和GPU驱动程序,不能在IOS模拟器中运行,必须在物理设备上运行。Some iOS-related instruments, such as the OpenGL ES Analyzer Instrument and GPU Driver Instrument, cannot be run in iOS Simulator and must be run on a physical device.
目标列表中的每一道文档工具栏也可用(见图7-2),允许你改变目标在任何时间在一个跟踪文件工作。Target lists are also available in the toolbar of every trace document (see Figure 7-2), allowing you to change the target at any time while working in a trace document.
Figure 7-2装置和过程跟踪中文档工具栏列表Target device and process lists in the trace document toolbar
-
单击目标设备列表或目标进程列表,并选择所需的设备和进程。Click the target device list or target process list, and select the desired device and process.
有些工具允许您针对所有进程。如果您想这样做,请选择目标进程列表中的所有进程。Some instruments allow you to target all processes. If you want to do this, select All Processes in the target process list.
如果未列出所需的流程,请在目标流程列表中选择“目标”。这将显示一个对话框,允许您浏览任何进程。您还可以通过这个对话框配置进程的环境变量。If the desired process isn’t listed, select Choose Target in the target process list. This displays a dialog that allows you to browse for any process. You can also configure environment variables for a process through this dialog.
针对iOS设备Target an iOS Device
若要针对iOS设备,请将设备连接到您的开发Mac。一旦连接,该设备会出现在目标设备列表,如图7-3所示。To target an iOS device, connect the device to your development Mac. Once connected, the device appears in the target device list, as shown in Figure 7-3.
Figure 7-3Targeting an iOS device in Instruments
NOTE
在您可以使用仪器简介iOS设备,您的设备必须配置的发展数据可以收集它。有关配置的信息,请参见在应用程序分发指南中创建开发配置概要文件。Before you can use Instruments to profile an iOS device, your device must be provisioned for development so data can be collected from it. For information on provisioning, see Creating Development Provisioning Profiles in App Distribution Guide.
以无线方式锁定iOS设备Target an iOS Device Wirelessly
仪器还允许您从iOS设备无线采集数据。在测试以下内容时,无线剖析特别有用:Instruments also allows you to collect data from an iOS device wirelessly. Wireless profiling is especially useful when testing the following:
-
加速度计。将设备移动到各个方向而不被栓住。Accelerometers. Move the device in all directions without its being tethered.
-
配件.将USB附件插入空闲槽中并进行测试。Accessories. Plug your USB accessory into the free slot and test it.
IMPORTANT
正如上面提到的,你的设备必须设置在仪器的发展可以从中收集数据。卓悦和组播也必须在您的无线网络接入点启用。有关这些服务的信息,看到Bonjour服务概述。设备和记录mac必须在同一无线网络和子网上。As mentioned above, your device must be provisioned for development before Instruments can collect data from it. Bonjour and multicast must also be enabled on your wireless network access point. For information on these services, see Bonjour Service Overview. Both the device and the recording Mac must be on the same wireless network and subnet.
-
确保你的iOS设备通过USB或闪电电缆连接到你的开发Mac上。Make sure your iOS device is connected to your development Mac by a USB or Lightning cable.
-
按下选项键,然后单击目标设备列表。Press the Option key, and click the target device list.
-
选择您的移动设备以启用它的无线分析。Select your mobile device to enable wireless profiling for it.
-
再次单击目标设备列表以打开它,选择设备的无线版本,然后选择一个进程。Click the target device list again to open it, select the wireless version of your device, and select a process.
-
从USB或闪电电缆断开设备。Disconnect the device from the USB or Lightning cable.
现在您应该能够在设备上以无线方式显示该流程。You should now be able to profile the process wirelessly on your device.
NOTE
在对设备进行无线分析时,关闭设备会导致数据收集停止。您必须重新连接设备到您的计算机以恢复数据收集。While profiling a device wirelessly, powering off the device causes data collection to stop. You must reconnect the device to your computer to resume data collection.
瞄准一只苹果手表Target an Apple Watch
在用仪器瞄准苹果手表之前,你必须先准备好苹果手表进行仿形加工。Before targeting an Apple Watch with Instruments, you must first prepare the Apple Watch for profiling.
-
确保你的苹果手表与你的开发iPhone配对。Ensure that your Apple Watch is paired with your development iPhone.
-
退出工具。Quit Instruments.
-
启动Xcode。Launch Xcode.
-
将你的苹果手表配对的iPhone连接到你的USB或闪电电缆的开发Mac上。Connect the iPhone that’s paired with your Apple Watch to your development Mac by a USB or Lightning cable.
-
选择窗口>设备(或按shift-command-2)在Xcode打开设备窗口。Choose Window > Devices (or press Shift-Command-2) to open the Devices window in Xcode.
-
等待iPhone出现在设备列表中。Wait for the iPhone to appear in the Devices list.
-
等待苹果手表作为iPhone的配对设备出现。Wait for the Apple Watch to appear as a paired device for the iPhone.
-
等待Xcode表明苹果手表已经准备。这个过程可能需要几分钟。Wait for Xcode to indicate that the Apple Watch has been prepared. This process may take several minutes.
-
从USB或闪电电缆断开iPhone。Disconnect the iPhone from the USB or Lightning cable.
-
再次连接iPhone到USB或闪电电缆。Connect the iPhone to the USB or Lightning cable again.
一旦你的苹果手表已经准备好谱,重启仪器,和苹果手表应该出现在目标设备列表,如图7-4所示。Once your Apple Watch has been prepared for profiling, relaunch Instruments, and the Apple Watch should appear in the target device list, as shown in Figure 7-4.
Figure 7-4Targeting an Apple Watch in Instruments
NOTE
当你对苹果手表进行剖析时,你的开发iPhone充当了一个代理,在手表和仪器之间传递信息。When profiling an Apple Watch, your development iPhone acts as a proxy, relaying information between the Watch and Instruments.
其他目标Other Ways to Target
在本章中,您学习了如何在工具中指定目标应用程序和设备。不过,您也可以在外部直接输入应用程序,而不必直接输入工具应用程序。访问以下章节了解更多信息:In this chapter, you learned how to specify a target app and device in Instruments. However, you can also target an app externally, without actually entering the Instruments app directly. Visit the following sections to learn more: