Calculate C/C++ Code Profiling Metrics on Target in Polyspace Platform User Interface
Using Polyspace® Test™, you can calculate C/C++ code profiling metrics, such as code coverage, execution time, and memory use:
The metric
Code Coveragemeasures how much of your code is covered by the existing test cases. Measure the value of different code coverage metrics by using Polyspace Test and add appropriate test cases to achieve your desired level of coverage. Polyspace Test calculates code coverage for standard metrics. See Review Code Profiling Results.The metric
Execution Timecomputes the time required to execute the different callable entities of your code. SeeExecution Time.The metric
Memory Usemeasures how the callable entities use the available stack memory. SeeMemory Use.
To calculate these metrics on a target, you can follow one of these two possible workflows:
Using a Polyspace Platform project — If you have a Polyspace Platform project (
.psprjx) containing your source files and tests, you can perform these calculations on your target hardware by registering a target in the project. To register a target, use a registration file, which is a MATLAB® file that sets up the connection between your target and Polyspace Test. You can execute this workflow either in the Polyspace Platform user interface or by using the Polyspace Test command-line interface.Without using a Polyspace Platform project — If you have xUnit API-based tests that you link with your source files using your own toolchain, then you can perform these calculations on your target hardware without requiring a Polyspace Platform project. In this workflow, you cross-compile your source and tests for the hardware board using your own cross-compiler.
This example shows how to calculate the code profiling metrics on target hardware by using a Polyspace Test project in the Polyspace Platform user interface. To do these calculations without using the Polyspace Platform user interface, see:
Prerequisites
To perform this workflow:
You require a valid Polyspace Platform project containing source files and tests. For this workflow, your project must contain at least one test.
You must have created a valid registration file for your target. For more information on target registration files, see Run C/C++ Tests on Target in Polyspace Platform User Interface.
Your target registration file might require additional information beyond the basic details, depending on the type of code profiling you want to perform. For example:
If you want to calculate execution time on a target, the target registration file must define appropriate timer functions for your target.
If you want to calculate memory use on a target, the target registration file must define functions that can locate the current position of the stack pointer on your target.
You must have set up a host compiler for use with Polyspace Test. A host compiler is required for on-target code profiling, as certain generated source files need to be compiled on the host before cross-compiling your sources for the specified target. For more information on host compiler requirements, see Specify C/C++ Compilers for Testing in Polyspace Platform User Interface.
You can calculate only one of the code coverage, execution time, or memory use metrics at a time. Calculate these metrics sequentially if you need more than one of the metrics.
Calculate Code Profiling Metrics
When you run your tests on a target by using a Polyspace Platform project, Polyspace builds an appropriate test executable for your target, establishes communication with the target, runs the test executable on the target, collects data, and creates the results files. You do not have to manually build the test executable or manage communications with the target board.
Configure Project
To allow Polyspace Test to build executables for your target and to allow communication with the target, configure your project:
Open the Configuration pane by clicking Configuration in the Projects pane.
In the Configuration pane, under the Build tab, locate the option Target board name (Testing) in the Target & Compiler node. Open the Manage Boards window by clicking
.To add your target, select Add a board. Navigate to your registration file and select the appropriate
Mfile. If your registration file is valid, your target appears in the list of boards.Select your target as the Target board name (Testing) options.
After specifying your target, specify the code profiling metric that you want to calculate:
To calculate code coverage, in the Profiling section of the toolstrip, select Code Coverage.
To calculate the execution time, select Execution Time.
To calculate the memory use, select Memory Use.
Calculate Code Profile Metrics
After configuring your project, you can calculate the code profile metrics by building and running your project:
Build your project by clicking Build Project at the toolstrip. Polyspace Test first instruments the source files with appropriate macros to enable code profile calculation. Then, Polyspace Test uses the toolchain defined in your registration file to compile the instrumented source into a test executable appropriate for your target.
Run the tests by clicking Run Tests at the toolstrip. Polyspace Test uses the communication interface implemented in the registration file to execute the instrumented test executable on the target and gathers the test results.
The results appear in the Results pane.
The Polyspace Platform user interface does not support viewing the execution time and memory use metrics. When you open these results in the Polyspace Platform user interface, the results are converted into an HTML report and then the report opens in your default browser.
Unregister Target
After completing the calculation, you can unregister the target board. To unregister the target board:
In the Configuration pane, click
near the option Target board name (Testing) to open the Manage Boards window. Click Unregister a target. Navigate to your registration file and select the appropriate
Mfile. If your registration file is valid, your target is removed from the list of boards.