Main Content

Calculate code metrics (-code-metrics)

(Removed) Compute and display code complexity metrics

Using Code Prover to compute code metrics is no longer supported. Use Calculate code metrics (-code-metrics) in Bug Finder instead. For more information, see Version History.

Description

Specify that Polyspace® must compute and display code complexity metrics for your source code. The metrics include file metrics such as number of lines and function metrics such as cyclomatic complexity and estimated size of local variables.

For more information, see Compute Code Complexity Metrics Using Polyspace.

To maintain an acceptable level of software complexity during the development cycle, use the software complexity checkers. See Reduce Software Complexity by Using Polyspace Checkers.

Set Option

User interface (desktop products only): In your project configuration, the option is on the Coding Standards & Code Metrics node.

Command line and options file: Use the option -code-metrics. See Command-Line Information.

Why Use This Option

By default, Polyspace does not calculate code complexity metrics. If you want these metrics in your analysis results, before running analysis, set this option.

High values of code complexity metrics can lead to obscure code and increase chances of coding errors. Additionally, if you run a Code Prover verification on your source code, you might benefit from checking your code complexity metrics first. If a function is too complex, attempts to verify the function can lead to a lot of unproven code. For information on how to cap your code complexity metrics, see Compute Code Complexity Metrics Using Polyspace.

Settings

On

Polyspace computes and displays code complexity metrics on the Results List pane.

Off (default)

Polyspace does not compute complexity metrics.

Tips

If you want to compute only the code complexity metrics for your code:

A Code Prover analysis computes the stack usage metrics after the source compliance checking phase. If you stop a Code Prover verification before source compliance checking, the stack usage metrics are not reported.

Command-Line Information

Parameter: -code-metrics
Default: Off
Example (Bug Finder): polyspace-bug-finder -sources file_name -code-metrics
Example (Code Prover): polyspace-code-prover -sources file_name -code-metrics
Example (Bug Finder Server): polyspace-bug-finder-server -sources file_name -code-metrics
Example (Code Prover Server): polyspace-code-prover-server -sources file_name -code-metrics

Version History

expand all

R2024a: Removed from Code Prover

If you use the option -code-metrics in a Code Prover analysis, Polyspace issues a warning and the analysis ignores the warning. The workflow for computing code metrics has been removed from Code Prover. To compute code metrics other than stack usage, use Bug Finder. For instance, at the command line, replace this command:

polyspace-code-prover -sources file_name -misra-cpp all-rules
with this command:
polyspace-bug-finder -sources file_name -misra-cpp all-rules
To compute stack usage metrics, use the option Calculate stack usage (-stack-usage). See Migrate Code Prover Workflows for Checking Coding Standards and Code Metrics to Bug Finder.