首页 > 代码库 > Target Devices and Processes

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技术分享

目标设备和进程To target a device and a process
  1. 单击目标设备列表或目标进程列表,并选择所需的设备和进程。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.

    技术分享技术分享

TIP

如果你试图描述你的目标应用程序,但是应用程序没有主动运行,仪器会自动启动。If you attempt to profile an app you’ve targeted, but the app isn’t actively running, Instruments launches it automatically.

针对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设备能够进行无线分析To enable an iOS device for wireless profiling
  1. 确保你的iOS设备通过USB或闪电电缆连接到你的开发Mac上。Make sure your iOS device is connected to your development Mac by a USB or Lightning cable.

    技术分享
  2. 按下选项键,然后单击目标设备列表。Press the Option key, and click the target device list.

  3. 选择您的移动设备以启用它的无线分析。Select your mobile device to enable wireless profiling for it.

    技术分享
  4. 再次单击目标设备列表以打开它,选择设备的无线版本,然后选择一个进程。Click the target device list again to open it, select the wireless version of your device, and select a process.

    技术分享
  5. 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.

To prepare an Apple Watch for profiling
  1. Ensure that your Apple Watch is paired with your development iPhone.

  2. Quit Instruments.

  3. Launch Xcode.

  4. Connect the iPhone that’s paired with your Apple Watch to your development Mac by a USB or Lightning cable.

    技术分享
  5. Choose Window > Devices (or press Shift-Command-2) to open the Devices window in Xcode.

  6. Wait for the iPhone to appear in the Devices list.

  7. Wait for the Apple Watch to appear as a paired device for the iPhone.

  8. Wait for Xcode to indicate that the Apple Watch has been prepared. This process may take several minutes.

    技术分享
  9. Disconnect the iPhone from the USB or Lightning cable.

  10. Connect the iPhone to the USB or Lightning cable again.

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

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:

  • Profile from the Dock

  • Profile from Xcode

  • Profile from the Command Line

Target Devices and Processes