Analyzing Program Performance With Sun WorkShop

Chapter 1 Performance Profiling and Analysis Tools

Developing high performance applications requires a combination of compiler features, libraries of optimized routines, and tools to analyze and isolate code. Analyzing Program Performance With Sun WorkShop describes these tools that are available to help you achieve the third part of this development strategy:

The Sampling Collector collects performance behavior data about a program during runtime and writes that data to a file. The Sampling Analyzer examines the data and displays it graphically.

The Sampling Collector and Sampling Analyzer are included in the following Sun Workshop products:

LoopTool supports performance tuning of automatically parallelized programs. LoopReport is the command line version of LoopTool.

LoopTool and LoopReport are included in the following Sun Workshop products:

LockLint extends Sun WorkShop development tools and compilers with support for development of multiprocessing/multithreaded applications.

LockLint performs a static analysis of the use of mutex and multiple readers-single writer locks, and looks for inconsistent use of these locking techniques. LockLint is included in the following Sun Workshop products:

prof and gprof are traditional tools for generating profile data and are included with versions 2.5.1, 2.6, and Solaris 7 of the Solaris SPARC Platform Edition and Solaris Intel Platform Edition.

tcov is a code coverage tool. It is included in Sun Workshop.

Sampling Analysis Tools

Sun WorkShop provides a pair of tools that you use together to collect performance data on your application and analyze that data.

The Sampling Collector

The Sampling Collector is a graphical tool that is available from the Sun WorkShop debugger. When you execute your application, the Sampling Collector collects performance data from the kernel; this is called an experiment. The Sampling Collector writes the data it collects to a file that is called an experiment record. The experiment record includes resource usage data, program memory usage data, and execution profile data with or without called-function times.

The Sampling Analyzer

The Sampling Analyzer examines the experiment record written by the Sampling Collector and displays it graphically. Two additional utilities enable you to convert the experiment record into ASCII format (er_export) and to print the data to a file or printer (er_print).

The sampling analysis tools are described in Chapter 2, The Sampling Analysis Tools.

Loop Analysis Tools

Many compute-intensive Fortran applications exhibit loop-level parallelism, where computations are performed over large datasets in loops. Sun WorkShop lets you use this parallelism through automatic parallelization of FORTRAN 77, Fortran 90, and C programs. Use the compiler to parallelize loops in your program. Use LoopTool or LoopReport to examine loops parallelized by the FORTRAN 77, Fortran 90, or C compiler.

LoopTool

LoopTool is a graphical analysis tool that reads the loop timing files created by programs compiled for loop analysis with Fortran and C compilers. LoopTool enables you to:

LoopTool displays a graph of loop run times and identifies which loops were parallelized. You can go directly from the display to the source code for any loop.

To use LoopTool, you compile your program with the -Zlp option. When you run a program that has been compiled with the -Zlp option, Sun WorkShop creates a loop timing file. You run LoopTool to read the timing file and display its results. Sun WorkShop provides a demonstration program named vgam and a demonstration timing file named vgam.looptimes. When you start LoopTool from the Sun WorkShop Tools menu, it displays results from these files. You can use these demos to become familiar with LoopTool or specify your own files if you have already compiled a program with the -Zlp option. LoopTool is described in Chapter 3, Loop Analysis Tools.

LoopReport

LoopReport is the command line version of LoopTool. LoopReport produces an ASCII file of loop times instead of a graphical display. LoopReport is described in Chapter 3, Loop Analysis Tools.

Lock Analysis Tool

Many C developers thread their applications by programming directly against Solaris user-level threads via the libthread library. With Sun WorkShop applications, you can run the multithreaded extension to the debugger for debugging programs that use Solaris user-level threads. Use LockLint to statically check your program for consistent use of locks and potential race conditions.

In multithreaded applications, threads must acquire and release locks associated with the data they share. When threads fail to acquire and release locks appropriately, they can cause your program to produce different results over different executions with the same input. This condition is known as a a data race. Data races are easy problems to introduce and difficult ones to find.

A program can also deadlock when various threads are waiting for a lock that will not be releases. For a definition of deadlock, see "Basic Concepts".

Sun WorkShop provides a command-line utility for analyzing locks and how they are used. LockLint looks for inconsistent use of mutex and multiple readers-single writer locks. It detects a common cause of data races: failure to hold the appropriate lock while accessing a variable. LockLint also detects common causes for deadlocks.

To gather the information used by LockLint you specify the -Zll option to the C compiler, which then generates an .ll file for each .c source code file. The .ll file contains information about the flow of control in each function and about each access to a variable or operation on a mutex or readers-writer lock.

LockLint is described in Chapter 5, Lock Analysis Tool.

Traditional Profiling Tools

Sun WorkShop includes three command-line utilities for reporting data about your program:

Use prof and gprof to gather and display information for threaded (including auto-parallelized) programs. These tools provide a variety of levels of feedback about your program for you to analyze. They work in combination with other utilities and compiler options to collect and use performance data. prof generates a program profile in a flat file. gprof generates a call graph profile. tcov generates statement-level information in a copy of the source file, annotated to show which lines are used and how often.

These tools are described in Chapter 4, Traditional Profiling Tools.