Compute Code Complexity Metrics Using Polyspace
This topic describes how to compute all code complexity metrics and then review the ones that exceed specified thresholds. To see metric values only if they exceed thresholds, check for guidelines on software complexity. See Reduce Software Complexity by Using Polyspace Checkers.
Code complexity metrics are a set of numbers that quantify the complexity of your C/C++ program. For instance:
A function with a high cyclomatic complexity contains too many branches.
A function with a high number of
returnstatements has too many exit points.
Complex programs are difficult to debug, analyze, test and maintain. To avoid too much complexity, impose limits on the complexity metrics during coding.
Polyspace® does not compute code complexity metrics by default. To compute them during analysis, use the option Calculate code metrics (-code-metrics).
After analysis, the software displays project, file and function metrics on the Results List pane. You can compare the computed metric values against predefined limits. If a metric value exceeds limits, you can redesign your code to lower the metric value. For instance, if the number of called functions is high and several of those functions are always called together, you can write one function that fuses the bodies of those functions. Call that one function instead of the group of functions that are called together.
Impose Limits on Metrics
In the Polyspace user interface, use the Guidelines checkers to check for coding metrics that exceed a specified threshold. The Guidelines checkers correspond to the code metrics supported by Polyspace Bug Finder™. You can specify acceptable value for the supported code metrics and then check for code that exceed the specified value.
To enable the Guidelines checkers and specify thresholds, use the Checkers Selection dialog box. For details, see Reduce Software Complexity by Using Polyspace Checkers. For a list of Guideline checkers, see Guidelines.
Impose Limits on Metrics (Server and Access products)
In the Polyspace Access™ web interface, limits on code complexity metrics are predefined. In the Dashboard perspective, if you select Code Metric, a Code Metrics window shows the metric values and limits.
To find the limits used, see HIS Code Complexity Metrics.
See also Code Metrics Dashboard in Polyspace Access Web Interface (Polyspace Access).
See Also
Calculate code metrics (-code-metrics)