Analyzing Program Performance With Sun WorkShop

Reordering an Application

You might wish to reorder your application if (and only if) text page faults are consuming a large percentage of its time.

After the behavior data is collected, you can use the Sampling Analyzer to generate a mapfile containing an improved ordering of functions. 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:

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

  2. Load the application in Sun WorkShop for debugging.

  3. Activate the Sampling Collector to collect performance data by choosing Windows > Sampling Collector from the Debugging window. Be sure to enable Address Space data collection.

  4. Run the application in Sun WorkShop.

  5. Load the specified experiment into the Sampling Analyzer.

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

  7. 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 omapfile_name a.o b.

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