Profile with the instruments command-line tool

Use the instruments command-line tool (see instruments(1) Mac OS X Developer Tools Manual Page) to profile an app using a specified template without launching Instruments. Data gathered during profiling is saved in a .trace file into a specified directory. After profiling is complete, you can open the recorded data file with Instruments to see a visual representation of the data.

  1. Open Terminal, in /Applications/Utilities.

  2. Enter an instruments command to collect data.

    For example, the following command profiles an app with the Allocations template and saves the results to the desktop in a .trace file.

    instruments -t "Allocations" -D ~/Desktop/YourTraceFileName.trace PathToYourApp
  3. Open Instruments, and choose File > Open.

  4. Find your saved .trace 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.

instruments options

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

Configuration option

Description

-t template

The name or path of the profiling template to use when analyzing your app.

-s

Returns a list of all installed profiling templates.

-D document

The path where the .trace document should be saved. If the file already exists, the newly recorded data is appended to it as a new run.

-l #

The amount of time to record, in milliseconds, before terminating. If not provided, recording occurs indefinitely, until the app is manually terminated.

-i #

The index of the instrument to use for recording.

-p pid

The process ID of the app to be recorded.

application

The path of the app to be recorded.

-w hardware device

The ID of the device to target.

-e variable value

An environment variable to be applied while profiling.

argument

A command-line argument to be passed to the app being profiled. Multiple arguments may be specified, if desired.

-v

Enables verbose logging while profiling.

SEE ALSORecord a traceProfile from the DockProfile your app from the Xcode Build and Product menusProfile from the Xcode gauges while debuggingCollect and view data with the iprofiler command-line toolInstruments User Guide