Performance Tools

The Xcode tools includes several graphical applications and command-line tools for gathering performance metrics. The following sections introduce the available tools and tell you when you might use them.

Installing the Apple Tools

The Apple performance tools are installed as part of the Xcode tools. This package ships on a CD that comes with retail copies of OS X. You can also download the Xcode tools for free from the Apple Developer website.

To install Xcode Tools, double-click the installer package found on the Xcode Tools CD or that you downloaded from the web. By default, the installer creates a /Developer directory on the boot volume of your hard drive and installs applications, documentation, examples, and other files in this directory. In Xcode 3.0 and later, the installer lets you specify a custom installation directory so that you can have multiple versions of the tools on your computer.

Most of the applications with a graphical user interface have online help available through the Help menu. For information about these tools, see OS X Man Pages.

Key Applications

Although Xcode comes with numerous applications for gathering performance data, there are a few that you will use more frequently than others. These tools can be used to gather data for both Mac apps and iPhone applications. The following sections describe these tools and the features they provide.

Instruments

Introduced in OS X v10.5, the Instruments application combines a set of powerful analysis tools with an easy-to-use graphical user interface. Instruments provides unprecedented information about the runtime behavior of your application. Rather than show only one aspect of your program at a time, you configure each analysis session with one or more “instruments”, each of which gathers information about a particular performance metric. The data from all instruments is shown side-by-side, making it easier to correlate the data from one instrument to another and detect trends in your application’s behavior.

Among the types of metrics you can gather with the Instruments application are the following:

  • The performance of Core Data–based applications

  • Information about file system reads, writes, and other operations

  • Statistics relating to garbage-collected code

  • Information about graphics operations and performance

  • Statistics about object and other memory-related allocations

  • Information about memory leaks

  • Statistical samples of your application at runtime

  • Information about process-specific and system-level activity

  • Information about Java thread activity

  • Information about events dispatched by Cocoa

For a quick example of how to use the Instruments application, see “Using Instruments.” For detailed information about the Instruments application, see Instruments User Guide.

Analysis Tools

Instruments is not the only analysis tool that you can use to gather data about the performance of your program. Most of the analysis tools are geared towards finding specific types of performance problems.

Table 3-1 lists the analysis tools installed with the Xcode Tools. (These tools are not able to analyze applications running in iOS.) Applications such as MallocDebug are installed in the <Xcode>/Applications/Performance Tools directory, where <Xcode> is the root directory of your Xcode installation. Command-line tools, such as heap and leaks, are installed in /usr/bin.

Table 3-1  Analysis tools

Tool

Description

MallocDebug

Tracks and analyzes memory allocated in an application. You can use this tool to find memory leaks or analyze memory allocation patterns.

OpenGL Driver Monitor

Gathers GPU-related performance data, including data related to VRAM usage, video bus traffic, and hardware stalls among others. You can use this information to identify the cause of temporary slowdowns or sporadic hesitations in your OpenGL application.

OpenGL Profiler

Creates a runtime profile of your OpenGL-based application. You can view function statistics and the call-trace history of your application’s OpenGL calls.

Saturn

Instruments your code to provide function-level profiling and displays the resulting data graphically. You can use this tool to count events, such as how many times a function is called or an event is sent.

heap

Lists all malloc-allocated buffers in the heap of a specified process

leaks

Searches the memory space of a process for any allocated but unreferenced blocks of memory.

vmmap

Displays the virtual memory regions allocated to a specified process. You can use this tool to analyze the memory usage of your process.

Monitoring Tools

Monitoring tools are passive tools that gather data automatically. To use these tools, leave them running while you exercise the features of your program. You can then analyze the data generated by these tools to gain a better understanding of your program’s performance characteristics. Some programs, like Spin Control, should be left running all the time. Most others can be launched and terminated as needed to gather performance information.

Table 3-2 lists the monitoring tools installed with the Xcode Tools in OS X. (These tools are not able to monitor applications running in iOS.) Applications such as BigTop and Spin Control are installed in the <Xcode>/Applications/Performance Tools directory hierarchy, where <Xcode> is the root directory of your Xcode installation. The Activity Monitor tool is installed in the /Applications/Utilities directory. Command-line tools, such as fs_usage and top, are installed in /usr/bin.

Table 3-2  Monitoring tools

Tool

Description

Activity Monitor

Displays common usage statistics relating to memory and CPU usage for the currently running processes. You can also initiate the sampling of a process from this application. This tool provides information that is similar to that of the top tool.

BigTop

Displays system statistics, such as CPU, disk, network and memory usage graphically over time. You can monitor a single process or all processes. This tool provides information that is similar to that of the top and vm_stat tools.

Quartz Debug

Shows screen updates in real time by briefly flashing the areas being redrawn. You can use this tool to analyze your application’s drawing behavior.

Spin Control

Samples programs that cause the spinning cursor to appear. Leave this program running in the background to catch unresponsive applications at critical moments.

Thread Viewer

Graphically displays activity across a range of threads. It provides color-coded timeline views of thread activity and can display backtraces of activity at specific points in time. (Available in OS X v10.5 and earlier.)

fs_usage

Displays an ongoing list of file-system activity, as generated by page faults and calls to file-system functions. You can use this tool to understand the file access patterns of your program.

sc_usage

Displays an ongoing list of system call and page fault statistics.

top

Displays common system usage statistics relating to memory and CPU usage for the currently running processes. This tool updates the information dynamically so that you can see trends at runtime.

Hardware Analysis Tools

The CHUD Tools include additional applications for doing hardware and low-level software analysis in OS X. (These tools are not able to analyze hardware running iOS.) Table 3-3 lists the tools that are part of this package and provides a brief overview of their purpose. The graphical applications are installed in <Xcode>/Applications/Performance Tools/CHUD directory, where <Xcode> is the root directory of your Xcode installation. The command-line tools are installed in the /usr/bin directory. All of the tools are included with the Xcode Tools.

Table 3-3  CHUD tools

Name

Description

Reggie SE

Lets you examine and modify CPU and PCI configuration registers.

acid

A command-line tool that analyzes TT6E instruction traces and presents detailed analyses and histograms. You can use this tool to detect bad instruction sequences, such as misaligned operands, data dependency stalls, and spilled loads.

simg4

A command-line tool that is a cycle-accurate simulator of the Motorola 7400 processor. This tool takes TT6 traces as input. (Available in OS X v10.5 and earlier.)

simg5

A command-line tool that is a cycle-accurate simulator of the IBM 970 processor. This tool takes TT6 traces as input. (Available in OS X v10.5 and earlier.)

For information about using the CHUD tools, see online help for a particular tool. Documentation for some CHUD tools is also installed in the <Xcode>/Documentation/CHUD directory, where <Xcode> is the root directory of your Xcode installation.

Additional Command-Line Tools

Table 3-4 lists some additional command-line tools that you can use to monitor and analyze performance in OS X. (These tools are not able to monitor and analyze applications running in iOS.) These tools are located in the /usr/bin/ directory and must be run from a command-line prompt. Most are installed along with the Xcode Tools. For information about these tools, see OS X Man Pages.

Table 3-4  Command-line tools

Name

Description

atos

Converts back and forth between a symbol name and the numeric address of that symbol in a running executable.

c2ph

Displays the C-structures from an object file along with their member offset values.

gprof

Produces execution profiles based on an execution analysis of a program.

malloc_history

Shows the malloc allocations performed by a specified process.

nm

Displays the symbol table information for one or more object files.

otool

Displays the contents of a Mach-O executable in a more human-readable form

pagestuff

Displays information about the logical pages of a Mach-O executable file.

pstruct

Parses the C structures from an object file and displays them along with their member offset values.

sample

Produces an execution profile based on the execution analysis of a program.

vm_stat

Displays Mach virtual memory statistics, including the number of active, inactive, wired, and free pages. This tool also displays page fault and other activity information.