Analyzing Program Performance With Sun WorkShop

Compiling for tcov Enhanced

To use tcov Enhanced, follow the same basic steps as the original tcov:

  1. Compile a program for a tcov Enhanced experiment.

  2. Run the experiment.

  3. Analyze the results using tcov.

For the original tcov, you compile with the -xa option. To compile a program for code coverage with tcov Enhanced, you use the -xprofile=tcov option for all compilers. Using a program named index.assist as an example, you would compile for use with tcov Enhanced with this command:

% cc -xprofile=tcov -o index.assist index.assist.c

tcov Enhanced, unlike tcov, does not produce a .d file. The coverage data file is not created until the program is run. Then one coverage data file is produced as opposed to one file for each module compiled for coverage analysis.

After you compiled index.assist.c, you would run index.assist to create the profile file:

% index.assist

% ls -dF *.profile

index.assist.profile/

% ls *.profile

tcovd

By default, the name of the directory where the tcovd file is stored is derived from the name of the executable. Furthermore, that directory is created in the directory the executable was run in (the original tcov created the .d files in the directory where the modules were compiled).

The directory where the tcovd file is stored is also known as the "profile bucket." The profile bucket can be overridden by using the SUN_PROFDATA environment variable. This may be useful if the name of the executable is not the same as the value in argv[0] (for example, the invocation of the executable was through a symbolic link with a different name).

You can also override the directory where the profile bucket is created. To specify a location different from the run directory, specify the path using the SUN_PROFDATA_DIR environment variable. Absolute or relative pathnames can be specified in this variable. Relative pathnames are relative to the program's current working directory at program completion.

TCOVDIR is supported as a synonym for SUN_PROFDATA_DIR for backward compatibility. Any setting of SUN_PROFDATA_DIR causes TCOVDIR to be ignored. If both SUN_PROFDATA_DIR and TCOVDIR are set, a warning is displayed when the profile bucket is generated. SUN_PROFDATA_DIR takes precedence over TCOVDIR. The variables are used at runtime by a program compiled with -xprofile=tcov, and are used by the tcov command.


Note -

This scheme is also used by the profile feedback mechanism.


Now that some coverage data has been produced, you could generate a report that relates the raw data back to the source files:

% tcov -x index.profile index.assist.c

% ls *.tcov

index.assist.c.tcov

The output of this report is identical to the one from the previous example (for the original tcov).