Collect and view data with the iprofiler command-line tool

Use the iprofiler command-line tool (see iprofiler(1) Mac OS X Developer Tools Manual Page) to measure an app’s performance without launching Instruments. After collecting performance data, import it into Instruments in order to see a visual representation of the data. Data collected by iprofiler is saved in a .dtps bundle that can be opened by Instruments.

  1. Open Terminal, in /Applications/Utilities.

  2. Enter an iprofiler command to collect data.

    For example, the following command performs an Activity Monitor trace on your app for 5 seconds and saves the results to the desktop in a .dtps file.

    iprofiler -activitymonitor -T 5s -d ~/Desktop/ PathToYourApp
  3. Open Instruments, and choose File > Open.

  4. Find your saved .dtps file, and click Open.

    After opening the saved file, Instruments automatically adds the associated instruments to a trace document and populates them with the collected data. You can view and analyze the data in order to locate any issues with your app.

iprofiler supports the following types of profiles:

iprofiler options

iprofiler provides the following set of configuration options for defining what data to collect.

Configuration option

Description

-l

Provides a list of all supported instruments.

-L

Provides a list of all supported instruments and a description of what each template does.

-legacy

Executes the legacy Instruments command-line interface found in /usr/bin/instruments.

-T duration

Sets the length of time for which data is collected. Set duration in seconds (ns or n), milliseconds (nm or nms), or microseconds (nu or nus). The default is 10 seconds.

-I interval

Sets the frequency with which a measurement is taken during the sample time. Set the interval to seconds (ns or n), milliseconds (nm or nms), or microseconds (nu or nus). The default is the Instruments app’s default sampling interval.

-window period

Limits the performance measurement to the final period of the iprofiler run. Set the period to seconds (ns or n), milliseconds (nm or nms), or microseconds (nu or nus). If this option is not specified, performance is measured throughout the entire run.

Note: This option can be used only with the -timeprofiler and -systemtrace template options.

-d path -o basename

Specifies the destination path and the name used when saving the collected data. The default path is the current working directory. The default basename is the process name or process ID.

-instrument name

Designates the instrument to be run. Valid name options are -activitymonitor, -allocations, -counters, -eventprofiler, -leaks, -systemtrace, and -timeprofiler.

At least one template must be listed. You can run up to all seven templates at once.

-kernelstacks

Designates kernel stacks only for backtraces.

If neither -kernelstacks nor -userandkernelstacks options are specified, backtraces include user stacks only.

-userandkernelstacks

Designates both kernel and user stacks for backtraces.

If neither -kernelstacks nor -userandkernelstacks options are specified, backtraces include user stacks only.

-pmc PMC_MNEMONIC

When used with -counters, specifies the mnemonic of the event to count. Multiple mnemonics should be comma-separated.

-allthreadstates

Causes the Time Profiler template to profile all threads. If this value is not specified, Time Profiler profiles only running threads.

-a process/pid

Attaches to a process that is already running. Specifying a string attaches the process whose name starts with that string. Specifying a process ID attaches it to the process associated with that process ID.

The -leaks option requires you to specify a specific single process or process ID.

executable [args…]

Causes the target process to be launched for the duration of the measurement. Lists the executable and the arguments as if they are being invoked from the command line.

iprofiler examples

A list of common iprofiler command-line examples are below.

This example collects data from all running processes for the current sampling duration set in Instruments using the Time Profiler and Activity Monitor instruments. The collected data is saved to the working directory as allprocs.dtps.

iprofiler -timeprofiler -activitymonitor

The following example opens and collects data from YourApp using the Time Profiler instrument. Data is collected for eight seconds, and the data is saved at /temp/YourApp_perf.dtps.

iprofiler -T 8s -d /temp -o YourApp_perf -timeprofiler -a YourApp

The following example collects data from the process with the 823 process ID using the Leaks and Activity Monitor instruments. Data is collected for 2500 milliseconds (2.5 seconds) and is saved to the working directory as YourApp_perf.dtps.

iprofiler -T 2500ms -o YourApp_perf -leaks -activitymonitor -a 823

The following example opens and collects data from YourApp using the Time Profiler and Allocations instruments. Data is collected for the default amount of time set in Instruments and saved in /tmp/allprocs.dtps.

iprofiler -d /tmp -timeprofiler -allocations -a YourApp.app

The following example opens and collects data from YourApp found in /path/to with the argument arg1 using the Time Profiler and System Trace instruments. Data is collected for 15 seconds, but only the data collected in the last 2 seconds is saved. The data is saved to the working directory as YourApp_perf.dtps.

iprofiler -T 15 -I 1000ms -window 2s -o YourApp_perf -timeprofiler -systemtrace /path/to/Your.app arg1
SEE ALSORecord a traceProfile from the DockProfile your app from the Xcode Build and Product menusProfile from the Xcode gauges while debuggingProfile with the instruments command-line toolInstruments User Guide