Guides and Sample Code

Developer

Instruments User Guide

On This Page

Monitor Network and File I/O

Instruments provides several profiling templates that monitor your app’s network and file I/O activity.

Use Activity Monitor to Track Overall Network and Disk Use

The Activity Monitor profiling template uses the Activity Monitor instrument to track overall system activity over time, including CPU, memory, network, and disk. By default, the Activity Monitor template doesn’t display network or disk activity in the timeline pane. However, you can manually enable the display of these statistics.

To record network and disk use with the Activity Monitor instrument
  1. Launch Instruments.

  2. In the profiling template selection dialog that appears, click Activity Monitor.

  3. Choose your device and app from the target device and process lists.

  4. Click Choose to create a trace document.

  5. Click the Activity Monitor instrument in the timeline pane.

  6. Press Command-2 to show record settings in the inspector pane.

  7. In the “Statistics to list” area, select the statistics you want to see. Then, select them again in the System Statistics area to enable them.

    The following statistics pertain to file I/O:

    • Disk read ops (operations)

    • Disk write ops

    • Disk bytes read

    • Disk bytes written

    • Disk read ops per second

    • Disk write ops per second

    • Disk bytes read per second

    • Disk bytes written per second

    The following statistics pertain to network I/O:

    • Net packets in (received)

    • Net packets out (sent)

    • Net bytes in

    • Net bytes out

    • Net packets in per second

    • Net packets out per second

    • Net bytes in per second

    • Net bytes out per second

  8. Click the Record button (image: ../Art/inline_record_button_2x.png) in the toolbar (or press Command-R) to begin recording.

  9. Use your app normally.

  10. Click the Stop button (image: ../Art/inline_stop_button_2x.png), or press Command-R again, when complete.

  11. Examine the collected data.

    The timeline pane displays graphs visually denoting activity. Comprehensive activity information is found in the detail pane. Choose Samples from the detail type list in the navigation bar of the detail pane to see all data captured during the sample period. Examine the network and disk columns to pinpoint times when activity was especially high. These may be areas where you can batch transactions for greater performance and energy efficiency.

Monitor Network Connections of an iOS App

The Network profiling template uses the Connections instrument to analyze your iOS app’s TCP/IP and UDP/IP connections.

To record network connections used by your iOS app
  1. Connect your iOS device to your Mac.

    You can use a physical or wireless connection. See Target an iOS Device Wirelessly.

  2. Launch Instruments.

  3. In the profiling template selection dialog that appears, click Network.

  4. Choose your iOS device and app from the target device and process lists.

  5. Click Choose to create a trace document.

  6. Click the Record button (image: ../Art/inline_record_button_2x.png) in the toolbar (or press Command-R) to begin recording.

  7. Use your app normally.

  8. Click the Stop button (image: ../Art/inline_stop_button_2x.png), or press Command-R again, when complete.

  9. Examine the collected data.

    Use the detail type list in the navigation bar of the detail pane to view information by process, connection, or network interface (hardware).

Monitor Disk Use in OS X

The File Activity profiling template uses the File Activity, Reads/Writes, File Attributes, and Directory I/O instruments to watch your OS X app’s disk use.

To record the file activity of your OS X app
  1. Launch Instruments.

  2. In the profiling template selection dialog that appears, click File Activity.

  3. Choose your Mac and OS X app from the target device and process lists.

  4. Click Choose to create a trace document.

  5. Click the Record button (image: ../Art/inline_record_button_2x.png) in the toolbar (or press Command-R) to begin recording.

  6. Use your app normally.

  7. Click the Stop button (image: ../Art/inline_stop_button_2x.png), or press Command-R again, when complete.

  8. Click individual instruments in the timeline pane to view their activity in the detail pane.

    Each instrument provides an event list and a call tree, which you can use to analyze specific instances of file activity.

  9. Select an event you want to inspect in the detail pane.

  10. Press Command-3 to display a stack trace for the selected event in the extended detail area of the inspector pane.

  11. Click the Collapse button (image: ../Art/inline_hidesystemcalls_button_2x.png) in the extended detail area to hide system calls in the stack trace. This makes it easier to locate your app’s methods.

    Calls made by your app are colored black and preceded by a user code icon (image: ../Art/inline_usercode_icon_2x.png).

  12. Double-click a method in the stack trace to display its code in Instruments.

  13. Click the Xcode button (image: ../Art/inline_xcode_2x.png) at the top of the detail pane to open the code in Xcode for editing.