A Utility for Calculating Ada Source Code Metrics

GNATmetric is available as part of the GNAT Static Analysis Suite

GNATmetric helps you meet the reporting requirements of your software verification standard. It takes an Ada source code file as input, computes the necessary measurements, and generates a file containing the metrics data as output. Users can choose which metrics are reported.

Automated Metric Reporting

Working to a software development standard inevitably means calculating and reporting quality metrics on your code. GNATmetric automates that process for you.

GNATmetric includes calculations for a full range of metrics for line counts, syntax, complexity, coupling and contracts. Select the metrics you need to report. Start the calculation. GNATmetric provides you with a full report.

GNATmetric makes generating metrics for compliance with your standard fast and easy.

Gnatmetric pane3 icon
Gnatmetric pane3 icon2

An Aid in Reducing Code Complexity

GNATmetric can be used to investigate your code for various areas of complexity. The metrics generated can help you focus your efforts right where they’re needed, so you can improve the quality of your code base and your development process.

GNATmetric also helps you find areas of your code base that exceed the boundaries you've set for any of the metrics it calculates.

GNATmetric is a GNAT project-aware tool

GNATcheck can use project files in GNAT Project Manager to extract the metrics it needs to compute. This saves users time in configuring GNATcheck when it’s used in conjunction with GNAT Project Manager.

A Full Range of Metrics

Metrics computed by GNATmetric include:

Line metrics

Computed for each source file and for each of its eligible local program units*

  • Total number of lines

  • Total number of code lines (non-blank lines that are not comments)

  • Number of comment lines

  • Number of code lines containing end-of-line comments

  • Comment percentage: the ratio between the number of lines containing comments and the number of all non-blank lines, expressed as a percentage

  • Number of blank lines

  • Average number of code lines in subprogram bodies, task bodies, entry bodies, and statement sequences in package bodies

Syntax metrics

Computed for the outermost program unit and for each eligible local program unit*

  • LSLOC (Logical Source Lines Of Code)

  • Maximal static nesting level of inner program units

  • Maximal nesting level of composite syntactic constructs

  • Number of formal parameters

  • Public subprograms

  • All subprograms

  • Public types

  • All types

Complexity metrics

Computed for any program unit that is an executable body*

  • McCabe cyclomatic complexity

  • McCabe essential complexity

  • Maximal loop nesting level

  • Extra exit points (for subprograms)

  • Complexity introduced by control statements only (excluding short-circuit forms)

  • Complexity introduced by short-circuit control forms only

  • Total cyclomatic complexity (sum of the two previous values)

* Eligible local program units include:

  • Subprogram (and generic subprogram) bodies

  • Package (and generic package) specs and bodies

  • Task object and type specifications and bodies

  • Protected object and type specifications and bodies

Coupling metrics

Coupling metrics measure the dependencies between a given entity and other entities in the program. High coupling may signal potential issues with maintainability as the program evolves.

  • object-oriented coupling (for classes in the traditional object-oriented sense)

  • unit coupling (for all the program units making up a program)

  • control coupling (reflecting dependencies between a unit and other units that contain subprograms)

  • fan-out coupling (‘efferent’ coupling: the number of entities the given unit depends upon)

  • fan-in coupling (‘afferent’ coupling: the number of entities that depend on a given entity)

Contract metrics

  • Number of public subprograms with contracts

  • Number of public subprograms with postconditions

  • Number of public subprograms with complete contracts

  • McCabe complexity of public subprograms

Two Output Formats

GNATmetric can generate metrics reports in either of two selectable formats. The text (human-readable) format is the default. The alternative is XML.

When the text format is selected, GNATmetric generates a separate report file for each Ada source code input file (except when all the metrics selected are for the entire set of analyzed sources).

When the XML format is selected, GNATmetric places all the output data in a single file.

GNATmetric is available as part of the GNAT Static Analysis Suite