< Previous PageNext Page > Hide TOC

Performance Tools

Mac OS X comes with tools for gathering several different types of performance metrics for your application. Some of these tools can be launched from the Finder and some must be run from the command line. The following sections introduce the available tools and tell you when you might use them.

In this section:

Installing the Apple Tools
Analysis Tools
Monitoring Tools
Hardware Analysis Tools
Additional Command-Line Tools


Installing the Apple Tools

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

To install Xcode Tools, double-click the installer package found on the Xcode Tools CD or that you downloaded from the web. The installer creates a /Developer directory on the boot volume of your hard drive. Inside this directory are subdirectories containing the applications, documentation, examples, and other files.

The primary performance tools are located in the /Developer/Applications/Performance Tools directory but some tools are located in other subdirectories of /Developer/Applications. Several command-line performance tools are also installed in the /usr/bin directory and are available from Terminal.

Most of the applications with a graphical user interface have online help available through the Help menu. All of the command-line tools have man pages, accessed on the command line by typing “mantoolname”.

Analysis Tools

Analysis tools let you actively gather data about the performance of your program. You can view these tools in a way similar to debugging tools. You use them to investigate problems and gather information needed to go back and revise your code. Unlike debugging tools, most analysis tools provide a way to save data from a session so that you can view it later, which is very useful for charting the progress of your application.

With the exception of Shark, most of the analysis tools are geared towards finding specific types of performance problems. While any one tool might give you useful information, it is important to run several tools on the same code to view problems from several different angles. For example, using ObjectAlloc, you might find that your program creates a number of objects, but running MallocDebug you might find that many of those objects are actually being leaked. Shark provides many ways to gather and view information and is indispensable for finding performance problems in your code.

Table 3-1 lists the analysis tools installed with the Xcode Tools. Applications such as Shark are installed in the /Developer/Applications/Performance Tools directory. 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.

ObjectAlloc

Tracks Objective-C and Core Foundation object allocations and deallocations in real time. The tool also lets you view the retention history for an object, which can be useful in recovering memory held by over-retained objects.

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.

Sampler

Analyzes your application’s behavior at runtime. It can identify where your program spends its time and summarize how often allocation routines, system calls, or arbitrary functions were called.

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.

Shark

Does statistical sampling of all processes and threads in the system. You can also use Shark to trace function calls, including malloc calls, and to chart information graphically. Shark helps you to isolate problems quickly by providing a rich set of data-mining features and is an indispensable tool for finding performance bottlenecks.

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. Applications such as BigTop and Spin Control are installed in the /Developer/Applications/Performance Tools directory hierarchy. 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. 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 i 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.

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. The graphical applications are installed in /Developer/Applications/Performance Tools/CHUD and the command-line tools are installed in /usr/bin. All of the tools are included with the Xcode Tools. Table 3-3 lists the tools that are part of this package and provides a brief overview of their purpose.

Table 3-3  CHUD tools

Name

Description

CacheBasher

Measures cache performance under a wide range of conditions.

MONster

Collects sampling data at a hardware level. The tool can collect samples at a systemwide or process-specific level and display the metrics for the collected data. You can use this tool to gather metrics such as utilized bandwidth, cycles per instruction, and cache miss rates.

PMC Index

Lets you search for available performance counter events. When you select multiple events, the tool notifies you if those events cannot be recorded simultaneously.

Reggie SE

Lets you examine and modify CPU and PCI configuration registers.

Skidmarks GT

Measures integer, floating-point, and vector performance.

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.

amber

A command-line tool that traces all threads of execution in a process, recording every instruction and data access to a trace file. This tool can generate traces in TT6, TT6E, or FULL format.

simg4

A command-line tool that is a cycle-accurate simulator of the Motorola 7400 processor. This tool takes TT6 traces as input.

simg5

A command-line tool that is a cycle-accurate simulator of the IBM 970 processor. This tool takes TT6 traces as input.

For information about using the CHUD tools, see online help for a particular tool. Documentation for some CHUD tools is also installed in /Developer/ADC Reference Library/CHUD.

Additional Command-Line Tools

Table 3-4 lists some additional command-line tools that you can use to monitor and analyze performance in Mac OS X. 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.

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.

kdump

Displays kernel trace data.

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.



< Previous PageNext Page > Hide TOC


© 2004, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-10-03)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.