Using Sun WorkShop

Chapter 6 Analyzing Program Performance

This chapter describes the basics of how to use the Sampling Collector and Sampling Analyzer to performance-tune applications in Sun WorkShop. For more detailed information on these and other performance-profiling tools included in Sun WorkShop, see Analyzing Program Performance With Sun WorkShop and Sun WorkShop online help.

This chapter is organized into the following sections:

Performance Profiling in Sun WorkShop

The Sampling Collector, available from the Debugging window, gathers performance data during the execution of an application and saves it to an experiment file. The Sampling Analyzer, a separate tool available from the Sun WorkShop main window, displays collected performance data and, if paging is causing a bottleneck, can create a file to instruct the linker to remap functions in memory.

The UNIX prof and gprof performance-profiling tools generate only user CPU information. With the Sampling Collector and Sampling Analyzer, you can get information about I/O time, system time, text and data page fault times, program sizes, and execution statistics, in addition to user CPU information.

Figure 6-1 illustrates the basic performance-tuning architecture in Sun WorkShop.

Figure 6-1 Performance-Tuning Architecture

Graphic

The Sampling Collector gathers performance data from the application and writes it to an experiment record. The Sampling Analyzer displays that experiment data online and can print the data to either a file or a printer. Additionally, the Sampling Analyzer can create a mapfile for the linker, and you can then recompile the application.

The following sections describe the basic steps involved in collecting and analyzing performance data. For more detailed information on any of the steps, see Analyzing Program Performance With Sun WorkShop, and "Analyzing Performance Data" and "Collecting Performance Data" in the online help for Sun WorkShop.

Building the Application

Before collecting performance data you must build your application. For information on building, see Chapter 4, Building Programs in Sun Workshop" and the online help.

Collecting Performance Data

The Sampling Collector gathers performance data about a program as it runs through the Debugging window. To view the results of the experiment file you collect, you must use the Sampling Analyzer, which is available separately through the Sun WorkShop main window or can be displayed by choosing Collect > Analyze from the Sampling Collector.

When you create an experiment file in the Sampling Collector, you also create a hidden directory in the same directory as the experiment file. The hidden directory name is preceded by a dot (.)--for example, if the experiment file is called test.1.er, the hidden directory is called .test.1.er. Files in this directory contain information on segments, modules, lines, and functions.


Note -

The Analyzer list field (selected from the Section list) in the WorkSet window lists the experiments associated with the current WorkSet and allows you to add or delete experiments using the Add Experiment and Delete Experiment buttons.


Types of Data You Can Collect

You can collect three types of data:

For more information on choosing the type of data to collect, see Analyzing Program Performance With Sun WorkShop, and "Choosing the Type of Data to Collect" in the Sun Workshop online help.

Frequency of Sample Collection

Samples are sets of data collected over specific periods of time while an application is running.

You can specify the frequency of sample collection by moving the Collect Profile data slider to the desired number of samples per second. Both data accuracy and collection overhead increase as the number of samples collected per second increases.

Collecting Data

To collect performance data:

  1. From the Debugging window, disable runtime checking and choose Windows > Sampling Collector to open the Sampling Collector.

  2. In the Experiment File text box, type the complete path name for the experiment file to be created.

  3. Using the Collect Data radio buttons, select whether you want to collect data for one run only or for all runs.

    If you select for one run only, the Sampling Collector turns off after an experiment is created. If for all runs is selected, the Sampling Collector remains turned on even after the experiment is created.

  4. Load the program into the Debugging window and run it by clicking either Start or Go.

Analyzing Performance Data

After you collect performance data with the Sampling Collector, you can view it only through the Sampling Analyzer, a separate tool available from the Sun WorkShop main window or by choosing Collect > Analyze in the Sampling Collector window. The three types of data you can collect with the Sampling Collector separate into nine types of data available to analyze; each of these nine types of data has one or two Analyzer display options associated with it.

Types of Data You Can View and Analyze

You can analyze the following types of data by selecting them from the Data list in the Sampling Analyzer window:

For more information on selecting a data type, see "Selecting Data Types" in the Sun WorkShop online help.

Display Options

The Sampling Analyzer offers five ways to view collected performance data:

For more information on selecting a display option, see "Selecting Display Options" in the Sun WorkShop online help.

Comparing Samples

By choosing View > New Window in a Sampling Analyzer window, you can open a new Analyzer window to compare two samples or view the same set of samples in two different ways.

Reordering Program Functions

If text page faults are consuming a lot of your application's time, the Sampling Analyzer can reorder your program, generating a mapfile containing an improved ordering of functions. With the most-used functions grouped together on the same set of pages, a function is more likely to already be in memory when called.

The --M option passes the mapfile to the linker, which then relinks your application and produces a new executable application with a smaller text address space size.

After you have reordered your application you can run a new experiment and compare the original version with the reordered one.

To reorder an application, compile the application using the --xF option.

The --xF option is required for reordering. This option causes the compiler to generate functions that can be relocated independently.

For C applications, type:

cc -xF -c a.c b.c cc -o application_name a.o b.o

For C++ applications, type:

CC -xF -c a.cc b.cc CC -o application_name a.o b.o

For Fortran applications, type:>

f77 -xF -c a.f b.f f77 -o application_name a.o b.o

If you see the following warning message, check any files that are statically linked, such as unshared object and library files, because these files may not have been compiled with the --xF option:


ld: warning: mapfile: text: .text%function_name: object_file_name: Entrance criteria not met the named file, function_name, has not been compiled with the --xF option.

  1. Load the application in Sun WorkShop for debugging.

  2. Start the Sampling Collector by choosing Windows > Sampling Collector from the Debugging window.

  3. Run the application in Sun WorkShop.

  4. Load the specified experiment into the Sampling Analyzer.

  5. Create a reordered map in the Sampling Analyzer by choosing Experiment > Create Mapfile. In the file chooser, enter the samples to be used, the mapfile directory, and the name of the mapfile to be created, and click OK.

    The mapfile contains names of functions that have user CPU time associated with them. It specifies a function ordering that reduces the size of the text address space by sorting profiling data and function sizes in descending order. All functions not listed in the mapfile are placed after the listed functions.

  6. Link the application using the new mapfile.

    For C applications, type:

    cc -Wl -M mapfile_name a.o b.o

    For C++ applications, type:

    CC -M mapfile_name a.o b.o

    For C applications, the --M option causes the compiler to pass --M mapfile_name to the linker.

    For Fortran applications, type:

    f77 -M mapfile_name a.o b.o

Printing

You can print a plain text version of the current display or a text summary of the experiment (including average sample times for each data type and the frequency of use of functions, modules, and segments). Choose Experiment > Print or Experiment > Print Summary in the Sampling Analyzer window and type the appropriate information in the dialog box.

Exporting Experiment Data

You can export collected experiment data to files for use by other programs (such as spreadsheets or custom-written applications).

To export experiment data to an ASCII file:

  1. Type the directory of the experiment file to be exported in the Directory text box and the name of the file in the File text box.

  2. Choose Experiment > Export.

  3. Click OK to save the experiment data under the given file name.