Performance Tools

There are several graphical applications and command-line tools available for gathering performance metrics. Some performance tools are installed with Xcode. Others are available for download from the Apple Developer website.

Key Applications

Although Xcode comes with numerous applications for gathering performance data, there are a few that you will use more frequently than others.

Instruments

Instruments combines a set of powerful analysis tools with a graphical user interface to provide unprecedented information about the runtime behavior of your application. Rather than showing 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 Instruments, see Using Instruments. For detailed information, see Instruments User Guide.

Analysis Tools

Instruments is not the only analysis tool that can gather data about the performance of your app. Other analysis tools are geared towards finding specific types of performance problems. Table 3-1 lists the analysis tools installed with Xcode and available for download.

Table 3-1  Analysis tools

Tool

Description

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.

This tool is part of the Graphics Tools for Xcode, available on the downloads page of the Apple Developer website.

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.

This tool is part of the Graphics Tools for Xcode, available on the downloads page of the Apple Developer website.

heap

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

This tool is installed in /usr/bin/.

leaks

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

This tool is installed in /usr/bin/.

vmmap

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

This tool is installed in /usr/bin/.

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 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 in OS X and available for download.

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.

This tool is installed in /Applications/Utilities/.

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.

This tool is part of the Graphics Tools for Xcode, available on the downloads page of the Apple Developer website.

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.

This tool is installed in /usr/bin/.

sc_usage

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

This tool is installed in /usr/bin/.

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.

This tool is installed in /usr/bin/.

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, which is available on the downloads page of the Apple Developer website.

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.)

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.