Source Code Metrics Analyzer

Overview

Starting Metrics Analysis

Metrics Analysis and Exceeding Limits

The Influence of Preprocessing on Metrics Analysis

The Relation Between Metrics and Static Code Analysis

Metrics Analysis and Different C Language Dialects

Metrics Analysis and Specific Function Calls

Metrics checked in DA-C

Overview

Considering the large amount of data involved, metrics analysis is carried out as a distinct process, should the user request it explicitly. Data compiled during the analysis is placed in the Metrics database, where it can later be accessed and used when generating metrics reports. Metrics analyze results can be examined visually by means of metrics reports, whose contents, as well as the form in which they are displayed, it is possible to adjust at will.

Starting Metrics Analysis

Metrics analysis is carried out immediately after Browser database source code analysis. Static code analysis and Source Code Metrics analysis can be started by means of either the Start > Build Database or the Start > Rebuild Database command. It is possible to turn metrics analysis off by clearing the Options > Software Metrics Analyzer > [x] Generate Source Code Metrics check box. Initially, the metrics analysis is turned off.

Metrics Analysis and Exceeding Limits

In calculating metrics, some of them may exceed the prescribed limits of the scope of acceptable values for a function, module, or group of modules. Should this happen, relevant warnings containing information on the parameter and function/module in question will appear on the Source Code Metrics tab of the Messages window.

You can disable warnings displayed when parameter values are exceeded for all types of parameters. In this way warnings not relevant to the project will not encumber the Message Logs. A warning that a particular parameter has exceed the prescribed value limits will appear only if the parameter in question has been selected on the General tab of the dialog box obtainable from the Options > Software Metrics Analyzer menu. Minimum and maximum suitable parameter values, when applied to modules, that is, functions, can be set on the Module, that is, Function tabs of this dialog box.

Apart from warnings about exceeding limits being displayed, unacceptable property values will be specially marked in metrics report graphics as well.

The Influence of Preprocessing on Metrics Analysis

Preprocessing is a procedure which directly precedes C code compiling and incorporates including header files, resolving conditional compiling, and performing macro expansion.

The content of header files does not directly influence the metrics of the module which includes these files.

Conditional compilation determines which part of the written code, considered in its entirety, is to be compiled. In determining metrics, the metrics analyzer considers only that part of the code which is to be compiled.

Macro expansion can also influence particular metrics, because macro expansion changes the form in which the code to be compiled will be displayed.

The Relation Between Metrics and Static Code Analysis

The metrics analyzer cannot recognize syntax errors in the code. Syntax errors are pinpointed by the static code analysis process, launched immediately prior to metrics analysis. Should static code analysis show that there are syntax or other errors in the program, correcting them prior to use or interpretation of metrics analysis results is recommended.

Metrics Analysis and Different C Language Dialects

The metric analyzer recognizes the differences between the different C language dialects supported by DA-C static code analysis. This is reflected in the different syntax of particular constructions, additional types of data, additional keywords, additional operators, and so on. As in the case of static code analysis, it is necessary to choose the correct dialect in which the source was implemented; otherwise, metrics data will not be valid.

Metrics Analysis and Specific Function Calls

Particular system calls and standard library functions, even if not a part of C language, can influence the course of program control. Examples would be exit() and longjmp(), which cause exiting of the current function (and probably other functions as well). The metrics analyzer considers these functions regular function calls. Using these functions can endanger the precision of metrics influenced by the number of exits from a function and metrics which count jump commands (for example, Cyclomatic Complexity depends on the number of exits from a function).

In order to determine property values with greater precision, you can, temporarily, substitute the specified function calls with equivalent C commands; for example, the return command.

Metrics checked in DA-C

Metrics in DA-C are organized into three groups, depending on the scope to which they belong:

1. Function metrics - values which relate exclusively to the contents of the function body.

2. Module metrics - values which relate to the contents of the module as a whole.

3. Group of modules metrics - total values obtained from a group of modules.

Function metrics have been described in detail in previous chapters. They are calculated only for a code contained within the function body.

Module metrics are calculated separately for a code contained within the module, excluding the contents of included files. The Maximal depth parameter is obtained as a maximum value of the "Maximal depth" parameter of all functions belonging to the module.

Group of modules metrics are obtained as corresponding module parameter value totals. The exceptions to this rule are the Function Points and Adjusted Function Points.

To follow is a list of metrics calculated for a project. For the benefit of greater clarity, the list has been divided into groups of related metrics, unlike in DA-C where the list appears alphabetically sorted.

Function Metrics

Metrics based on the number of lines of code (Line count metrics):

Lines

White lines

Comment lines

Executable lines

Lines with comments

Preprocessor lines

Metrics based on the number of statements in the code (Statement count metrics):

Compound statements

Jump statements

Declaration statements

Loop statements

Empty statements

Selection statements

Executable statements

Label statements

Expression statements

 

Code complexity metrics:

McCabe's Cyclomatic Complexity

Local variables

Maximal depth

 

Halstead metrics:

Halstead Volume

Halstead Length

Halstead Difficulty

Halstead Vocabulary

Halstead Intelligence Content

Halstead Programming Time

Halstead Language Level

Halstead Programming Effort

Operator metrics:

Operators per line

Operator weight per expression

Operators per operand

Operator weight per operand

Operators per token

Sum of weights

Module Metrics

Metrics based on the number of lines of code (Line count metrics):

Lines

White lines

Comment lines

Executable lines

Lines with comments

Preprocessor lines

Code complexity metrics:

Maximal depth

Global/Static variables

Metrics based on the number of statements in the code (Statement count metrics):

Statements

Number of functions:

Global/Static functions

Group of Modules Metrics

Metrics based on the number of lines of code (Line count metrics):

Lines

White lines

Comment lines

Executable lines

Lines with comments

Preprocessor lines

Number of Function Points (FP):

Function Points

Adjusted Function Points

Metrics based on the number of statements in the code (Statement count metrics):

Statements

Number of variable types used:

Global/Static variables

Number of functions and modules:

Global/Static functions

Number of modules