Profile Data - CTC++, gcov and gprof

While much of the information collected and displayed by Imagix 4D is based on static analysis of your source code, the tool can also collect and display certain information about the runtime performance of your C and C++ software. Collected from profile data sources, these runtime performance measurements can be displayed as separate, individual metrics associated with the functions in your code. They can also be viewed collectively in the Graph window under the structure views, so you can see the run-time performance of each function and call within the context of your program's overall calling structure. And coverage results can be displayed in Flow Charts, File Editors and Diff Tools to provide insight into the specific portions of a function that have, and have not, been exercised by your test cases.

The process of importing profile data sources into your project consists of determining what data sources you need, appropriately compiling your source code, running your executable(s), and loading in the data sources. Optionally, you may use Imagix 4D to manage the profile data sources, thereby supporting incremental measurements.

Sources of Profile Data

Imagix 4D supports several sources of run-time profile data for C and C++ source code. For embedded development, Testwell CTC++ is an instrumentation-based code coverage tool that can be used with any target. CTC++ is compiler-independent; other profile data sources are linked to the compiler used to build the executable. If you're compiling with gcc/g++, you can create gcov and gprof datafiles and then import them into Imagix 4D. Some native compiler environments include tcov and gprof in order to create similar datafiles. If you're using a pre-.NET versions of the Microsoft Visual C++ compilers, Imagix 4D accepts the profiler databases they can create.

Your choice of which data source to generate and load will depend upon which metric you want to see:

Coverage shows how completely each function has been exercised.
embedded compilerTestwell CTC++ required
gcc compilergcov required, gprof optional
other native compilertcov required, gprof optional
Visual C++ compilerprofiler (line coverage or line counting type) required

Time shows how much time was spent in each function.
gcc compilergprof required
other native compilergprof required
Visual C++ compilerprofiler (function timing type) required

Frequency shows how often each function was executed.
embedded compilerTestwell CTC++ required
gcc compilergprof required
other native compilergprof required
Visual C++ compilerprofiler (any function type) required

Compiling to Enable Profile Data

Generating profile data begins with the compile/build instrumenting the executable code and creating files to capture the profile results.

To make this happen with the gcov, tcov and gprof data sources, you need to set the appropriate flags when you compile your source code. Normally, the corresponding compile flags you'll use are:

gcov--coverage (or -fprofile-arcs -ftest-coverage prior to gcc 4.1.2)
tcov-a or -xa
gprof-pg (or -xpg in some native Unix compilers)

Certain of these compiler flags can not be set if you have set the -g flag. For more information about using the compiler flags, refer to the documentation for your compiler.

To generate profiler information under CTC++ and pre-.NET versions of Microsoft Visual C++, refer to their respective user guides.

Generating Profile Data

After you've recompiled with the appropriate flags set, you'll need to exercise your software in order to generate the profile data for Imagix 4D to examine.

This is done by running your executable, using whatever test cases you wish to examine. As you run your executables, results are automatically captured into the MON.dat file (CTC++), the .gcda/.da and gmon.out files (gcc), .d and gmon.out files (native Unix) or .pbt files (Visual C++).

Except for CTC++, if you're running Imagix 4D on the same platform where you ran your executables, Imagix 4D can collect the profile data directly from the resulting data files. Imagix 4D uses the native tools available on the platform, such as gprof or some of the Microsoft Visual C++ utilities, to help process the data files.

If you are using CTC++ or if you wish to perform cross-platform analysis of the profile data, Imagix 4D is still able to load in the data. In this case, you need to do some initial processing of the run-time data files on the executable's native platform. Imagix 4D is then able import the intermediate results on whatever platform it is running on.

The post-processing necessary depends on the type of profile data you have generated. The appropriate commands can be issued from the command line.

CTC++ (MON.dat)ctcpost MON.sym MON.dat -x xml_results_file
gcov (for each .gcda or .da file)gcov -b sourcefilename.gcda
tcov (.d files)no post-processing is necessary
gprof (gmon.out)gprof -b executable gmon.out > results_file
profile (executable_rootname.pbt)plist /t executable_rootname > results_file

Refer to the CTC++ user guide, gcov man page, gprof man page or Microsoft Visual C++ user guide for further information.

Importing Profile Data

You can use the Data Sources dialog (Project > Data Sources) to load the data sources.

There are restrictions on the order in which you load the data sources. The program structure information must be added, using one of the C/C++ Source Files approaches, before the profile information can be loaded. This is because Imagix 4D builds the profile information on top of the information it maintains about your software's functions and calling hierarchy. This is how, for example, Imagix 4D is able to convert gcov's file-related results into more meaningful function-related results. This also enables you to view each function's profile results as values in the Metrics display.

If you are importing gprof or profiler data, and are running Imagix 4D on the platform where the executable ran, there are two choices for loading in the profile data. Use gprof Data Files or MSVC Profile Data File if you wish to import the raw data; use gprof Result File or MSVC Profile Result File if you've already done the post-processing. For gcov, the choice of whether or not to do the post-processing manually is made within the Coverage Files settings. If you are doing cross-platform development, your choice will be automatically limited to importing the post-processed results.

Managing Profile Data Files

CTC++ has extensive functionality for combining results across multiple test case runs and test targets, and those are best managed through CTC++ itself. For the other profile sources, the functions of the Manage Profile Data dialog enable you to profile your executables across a series of test cases, store the results of the each run, and view the results for whichever run or combination of runs you're interested in.

This eliminates some of the complexity of dealing with the various profiling tools. For multiple (or incremental) runs, the tcov, gcov, gprof and MSVC profiler data collectors behave differently. With gprof and profiler, the data files are reset each time you run the executable. Therefore, at any point, gmon.out and executable.pdt contain just the profile data for your latest run. With gcov and tcov, the .gcda and .d files are not reset. As you make multiple runs of your executable, the results accumulate.

One of the Manage Profile Data functions enables you to reinitialize all of the tcov data files before executing a test case. This causes the gcov and tcov data files to reflect just the results for the subsequent test runs. In this way, you can track and analyze the coverage associated with the individual test cases. Another function in the dialog saves the current contents of profile data or results files.

Using these functions, you can run a series of test cases, reinitializing tcov data before each run and recording the results after each run. Then, you can use the Manage Profile Data dialog to specify which results you want to view. You're able to view the results for any of the stored runs, either individually or in combination.

There are a number of ways that you might use these capabilities. If you wanted to analyze the impact that particular software changes have on the performance of your code, you could compare the results of the same test case on different versions of the software. Alternatively, you might analyze the completeness of your testing by looking at the combined coverage across a whole series of test cases. Or you might optimize your testing by determining the incremental coverage achieved by specific test cases.