Metrics - overview and description
Column abbreviation in Standard Metrics view | Description |
---|---|
Code size | |
Variables size | |
Stack size | |
Calls | |
Tasks | |
Globals | |
IOs | |
Locals | |
Inputs | |
Outputs | |
NOS | |
Comments | |
McCabe | |
Prather | |
DIT | |
NOC | |
RFC | |
CBO | |
Elshof | |
LCOM | |
n1 (Halstead) | |
N1 (Halstead) | |
n2 (Halstead) | |
N2 (Halstead) | |
HL (Halstead) | |
HV (Halstead) | |
D (Halstead) | |
SFC branches | |
SFC steps |
Detailed description
Code size [number of bytes] ("code size")
Code size as number of bytes.
Variables size [number of bytes] ("variable size")
Variables size as number of bytes.
Stack size [number of bytes] ("stack size")
Stack size as number of bytes.
Number of calls ("calls")
Number of function block calls within the application.
Called in tasks ("tasks")
Number of tasks calling the function block.
Used different global variables ("Globals")
Number of different global variables used in the function block.
Number of direct address accesses ("IOs")
Number of IO access operations in the function block = number of all read and write access operations to a direct address.
Example:
The number of direct address access operations for the MAIN program is 2.
PROGRAM MAIN
VAR
OnOutput AT%QB1 : INT;
nVar : INT;
END_VAR
OnOutput := 123;
nVar := OnOutput;
Number of local variables ("local")
Number of local variables in the function block (VAR).
Number input variables ("inputs")
Number of input variables in the function block (VAR_INPUT).
Number output variables ("outputs")
Number of output variables in the function block (VAR_OUTPUT).
Number of statements ("NOS")
NOS: Number Of executable Statements
NOS = number of executable statements in the function block
Percentage of comments ("comments")
Comment proportion = number of comments / number of statements in a function block
For the purpose of this definition, statements also include declaration statements, for example.
Complexity (McCabe) ("McCabe")
Complexity = number of binary branches in the control flow graph for the function block (e.g. the number of branches in IF and CASE statements and loops)
Complexity of nesting (Prather) ("Prather")
Nesting weight = statements * nesting depth
Complexity of nesting = nesting weight / number statements
Nesting through IF/ELSEIF or CASE/ELSE statements, for example.
Depth of inheritance tree ("DIT")
DIT: Depth of Inheritance Tree
DIT = inheritance depth or maximum path length from the root to the class under consideration
Number of children ("NOC")
NOC: Number Of Children
NOC = number of child classes or number of direct class specializations
Response for class ("RFC")
RFC: Response For Class
RFC = number of methods that can potentially be executed, if an object of the class under consideration responds to a received message
The value is used for measuring the complexity (in terms of testability and maintainability). All possible direct and indirect method calls can be reached via associations are taken into account.
Coupling between objects ("CBO")
CBO: Coupling Between Objects
CBO = number of classes coupled with the class under consideration
The value is used to indicate the coupling between object classes. Coupling refers to a situation where a class uses instance variables (variables of an instantiated class) and the methods of another class.
Complexity of reference (Elshof) ("Elshof")
Complexity of reference = referenced data (number of variables) / number of data references
Lack of cohesion of methods (LCOM) ("LCOM")
Cohesion = pairs of methods without common instance variables minus pairs of methods with common instance variables
This cohesion value is a measure for the encapsulation of a class. The higher the value, the poorer the encapsulation. Reciprocal method and property calls (without init or exit) are also taken into account.
Halstead ("n1","N1","n2","N2", "HL", "HV", "D")
The following metrics are part of the "Halstead" range:
- Number of different used operators - Halstead (n1)
- Number of operators - Halstead (N1)
- Number of different used operands - Halstead (n2)
- Number of operands - Halstead (N2)
- Length - Halstead (HL)
- Volume - Halstead (HV)
- Difficulty - Halstead (D)
Background information:
- Relationship between operators and operands (number, complexity, test effort)
- Based on the assumption that executable programs consist of operators and operands.
- Operands in TwinCAT: Variables, constants, components, literals and IEC addresses.
- Operators in TwinCAT: keywords, logical and comparison operators, assignments, IF, FOR, BY, ^, ELSE, CASE, case label, BREAK, RETURN, SIN, +, labels, calls, pragmas, conversions, SUPER, THIS, index access, component access etc.
For each program the following basic parameters are formed:
- Number of different used operators - Halstead (n1),
Number of different used operands - Halstead (n2): - Number of different used operators (h1) and operands (h2); together they form the vocabulary size h.
- Number of operators - Halstead (N1),
Number of operands - Halstead (N2): - Number of total used operators (N1) and operands (N2); together they form the implementation class N.
- (Language complexity = operators/operator occurrences * operands/operand occurrences)
These parameters are used to calculate the Halstead length (HL) and Halstead volume (HV):
- Length - Halstead (HL),
Volume - Halstead (HV): - HL = h1* log2h1 + h2* log2h2
- HV = N* log2h
Various indicators are calculated from the basic parameters:
- Difficulty - Halstead (D):
- Describes the difficulty to write or understand a program (during a code review, for example)
- D = h1/2 *N2/h2
- Effort:
- E = D*V
The indicators usually match the actual measured values very well. The disadvantage is that the method only applies to individual functions and only measures lexical/textual complexity.
Number of SFC branches
If the function block is implemented in the Sequential Function Chart language (SFC), this code metric indicates the number of branches in the function block.
Number of SFC steps
If the function block is implemented in the Sequential Function Chart language (SFC), this code metric indicates the number of steps in the function block.