Guides and Sample Code


Instruments User Guide

On This Page

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.

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-1Target device and process lists in the profiling template selection dialog image: ../Art/instruments_profiling_dialog_target_2x.png

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-2Target device and process lists in the trace document toolbar image: ../Art/instruments_trace_document_toolbar_target_menus_2x.png
To target a device and a process
  1. Click the target device list or target process list, and select the desired device and process.

    image: ../Art/instruments_targetspecificprocess_menuitem_2x.png

    Some instruments allow you to target all processes. If you want to do this, select All Processes in the target process list.

    image: ../Art/instruments_targetallprocesses_menuitem_2x.png

    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.

    image: ../Art/instruments_choosetarget_menuitem_2x.png
    image: ../Art/instruments_choosetargetdialog_2x.png

Target an iOS Device

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 image: ../Art/instruments_targetiosdevice_2x.png

Target an iOS Device Wirelessly

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.

  • Accessories. Plug your USB accessory into the free slot and test it.

To enable an iOS device for wireless profiling
  1. Make sure your iOS device is connected to your development Mac by a USB or Lightning cable.

    image: ../Art/graphic_computerconnectedtodevice_2x.png
  2. Press the Option key, and click the target device list.

  3. Select your mobile device to enable wireless profiling for it.

    image: ../Art/instruments_targets_enablewireless_2x.png
  4. Click the target device list again to open it, select the wireless version of your device, and select a process.

    image: ../Art/instruments_targtetlist_selectwirelessprocess_2x.png
  5. Disconnect the device from the USB or Lightning cable.

    You should now be able to profile the process wirelessly on your device.

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.

    image: ../Art/graphic_computerconnectedtodevice_2x.png
  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.

    image: ../Art/xcode_devices_pairedwatch_2x.png
  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 image: ../Art/instruments_targetwatch_2x.png

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: