How To Use Gcov with TimeStorm for code coverage of C/C++ Programs
Gcov is a source code coverage analysis and statement-by-statement profiling tool. Gcov generates exact counts of the number of times each statement in a program is executed and annotates source code to add instrumentation. Gcov comes as a standard utility with the GNU Compiler Collection (GCC) suite. For more information, please refer to https://gcc.gnu.org/onlinedocs/gcc/Gcov.html
This document will show How to Use Gcov with TimeStorm. To run Gcov in TimeStorm.
- Open your C/C++ Project. If you want to learn how to use gcov, go to Learn Gcov by creating a C Project using the Gcov sample section below.
- Add Gcov flag to Compiler and Linker.
- Build Project
- Set up Gcov configuration for a Remote target
- Start Gcov profiling and view the results in Gcov editor.
1. Open your C/C++ Project:
Open your project using project explorer (we are using a C/C++ project created using the gprof sample) as shown below.
2. Add Gcov flag to Compiler and Linker:
Make sure you are in the C/C++ perspective (Window → Perspective → Open Perspective → Other → C/C++) in TimeStorm. Right click your Project, and select Properties. Expand C/C++ Build > Settings, and select the Tool Settings tab. Select Miscellaneous under GCC C/C++ Compiler and GCC C/C++ Linker, append '-ftest-coverage -fprofile-arcs' to the already existing flags as shown below.
This will make a
Note: If the “-ftest-coverage -fprofile-arcs” flag already exists in the GCC C/C++ Compiler and GCC C/C++ Linker don’t add it again.
3. Build Project:
Right click your project, and select Build Project. There should be a .gcno file generated as a result of building the project. Verify this file exists by expanding the
4. Set up Gcov configuration for a Remote target:
A TimeStorm Profiling Tools Configuration is a collection of settings that are required to download and profile an application. The TimeStorm Profiling Tools Configuration is persistent and can be launched multiple times to profile the application. To profile the application on the remote target, you have to create a TimeStorm Profiling Tools Configuration. To create a TimeStorm Profiling Tools configuration, right click on the project and click on TimeStorm Profiling Tools → Code Coverage as shown below.
Click on “Code Coverage” option and this will open the “TimeStorm Profiling Tools Configurations” dialog as shown below.
Note that an entry is created under TimeStorm C/C++ remote category with the project name appended with the Active build configuration, and other values are filled in with the default values that should work. The Timestorm Profiling Tools Configurations entries are categories in different tabs on the right hand panel and are explained below. To profile the application, mostly you have to just select the remote target on the target tab and click the Profile button.
Main Tab:
In the Main tab, you can change the C/C++application by searching the project. You can change the project too if you want to use this configuration for a different project.
Arguments tab:
In the Arguments tab, you can specify the arguments to be passed to the application program. The remote working directory is set as ‘.’, which means that the directory specified in the target definition is used as the working directory.
The command to be executed is filled in. Un-check ‘Use default command’ to change this value. Keep in mind the directory structure on your target when constructing this command. For example, if you have copied your application file to a directory named /apps but you want to execute it from a working directory named /home/test, you must include the path to your application in your command.
For example: ../../apps/my_app
Environment tab:
In the ‘Environment’ tab, you can set environment variables for the target.
The panel shown above contains the following buttons:
Add — Click the ‘Add’ button to create a new entry, and the ‘New Environment Variable’ dialog will appear, as shown below. Click the ‘Variables’ button to select the variables that you want to use. Then, click ‘OK’ twice.
Select — Click the ‘Select‘ button to import environment variables from the host file system.
Edit — To change an entry, select it from the list, and click the ‘Edit’ button.
Remove — To delete an entry, select it from the list, and click the ‘Remove’ button
Copy — To copy environment variables and values, select if from the list, and click the ‘Copy’ button.
Paste — To paste environment variables and values, click the ‘Paste’ button.
Source tab:
Source Lookup Path — This field shows the project being run, as well as any projects that it references.
Add — You can add arbitrary source file locations by using the Add button. These locations are searched after the generic locations, from the top to the bottom item in order.
Edit, Remove, Up, Down — The other buttons to the right of the list allow you to edit, remove, or reorder the list items, and to restore the default information.
Search for duplicate source files on the path — Selecting this checkbox causes TimeStorm to notify the user if it is unable to determine which source file corresponds to an executing binary file. For example, if you have two source files with the same filename in different directories of the search path, TimeStorm is unable to determine which file is related to the binary file with that name. If this checkbox is selected, TimeStorm displays a message and asks the user to select which file to use. This checkbox is not selected by default.
Target tab:
The Target tab shown below, allows you to select the hardware target used when you Profile the application.
In the Target tab, use the drop-down list to select a hardware target that you have already created. If you have not yet created a hardware target or want to change the settings for an existing target, click ‘Manage targets’ to open the Hardware Targets management utility.
Download Files tab:
In the ‘Download Files’ tab, you can select the files that TimeStorm transfers to your target. The application that has to be downloaded is already listed. You can use this panel to download additional files to your target, along with your application.
The application specified in the File field is listed as [Target Program]. This is the application that will be a profiling. You can change where it is downloaded by selecting it and clicking Edit.
If the program links in shared libraries, then these libraries will be downloaded to the target as well and the Files field is listed as [Target Program and Libraries]. These libraries will be downloaded to the same location as the target program. To download the program and libraries to separate locations, remove the default entry and re-add each as a separate entry.
This panel contains the following buttons:
Add File – Use the ‘Add File’ button to specify additional files to transfer, along with the application. These files are transferred every time you transfer the application file.
Edit – To change where the application (or any other file in this list) is installed, select it and click ‘Edit’ to change its destination directory.
Remove – To eliminate a file from the items to download, select it in the list and click the ‘Remove’ button.
Download Now – The ‘Download Now’ button copies files immediately, without running the application.
Restore Default – The ‘Restore Default’ button resets the panel to its initial state (download only the application and its libraries).
NOTE: Downloaded files overwrite any identically named files on the target without giving a warning. TimeStorm will not create destination directories on the target, so be sure to create them before launching the configuration.
Common tab:
The ‘Common’ tab, sets options for sharing this TimeStorm Profiling Tools Configuration among multiple projects.
The options with the Common tab include:
Local File — By default, TimeStorm Profiling Tools Configurations are saved with the workspace state files, so they can only be used with projects in the current workspace. (This setting corresponds to the ‘Local file’ radio button on this panel.) However, you can make the configuration available for use in other workspaces by choosing the ‘Shared file’ radio button.
Shared File — When you select this option, the TimeStorm Profiling Tools Configuration is saved as a .launch file that can be imported into another TimeStorm workspace. Optionally, you can specify a different location for the file so that it is more easily accessible to multiple projects.
Display in Favorites Menu — You can select whether to include this TimeStorm Profiling Tools configuration on the context menu. For example, if you select the ‘TimeStorm Profiling Tools’ checkbox, the TimeStorm Profiling Tools configuration always appears in the Profiling History’ submenu.
You can choose to include the TimeStorm Profiling Tools Configuration in either menu, both menus, or neither menu.
Launch in Background — Selecting the ‘Launch in background’ checkbox causes this TimeStorm Profiling Tools configuration to run as a background thread. Running as a background thread is the default value. Clear this checkbox if you want to run in the foreground, along with other TimeStorm processing.
5. Start Gcov profiling and view the results in Gcov editor:
After setting the values in all the tabs, click the Profile button at the bottom of the TimeStorm Profiling configuration dialog. This will connect your host to your target, download the application to the target and execute the application on the target. The commands executed on the target and the program output progress are displayed in the console view.
After your program successfully runs on your target, a .gcda file will be emitted in the /home/* directory on your target. And automatically copy this .gcda from your target to your local TimeStorm project directory. Double click the .gcda file to open it. Verify that the binary specified in the Gcov - Open coverage results... window and select OK to open Coverage results. You will now be viewing coverage information from your previous target program run in TimeStorm as shown below. For more information, please refer to https://wiki.eclipse.org/Linux_Tools_Project/GCov/User_Guide#Gcov_main_view
<>
Learn Gcov by creating a C Project using the Gcov sample:
To create a C/C++ project, open the ‘New Project’ wizard by choosing File → New → Project from the main menu OR click the ‘New’ button and use the drop-down menu to the right of the button to choose ‘Project’ as shown below.
Expand C/C++ , choose a C/C++ Project and click Next. To illustrate the Sample Gcov Project (Samples → Gcov).
Project page
- Enter a Project Name.
- Under the ‘Project Type’ heading, expand Samples and select Gcov project.
- Under the Toolchains heading select the TimeStorm Cross-Compile Toolchain.
Click ‘Next’ to bring up the ‘Basic Settings’ as shown below.
Basic settings page
On this page, set the basic properties of the project like Author, Copyright notice, Greeting message, and Source (where the project source files are to be stored within the project).
Select build configuration page
Build Configuration is a set of pre-defined compiler and linker settings that are used to build a project.
By default, TimeStorm creates three Build Configurations for new projects:
Debug — This setting performs no code optimization and attaches complete debugging information. These settings are designed to make debugging as easy as possible.
Release — This setting has the highest compiler code optimization settings. The output will not include any debugging symbols. Code compiled with this configuration is ready for production use.
GnuProfiler — This setting builds the software with debugging information as well as code to collect profiling information via GNU gcov.
You can change the build configuration settings before creating the project by clicking the ‘Advanced Settings…’ button. You can also change these settings after creating the project.
Click Next to continue.
Select SDK page
The Select SDK page show below allows you to choose the SDK you want to use with the project. Select the SDK Type and then choose the SDK.
Click Finish to create and exit the wizard. The new project is created and displayed in the Project Explorer view as shown below.
After creating the Sample Gcov Project, follow the above steps (Step2: Add Gcov flags to Compiler and Linker to your c/c++ project, Step3: Build Project, Step4: Set up Gcov configuration for a Remote target, Step5:Start Gcov profiling and view the results in Gcov editor) to run Gcov Profiling.