Code Profiling Using Self-Managed Builds
R2026bIf you author C/C++ tests using the Polyspace Test xUnit API, you can profile your source files and tests to calculate code coverage, code execution time, or memory use. Instrument your source code at compile time, then run the tests with polyspace-test -monitor to collect profiling
results:
polyspace-code-profiler -instrument -instrum-dir instrums -cov-metric-level decision -- gcc -c src.c
gcc -c test.c <PSTEST_SOURCE> <PSTEST_INCLUDE> # <PSTEST_SOURCE> is pstest.c
gcc src.o test.o pstest.o <PSTEST_LIB> -o testrunner
polyspace-code-profiler -run -instrum-dir instrums -results-dir results -- ./testrunner<PSTEST_SOURCE>, <PSTEST_INCLUDE> and <PSTEST_LIB>, see Set Up C/C++ Testing and Code Profiling Using Self-Managed Builds.
System Commands
polyspace-code-profiler | (System Command) Profile your source code for calculating C/C++ code coverage, code execution time, and memory use |
| (System Command) Monitor execution of C/C++ xUnit tests and retrieve test and code profiling results |
polyspace-test -dccc | (System Command) Generate Data Coupling and Control Coupling (DCCC) coverage data from static and dynamic results (requires Polyspace Code Prover) |
CMake Functions
pstest_add_profiling_runtime | (CMake) Create target for compiling a custom run-time library for code profiling |
pstest_instrument_target | (CMake) Instrument a target for profiling |
pstest_add_convert_target | (CMake) Create target for converting test or code profiling results to standard Polyspace Test format |
pstest_add_report_target | (CMake) Generate XML and HTML reports from test or code profiling results |
MATLAB Functions
pstest.exportToPolyspaceProfilingResults | (MATLAB Function) Export coverage results from Simulink Coverage, Simulink Test, or MATLAB Test to Polyspace Test |
Topics
- Set Up C/C++ Testing and Code Profiling Using Self-Managed Builds
Define environment variables that point to locations of Polyspace® Test™ files required for compiling xUnit tests or code profiling macros.
- Calculate C/C++ Code Coverage Using Self-Managed Builds
Calculate and review the code coverage of test cases authored using the xUnit API.
- Calculate Execution Time and Memory Use of C/C++ Code Using Self-Managed Builds
Calculate the execution time and memory use metrics of your code using the
polyspace-code-profilercommand to identify possible bottlenecks. - Calculate Code Profiling Metrics in Microsoft Visual Studio
Calculate and review the code coverage metrics of your xUnit API-based test cases in a Microsoft® Visual Studio® project. Profile the execution time and memory use of functions in your code to determine bottlenecks.
- Calculate Code Profile by Using Makefile
Modify the makefile to instrument your sources and xUnit API-based tests for calculating code profile.
- Calculate Code Coverage of xUnit API-Based Tests Using CMake
Use Polyspace Test CMake package to manage profiling workflow.
- Calculate Coverage of Data Couplings and Control Couplings (DCCC) in C/C++ Code
Determine to what extent your tests cover cross-component data and control flows in your code base.
- Create Library for Code Profiling Using Self-Managed Builds
Create library containing definitions of code instrumentation macros for cases where precompiled libraries included with Polyspace Test are not compatible with your toolchain.
- Merge C/C++ Code Coverage Results from Build Variants
Collect code coverage results from different build variants and aggregate them into a single combined result.
- Changes to Self-Managed Build Workflows in Polyspace Test in R2026b
Find all changes you need to make in your build scripts starting R2026b for self-managed builds using Polyspace Test.
Troubleshooting
Troubleshoot Code Profiling for Polyspace Test xUnit API-Based Tests
Troubleshoot calculating code coverage, execution profiling, and stack memory profiling of xUnit based tests.