home_button product_button service_button support_button download_button whats_new_button company_button
Metrics4CTM, Metrics4FORTRANTM, Metrics4PascalTM,
Metrics4ProjectTM, and Metrics2GIFTM User's Guide

Version 3.2


TABLE OF CONTENTS

1. Introduction

2. Metrics4C, Metrics4FORTRAN AND Metrics4Pascal User Interface

3. Metrics4Project User Interface

4. Metrics2GIF User Interface

5. Running Software Metrics On A Daily, Weekly Or Monthly Basis

6. Integrating Software Metrics Into The +1Environment

7. Software Metrics Defined

8. Conclusion

9. Additional Information

LIST OF FIGURES

Figure 7-1. Fan Out Metric Example


1. Introduction

Metrics4CTM, Metrics4FORTRANTM, and Metrics4PascalTM calculate software metrics for individual modules or for the entire project. These tools run interactively or in the background on a daily, weekly, or monthly basis. The software metrics calculated for an individual module include:

  • Lines of code
  • Number of embedded SQL lines of code
  • Number of blank lines
  • Number of comment lines
  • Total number of lines
  • Number of decision elements
  • Cyclomatic complexity
  • Fan out

The above values are then summed to provide their respective project metrics. In addition, other project metrics calculated include:

  • Average project cyclomatic complexity
  • Project fan out metric (with and without leaf nodes)
  • Total number of procedures and functions
  • Total number of source code and header files
  • Lines of code in source code and header files
  • Total number of source code files unit tested
  • Total number of SQL statements
  • Lines of code unit tested
  • Percent of files unit tested
  • Integration Test Percentage

The Integration Test Percentage (ITP) provides a numeric value indicating how much of the project's source code has been tested and can be used to better prepare for Formal Qualification Testing (FQT).

Metrics4ProjectTM displays the number of open, closed, and total number of change requests organized by status, priority, category, class, and longevity. All change requests or only those change requests satisfying the last change request query are displayed.

Metrics2GIF generates graphs in GIF format that can be viewed using a web browser.

2. Metrics4C, Metrics4FORTRAN And Metrics4Pascal User Interface

The command syntax for Metrics4C, Metrics4FORTRAN, and Metrics4Pascal is:

    metrics4c [-acDfFimnpqrsvV] filename [...]
    metrics4c [-acDfFimnpqrsvV][-t | -%][-w][-# | -,] -l [filename]
    metrics4c [-acDfFimnpqrsvV][-t | -%][-w][-# | -,] -d [directory_name]

where:

    -a
    Display acronym list at end of report.
    -c Run Metrics4C (default). Alias: metrics4c.
    -D Date output file. Write output to metrics.YYYYMMDD file.
    -d Calculate metrics for files listed in file "../metrics/metric.files".
    -d directory_name Calculate metrics for files listed in file: "directory_name/metrics/metric.files". The directory_name specifies the name of a +1Environment project directory.
    -f Run Metrics4FORTRAN. Alias: metrics4fortran.
    -F Run Metrics4FORTRAN. The source code can contain preprocessor commands. Alias: metrics4Fortran.
    -i Display system information and license file.
    -l Calculate metrics for files listed in file "metric.files".
    -l filename Calculate metrics for files listed in file filename, e.g., in file "/home/john/files".
    -m Verbose mode option. Displays metrics as calculated.
    -n Do not display metrics report on screen.
    -p Run Metrics4Pascal. Alias: metrics4pascal.
    -q Display number of SQL statements and SQL lines of code. Counts EXEC SQL or $EXEC SQL statements in source code.
    -r Generate and display metrics report (default), e.g., "metrics.981220".
    -s Generate metrics and append an entry to the "metrics.totals" summary file. If the "-d" option is used, the output is saved in the ../metrics/metrics.totals file.
    -t or -% Calculate test metrics including the number of files unit tested, lines of code unit tested, percent of files unit tested, and Integration Test Percentage (ITP).
    -v Verbose mode option. Display function calls.
    -V Verbose mode option. Display source code.
    -w [L|C[99]] Flag warning if lines of code (L) and/or cyclomatic complexity (C) value exceeds a specified maximum (e.g., -wL150 or -wC15).
    -# or -, Use the '#' or ',' character to separate fields in the "metrics.totals" file. This option is supported to make it easier to import data contained in the "metrics.totals" file into a spreadsheet program. By default, the tab character is used to separate fields in the "metrics.totals" file.
    filename [...] Calculate metrics for one or more files. Each file is specified on the command line.

When the "-l" or "-d" options are specified, two files are created or updated: a metrics report, which can be presented to management, and a metrics summary file. The metrics report file is named metrics.project. If the "-D" option is specified, the metrics report file is named metrics.YYYYMMDD, where YYYY stands for year, MM for month, and DD for day. For example, report "metrics.20040116" is generated on January 16, 2004. The metrics summary file is named "metrics.totals". The metrics summary file can be read by a spreadsheet program or by Metrics2GIF to graphically display the metrics data over a period of time.

By default, the metrics report is always generated and displayed on the screen. Two exceptions are when the "-n" and "-s" options are specified. The "-n" option prevents the generated report from being displayed on the screen. The "-s" option only appends an entry to the metrics summary file. To display the metrics report and append an entry to the metrics summary file, both the "-r" and "-s" options need to be specified.

When any of the verbose options are selected (-m, -v, or -V), the verbose output is written to the standard output and not into the actual report.

If the "-v" option is selected and a file listed in "metric.files" does not exist (e.g., file List_Records.c), the metrics program will prompt you:

    WARNING: Cannot read file List_Records.c.
    Check to see if file exists.
    Do you want to continue Metrics4C? (y/n):

If the "-v" option is not selected, a warning message is displayed in the report itself.

If preprocessor variables are used in the source code (e.g., #ifdef VARIABLE_NAME), these variables can be defined by listing each variable in the file "ifdefs". If this file exists, the listed variables are read in and are used when parsing the source code. The "ifdefs" file needs to exist in the directory where the metrics results are stored. For example, if running "metrics4c -l", the "ifdefs" file needs to be in the current directory. If running the command "metrics4c -d", the "ifdefs" file needs to be in directory ../metrics. And if running "metrics4c -d /home/john/medic", the "ifdefs" file needs to be in directory /home/john/medic/metrics.

When the "-t" or "-%" option is specified, the list of files stored in "metric.files" or another specified name must contain either a 'U' for unit tested, an 'N' for not unit tested, or 'H' for header file. The syntax for a single line in the "metric.files" is "filename <TAB><U | N | H><NL>", where <NL> represents the new line character ('\n'). The syntax for each line in the "metric.files" when the "-t" or "-%" is not specified is "filename<NL>".

Finally, the "-w" option flags a warning if the lines of code or the cyclomatic complexity value exceeds a specified maximum. Examples for the warning option are:

    -w Flag a warning if any function exceeds the maximum lines of code and/or exceeds the maximum cyclomatic complexity value. The default maximum values are 150 lines of code and 10 cyclomatic complexity per procedure or function. These values are read from the "warning_defaults" file.
    -wL Flag a warning if any function exceeds the maximum lines of code. The maximum lines of code is read from the "warning_defaults" file.
    -wL200 Flag a warning if any function exceeds 200 lines of code. Any number can be specified.
    -wC Flag a warning if any function exceeds the maximum cyclomatic complexity value. This value is read from the "warning_defaults" file.
    -wC15 Flag a warning if any function exceeds a cyclomatic complexity value of 15. Any number can be specified.

If a procedure or function does exceed the maximum, a 'W' is placed to the right of the value in the metrics.project or metrics.YYYYMMDD report. Also, a new file named "warnings.YYYYMMDD" is created. In the warnings file, only the function names and their respective values that exceeded the maximum are listed. The "warning_defaults" file contains:

    150-- Maximum Lines of Code Per Procedure/Function
    10 -- Maximum Cyclomatic Complexity Value Per Procedure/Function

The default values in this file can be modified by the project administrator.

2.1 listfiles User Interface

When the "-l" or "-d" option is specified, the contents of the file "metric.files" or the specified filename can be edited by hand, created using the ls or find command, or if using +1Environment, created using the listfiles command. For example, to calculate software metrics for all header (".h") and Pascal source code (".p") files located in the current directory, type:

    ls *.h *.p > metric.files; metrics4pascal -l

This creates file "metric.files" containing a list of all ".h" and ".p" files in the current directory, which is then read in by the metrics4pascal program.

To calculate software metrics for all header (".h") and C source code (".c") files located below a project directory (e.g., project SMP), type:

    find /projects/SMP -name SCCS -prune -o \( -name '*.c' -o -name '*.h' \) -print > met.files | metrics4c -lrs met.files

This command creates file "met.files", whose contents contains all ".c" or ".h" file names not located under any SCCS directories. There must be a space character after the "\(" and before the "\)" symbols. The generated file, mets.file, is read in by the metrics4c program.

If using the +1Environment, the command syntax for the listfiles command is:

    listfiles [-p project_name] [-t or -%] project_directory

where:

    -p project_name Specifies the project name if different than project_directory.
    -t or -% Indicates whether the file is unit tested or is a header file.
    project_directory Specifies the pathname to a +1Environment project.

The listfiles command creates file "metric.files" in the directory "project_directory/metrics". The "metric.files" contains a current listing of all files defined in a +1Environment project. If the "-t" or "-%" option is specified, listfiles appends to the end of each filename whether the file is unit tested, is not unit tested, or is a header file. This information is used to generate the test metrics, such as the Integration Test Percentage.

The "-p" option is necessary when calculating software metrics for files not in the baseline directory. For example, to list files only in johns_workspace directory for project_ABC, the command is:

    listfiles -p project_ABC /home/john/johns_workspace

To list all files in the baseline directory, the command is simply:

    listfiles /home/project/project_ABC

since the project name and project directory name are the same.

2.2 Metrics4C, Metrics4FORTRAN And Metrics4Pascal Examples

The following examples illustrate the metric options. If you only have one metric product, say Metrics4C, you can switch the command in all of these examples with the metrics4c command. The options in the examples are still valid and the corresponding output reflective of the actual output you would see if you were to run the same command.

1. Command:

    metrics4c

Action:

Displays the Metrics4C help message. The following message is displayed on the screen.

    To run Metrics4C, Metrics4FORTRAN, or Metrics4Pascal, type:
    
      metrics4c [-acDfFimnpqrsvV] filename [...]
      metrics4c [-acDfFimnpqrsvV][-t|-%][-w][-#|-,] -l [filename]
      metrics4c [-acDfFimnpqrsvV][-t|-%][-w][-#|-,] -d [dir_name]
    
    where:
    
      -a  Display acronym list at end of report.
      -c  Run Metrics4C (default).  Alias: metrics4c.
      -D  Date output file.  Write output to metrics.YYYYMMDD file.
      -d  Calculate metrics for files listed in "../metrics/metric.files".
      -d dir_name Calculate metrics for files listed "dir_name/metrics/metric files".
      -f  Run metrics4fortran.
      -F  Run metrics4Fortran.  Source code may contain preprocessor
      commands.
      -i  Display system information and license file.
      -l  Calculate metrics for files listed in "metric.files".
      -l filename Calculate metrics for files listed in "filename".
      -m  Verbose mode.  Display metrics as calculated.
      -n  Do not display metrics report on screen.
      -p  Run metrics4pascal.
      -q  Display number of SQL statements and SQL lines of code.
      -r  Generate metrics report (default).
      -s  Generate metrics and append an entry to the "metrics.totals"
      summary file.
      -t or -% Calculate test metrics.
      -v  Verbose mode.  Display function calls.
      -V  Verbose mode.  Display source code.
      -w[L|C[99]]  Flag warning if the lines of code or cyclomatic complexity
      value exceeds specified maximums.
      -# or -, Use the '#' or ',' character to separate fields in the
      "metrics.totals" file.
    
    Please try again.
    
    Copyright © 1997-1998 +1 Software Engineering.  All Rights Reserved.
    

2. Command:

    metrics4c -X

Action:

Displays the above help message and indicates that 'X' is an invalid option.


3. Command:

    metrics4Fortran inverse.F

Action:

Displays software metrics for inverse.F, a single FORTRAN function. The file "metrics.project" is created and displayed on the screen using the cat command. The column header displays the name of the file, the number of lines of code (LOC), the number of comment lines (#Comments), the number of blank lines (#Blanks), the total number of lines (#Lines), the number of decision elements (#DE), the cyclomatic complexity (v(g)), and the fan out (FO) for file inverse.F. The total number of lines (#Lines) is equal to the sum of LOC + #Comments + #Blanks. (These and the other metrics are explained in section 6 of this user's guide.) In this example, file "metrics.project" contains:

                                 PROJECT METRICS
                          Wednesday -- December 28, 2004
    
    
    File            LOC      #Comments     #Blanks     #Lines    #DE    v(g)    FO
    inverse.F       148             12          10        170      6       7     2
    Totals          148             12          10        170      6       7     2
    
    
    Number of Procedures/Functions = 1
    
    Number of Source Code Files   = 1
    Number of Header Files        = 0
    Total Number of Files         = 1
    
    LOC in Source Code Files      = 148
    LOC in Header Files           = 0
    Lines of Code (LOC)           = 148
    
    Average Cyclomatic Complexity = 7.00
    Average Fan Out With Leafs    = 2.00
    Average Fan Out Without Leafs = 2.00
    

4. Command:

    metrics4c -D kermit.c

Action:

Displays software metrics for file kermit.c, a single file that contains several C functions. Kermit is a file transfer protocol. If run on January 29, 2004, the file "metrics.20040129" is created and displayed on the screen. Actual output follows.

                              PROJECT METRICS
                        Thursday -- January 29, 2004
    
    File               LOC   #Comments    #Blanks   #Lines    #DE   v(g)    FO
    kermit.c
      main()           217         129         67      413     46     47     5
      sendsw()          23           8          4       35     11     12     5
      sinit()           27           5         13       45     10     11     5
      sfile()           46           5         14       65     16     17     5
      sdata()           25           5          9       39      9     10     3
      seof()            30           5          9       44     12     13     2
      sbreak()          23           5          8       36      8      9     2
      recsw()           19           5          5       29      7      8     3
      rinit()           23           5          8       36      5      6     4
      rfile()           57           5         15       77     18     19     5
      rdata()           50           6          9       65     13     14     3
      dopar()           19           3          4       26      6      7     0
      clkint()           4           0          2        6      0      1     0
      spack()           41           5          7       53      6      7     1
      rpack()           45          14         17       76     15     16     2
      cinchr()           7           4          4       15      0      1     1
      inchr()            9           4          4       17      2      3     0
      bufill()          33           7          5       45     10     11     0
      bufemp()          20           5          5       30      5      6     0
      gnxtfl()           8           7          4       19      2      3     0
      spar()            10           6          3       19      0      1     0
      rpar()            10           5          3       18      0      1     0
      flushinput()       3          21          5       29      0      1     0
      usage()           10          17          4       31      0      1     0
      printmsg()        11           6          2       19      1      2     0
      error()           13           9          3       25      1      2     2
      prerrpkt()         5           5          1       11      0      1     0
      ttopen()          94          21         18      133     14     15     1
      ttbin()           13           0          3       16      2      3     1
      ttres()            7           0          1        8      0      1     0
      setspd()          23           0          2       25     10     11     1
    Totals             926         322        258     1506    229     260   51
    
    Number of Functions           = 31
     
    Number of Source Code Files   = 1
    Number of Header Files        = 0
    Total Number of Files         = 1
    
    LOC in Source Code Files      = 926
    LOC in Header Files           = 0
    Lines of Code (LOC)           = 926
    
    Average Cyclomatic Complexity = 8.39
    Average Fan Out With Leafs    = 1.65
    Average Fan Out Without Leafs = 2.83
    

5. Command:

    metrics4pascal chess.h chess.p chess_moves.p chess_misc.p

Action:

Displays software metrics for chess.h, chess.p, chess_moves.p, and chess_misc.p, a group of Pascal programs implementing a chess game. Assuming this command is run on August 24, 2004, file "metrics.20040824" is created and displayed on the screen. As shown below, each Pascal file contains several functions or procedures.

                                      PROJECT METRICS
                                 Tuesday -- August 24, 2004
    
    File                  LOC   #Comments    #Blanks   #Lines    #DE   v(g)    FO
    chess.h               126          34          8      168      0      0     0
    chess.p
      Main_Program()       92          30          10     132      4      5     6
      Castle()             24           5           6      35      2      3     0
      Initialize_Board()   99          27          22     148      0      1     0
      Search()            145          62          19     226     15     16     5
      New_Game()           34          24           9      67      4      5     3
      En_Passant()         78           0           5      83      4      5     3
      Check_Mate()         18          34           9      61      0      1     0
      Totals:             490         182          80     752     29     36    17
    chess_moves.p
      Opening_Move()       72          14           5      91      8      9     4
      Select_Move()       156          43          22     221     14     15     7
      Move_Piece()         54           5          10      69      3      4     0
      Evaluate_Moves()     89          23                 119     10     11    11
      Totals:             371          85          44     500     35     39    22
    chess_misc.p
      Help()               40          14           0      54      0      1     0
      Draw_Board()         55          12          12      79      0      1     0
      Score()             122          50          14     186      4      5     3
      Totals:             217          76          26     319      4      6     3
    Totals               1204         377         158    1739     68     81    42
    
    
    Number of Procedures/Functions  = 14
    
    Number of Source Code Files     = 3
    Number of Header Files          = 1
    Total Number of Files           = 4
    
    LOC in Source Code Files        = 1078
    LOC in Header Files             = 126
    Lines of Code (LOC)             = 1204
    
    Average Cyclomatic Complexity   = 5.79
    Average Fan Out With Leafs      = 3.00
    Average Fan Out Without Leafs   = 5.25
    

6. Command:
    metrics4pascal *.h *.p
Action:

Displays software metrics for all header and Pascal source code files in current directory. The screen output is the same as the previous example if the current directory only contains chess.h, chess.p, chess_moves.p, and chess_misc.p.


7. Command:
    metrics4Fortran -l
Action:

Calculate software metrics for all FORTRAN files listed in file "metric.files" (default) and store results into file "metrics.project" (assume command is run on December 20, 2004). Sample output follows.

                                        PROJECT METRICS
                                  Monday -- December 6, 2004
    
    File                  LOC   #Comments    #Blanks   #Lines    #DE   v(g)    FO
    ALLOC.F                78          33         10      121     11     12     2
    NEXT.F                 26          40          9       75      0      1     0
    CLASS.F
      CLASS2()             33           4          3       40      4      5     2
      CLASS4()             45           7          5       57      3      4     3
      FINDTRN()            76          12          8       96      6      7     5
      ANSWER()             55           9         22       86      4      5     0
      Totals:             209          32         38      279     17     21    10
    Totals                313         105         57      475     28     34    12
    
    Number of Procedures/Functions  = 6
    
    Number of Source Code Files     = 3
    Number of Header Files          = 0
    Total Number of Files           = 3
    
    LOC in Source Code Files        = 313
    LOC in Header Files             = 0
    Lines of Code (LOC)             = 313
    
    Average Cyclomatic Complexity   = 5.67
    Average Fan Out With Leafs      = 2.00
    Average Fan Out Without Leafs   = 3.00
    


8. Command:

    metrics4c -Dl myfiles -v

Action:

Calculate software metrics for all C files listed in file "myfiles" and store results into file "metrics.20040130" (assume command is run on January 30, 2004). Sample output follows.

                                  PROJECT METRICS
                             Friday -- January 30, 2004
    
    File                  LOC   #Comments    #Blanks   #Lines    #DE   v(g)    FO
    CheckMap.c            231          45         30      306      9     10     0
    DisplayMap.c          167          32         19      218      6      7     3
    DisplayMap.h           45          14          8       67      0      0     0
    DrawCity.c             55          17         10       82      4      5     3
    ReadData.c            188          28         24      240      6      7     0
    Totals                686         136         91      913     25     29     6
    
    Number of Functions            = 5
    
    Number of Source Code Files    = 4
    Number of Header Files         = 1
    Total Number of Files          = 5
    
    LOC in Source Code Files       = 641
    LOC in Header Files            = 45
    Lines of Code (LOC)            = 686
    
    Average Cyclomatic Complexity  = 5.80
    Average Fan Out With Leafs     = 1.20
    Average Fan Out Without Leafs  = 3.00
    
    Acronym List
      LOC        - Lines of Code
      #Comments  - Number of Comment Lines
      #Blanks    - Number of Blank Lines
      #Lines     - Total Number of Lines
      #DE        - Number of Decision Elements
      v(g)       - Cyclomatic Complexity
      FO         - Fan Out
      filename*  - File Is Unit Tested
    


9. Command:

    metrics4c -d

Action:

Calculate software metrics for all C files listed in file "../metrics/metric.files" (default), store results into file "metrics.project" (assume command is run on September 28, 2004), and display file "metrics.20040928" on screen. Sample output follows.

                                 PROJECT METRICS
                          Tuesday -- September 28, 2004
    
    File                  LOC   #Comments    #Blanks   #Lines    #DE   v(g)    FO
    calculator.c
      calculator()         37          10          6       53      2      3     3
      readchar()           19           0          0       19      3      4     0
      reporterror()         6           0          0        6      1      2     1
      readnumber()         28          12          0       40      4      5     1
      readexpr()           19           8          2       29      2      3     2
      readterm()           21           5          2       28      4      5     3
      readfactor()         27           4          0       31     14     15     4
    Totals                157          39         10      206     30     37    14
    
    Number of Functions            = 7
    
    Number of Source Code Files:   = 1
    Number of Header Files         = 0
    Total Number of Files          = 1
    
    LOC in Source Code Files       = 157
    LOC in Header Files            = 0
    Lines of Code (LOC)            = 157
    
    Average Cyclomatic Complexity  = 5.29
    Average Fan Out With Leafs     = 2.00
    Average Fan Out Without Leafs  = 2.33
    


10. Command:

    metrics4c -q /u/sql/oracle_report.pc

Action:

Calculate software metrics for a C program containing embedded SQL statements. Output displays the number of SQL statements and SQL lines of code. Sample output follows.

                                    PROJECT METRICS
                               Wednesday -- July 21, 2004
    
    File                  LOC     SQL LOC  #Comments    #Blanks   #Lines    #DE   v(g)    FO
    oracle_report.pc      116           3         92         53      264      -      -     -
      flush_output()        8           0          0          0        8      0      1     0
      main()              335          76        121        157      689     32     33     1
    Totals                459          79        213        210      961     32     34     1
    
    Total Number of Functions      = 2
    
    Number of Source Code Files    = 1
    Number of Header Files         = 0
    Total Number of Files          = 1
    
    LOC in Source Code Files       = 459
    LOC in SQL Statements          =  79
    LOC in Header Files            =   0
    Lines of Code (LOC)            = 538
    
    Number of SQL statements       = 26
    
    Average Cyclomatic Complexity  = 17.00
    Average Fan Out With Leafs     =  0.50
    Average Fan Out Without Leafs  =  1.00
    


11. Command:

    metrics4Fortran -Dd /home/projects/TEK90

Action:

Calculate software metrics for all FORTRAN files listed in file "/home/projects/TEK90/metrics/metric.files", store results into file "metrics.20040520" (assume command is run on May 20, 2004), and display file "metrics.20040520" on screen. Sample output follows.

                                  PROJECT METRICS
                             Thursday -- May 20, 2004
    
    File                  LOC   #Comments    #Blanks   #Lines    #DE   v(g)    FO
    ANALYZE.F              45          10          5       60      4      5     3
    CATPATH.F             148          25         19      192     10     11     0
    DISPLAY.F              88          16         18      122      6      7     0
    LAUNCH.F              133          53         24      210      7      8     2
    TRANSMIT.F             95          32         22      149      3      4     2
    Totals                509         136         88      733     30     35     7
    
    Number of Procedures/Functions = 5
    
    Number of Source Code Files    = 5
    Number of Header Files         = 0
    Total Number of Files          = 5
    
    LOC in Source Code Files       = 509
    LOC in Header Files            =   0
    Lines of Code (LOC)            = 509
    
    Average Cyclomatic Complexity  = 7.00
    Average Fan Out With Leafs     = 1.40
    Average Fan Out Without Leafs  = 2.33
    


12. Command:

    metrics4Fortran -d /home/projects/TEK90 -s

Action:

Calculate software metrics for all FORTRAN files listed in file "/home/projects/TEK90/metrics/metric.files" and append a summary entry to file "/home/projects/TEK90/metrics/metric.totals". The following line is appended to "metrics.totals":

    20040520 145422 509 0 136 88 733 30 35 7 0 5 5 0 0 7.00 -1 -1 -1 -1

where:

      Value Represents
    
      20040520 May 20, 2004
      145422 2:54 PM and 22 seconds
      509 Lines of code
      0 SQL lines of code
      136 Number of comment lines
      88 Number of blank lines
      733 Total number of lines
      30 Total number of decision elements
      35 Project cyclomatic complexity
      7 Project fan out
      0 Number of SQL statements
      0 Reserved Field
      5 Number of functions
      5 Number of source code files
      0 Number of header files
      509 Lines of code in source files
      0 Lines of code in header files
      7.00 Average project cyclomatic complexity
      -1 Number of files unit tested
      -1 Lines of code unit tested
      -1 Percent of files unit tested
      -1 Integration Test Percentage
    

The last four -1 values indicate that test metrics were not generated. Each entry is separated by a tab character and each line is delimited by a new line character. A metrics report is not generated or displayed on the screen.


13. Command:

    metrics4pascal -lrs

Action:

Calculate software metrics for all Pascal files listed in file "metric.files", store results into file "metrics.project", and append an entry to file "metric.totals". File "metrics.project" is displayed on the screen.

                                 PROJECT METRICS
                          Wednesday -- January 28, 2004
    
    File                  LOC   #Comments    #Blanks   #Lines    #DE   v(g)    FO
    copy_data.p           112          21          9      142      4      5     0
    get_buffer.p           48          14         11       73     10     11     3
    parse_header.p        148          54         18      220      6      7     2
    network.p              90          40         13      143      6      7     4
    network.h             120          33         21      174      0      0     0
    route_packet.p         76          19          9      104      7      8     3
    send_packet.p          62          42         12      116      3      4     0
    Totals                656         223         93      972     36     42    12
    
    Number of Procedures/Functions = 6
    
    Number of Source Code Files    = 6
    Number of Header Files         = 1
    Total Number of Files          = 7
    
    LOC in Source Code Files       = 536
    LOC in Header Files            = 120
    Lines of Code (LOC)            = 656
    
    Average Cyclomatic Complexity  = 7.00
    Average Fan Out With Leafs     = 2.00
    Average Fan Out Without Leafs  = 3.00
    

Also, the following line is appended to "metrics.totals":

    20040128 081510 656 0 223 93 972 36 42 12 0 0 6 6 1 656 120 7.00 -1 -1 -1 -1

where:

       Value Represents
    
       20040128 January 28, 2004
       081510 8:15 AM and 10 seconds
       656 Lines of code
       0 SQL lines of code
       223 Number of comment lines
       93 Number of blank lines
       972 Total number of lines
       36 Total number of decision elements
       42 Project cyclomatic complexity
       12 Project fan out
       0 Number of SQL statements
       0 Reserved Field
       6 Number of procedures/functions
       6 Number of source code files
       1 Number of header files
       656 Lines of code in source files
       120 Lines of code in header files
       7.00 Average project cyclomatic complexity
       -1 Number of files unit tested
       -1 Lines of code unit tested
       -1 Percent of files unit tested
       -1 Integration Test Percentage
    

The last four -1 values indicate that test metrics were not generated.


14. Command:

    metrics4c -% -d /home/projects/medic

Action:

Calculate software metrics, including test metrics, for all C files listed in file "/home/projects/medic/metrics/metric.files" and display file "metrics.project" on screen (assume command is run on December 6, 2004). An asterisk after the file name indicates that the file is unit tested. Sample output follows.

                                 PROJECT METRICS
                           Monday -- December 6, 2004
    
    File                  LOC   #Comments    #Blanks   #Lines    #DE   v(g)    FO
    CheckMap.c            231          45         30      306      9     10     2
    DisplayMap.c*         167          32         19      218      6      7     4
    DisplayMap.h           45          14          8       67      0      0     0
    DrawCity.c*            55          17         10       82      4      5     0
    Help.c*                20          12          7       39      1      2     0
    ReadData.c            188          28         24      240      6      7     0
    Totals                706         148         98      952     26     31     6
    
    Number of Functions            = 5
    
    Number of Source Code Files    = 5
    Number of Header Files         = 1
    Total Number of Files          = 6
    
    LOC in Source Code Files       = 661
    LOC in Header Files            =  45
    Lines of Code (LOC)            = 706
    
    Average Cyclomatic Complexity  = 6.20
    Average Fan Out With Leafs     = 1.20
    Average Fan Out Without Leafs  = 3.00
    
    Number of Files Unit Tested    = 3
    LOC Unit Tested                = 242
    Percent of Files Unit Tested   = 60%
    Integration Test Percentage    = 37%
    


15. Command:

    metrics4c -%s,d /home/projects/medic

Action:

Calculate software metrics, including test metrics, for all C files listed in file "/home/projects/medic/metrics/metric.files" and append an entry to file "metric.totals". No output is displayed on screen.

The following line is appended to "metrics.totals":

    20041206,094259,706,0,148,98,952,26,31,6,0,0,5,5,1,661,45,6.20,3,242,60,37

where:

      Value Represents
    
      20041206 December 6, 2004
      094259 9:42 AM and 59 seconds
      706 Lines of code
      0 SQL lines of code
      148 Number of comment lines
      98 Number of blank lines
      952 Total number of lines
      26 Total number of decision elements
      31 Project cyclomatic complexity
      6 Project fan out
      0 Number of SQL statements
      0 Reserved field
      5 Number of functions
      5 Number of source code files
      1 Number of header files
      661 Lines of code in source files
      45 Lines of code in header files
      6.20 Average project cyclomatic complexity
      3 Number of files unit tested
      242 Lines of code unit tested
      60 Percent of files unit tested
      37 Integration Test Percentage
    


16. Command:
    metrics4c -% -wL175 -wC8 -l /home/projects/cp500/list_of_files

Action:

Calculate software metrics, including test metrics, for all C files listed in file "/home/projects/cp500/list_of_files" and display file "metrics.project" on screen (assume command is run on January 30, 2004). Also, flag a warning (as indicated by a 'W' character next to the value) if the lines of code is greater than 175 or the cyclomatic complexity is greater than 8. Sample output follows.

                                     PROJECT METRICS
                                Friday -- January 30, 2004
    
    File                  LOC   #Comments    #Blanks   #Lines    #DE   v(g)    FO
    Calc_Distance.c       187 W        34         21      242      9     10 W   2
    Current_Position.c    105          22         19      146      3      4     4
    Simulate_Path.c*       33          26         10       69      2      3     0
    Target.c*             123          38         23      184      8      9 W   0
    Tracking.c            178 W        11         34      223      7      8     3
    Totals                626         131        107      864     29     34     9
    
    Number of Functions            = 5
    
    Number of Source Code Files    = 5
    Number of Header Files         = 0
    Total Number of Files          = 5
    
    LOC in Source Code Files       = 626
    LOC in Header Files            = 0
    Lines of Code (LOC)            = 626
    
    Average Cyclomatic Complexity  = 6.80
    Average Fan Out With Leafs     = 1.80
    Average Fan Out Without Leafs  = 3.00
    
    Number of Files Unit Tested    = 2
    LOC Unit Tested                = 156
    Percent of Files Unit Tested   = 60%
    Integration Test Percentage    = 25%
    
    

File "warnings.20040130" contains:

    LINES OF CODE AND CYCLOMATIC COMPLEXITY WARNINGS
            Friday -- January 30, 2004
    
    The maximum lines of code (LOC) is 175.
    The maximum cyclomatic complexity is 8.
    
    The following functions exceeded at least one of these maximums:
    
    File                 LOC        v(g)
    Calc_Distance.c      187 W        10 W
    Target.c             123           9 W
    Tracking.c           178 W         8
    


17. Command:

    listfiles /home/projects/Calendar;
    metrics4pascal -rsDd /home/projects/Calendar

Action:

First, list all files currently defined in project Calendar by extracting their names from the +1Environment project. This list is stored in file "/home/projects/Calendar/metrics/metric.files".

Second, calculate software metrics for all Pascal files listed in file "/home/projects/Calendar/metrics/metric.files" and store results into files "metrics.20040721" and file "metric.totals", both which are located in the /home/projects/Calendar/metrics directory. Sample output follows.

                                 PROJECT METRICS
                            Wednesday -- July 21, 2004
    
    File                  LOC   #Comments    #Blanks   #Lines    #DE   v(g)    FO
    Calendar.p            122          22          8      152      6      7     5
    Calendar.h             89           7          5      101      0      0     0
    AddText.p*            167          12         19      198      4      5     3
    DeleteText.p          121           9          8      138      3      4     2
    PackDate.p*            10           3          0       13      5      6     0
    PackTime.p*             9           0          2       11      0      1     0
    ListEntries.p*         35           4          4       43      1      2     0
    PrintHelp.p*           54          14          7       75      0      1     0
    ReadEntry.p           188          28         24      240      6      7     0
    Totals                795          99         77      971     25     33    10
    
    Number of Functions            = 8
    
    Number of Source Code Files    = 8
    Number of Header Files         = 1
    Total Number of Files          = 9
    
    LOC in Source Code Files       = 706
    LOC in Header Files            = 89
    Lines of Code (LOC)            = 795
    
    Average Cyclomatic Complexity  = 4.13
    Average Fan Out With Leafs     = 1.25
    Average Fan Out Without Leafs  = 3.33
    
    Number of Files Unit Tested    = 5
    LOC Unit Tested                = 275
    Percent of Files Unit Tested   = 63%
    Integration Test Percentage    = 39%
    
    
The following line is appended to "metrics.totals":

    20040721 031809 795 0 99 77 971 25 33 10 0 0 8 8 1 706 89 4.13 5 275 63 39

where:

      Value Represents
    
      20040721 July 21, 2004
      031809 3:18 AM and 9 seconds
      795 Lines of code
      0 SQL lines of code
      99 Number of comment lines
      77 Number of blank lines
      971 Total number of lines in project
      25 Total number of decision elements
      33 Project cyclomatic complexity
      10 Project fan out
      0 Number of SQL statements
      0 Reserved field
      8 Number of functions
      8 Number of source code files
      1 Number of header files
      706 Lines of code in source files
      89 Lines of code in header files
      4.13 Average project cyclomatic complexity
      5 Number of files unit tested
      275 Lines of code unit tested
      63 Percent of files unit tested
      39 Integration Test Percentage
    


18. Command:
    listfiles ../../Calendar; metrics4pascal -dDrs

Action:

First, list all files currently defined in project Calendar and store this list in file "../../Calendar/metrics/metric.files". The above command is run in the +1Environment src directory of project Calendar and must specify the project name in the listfiles command, i.e., ../../Calendar.

Second, calculate software metrics for all Pascal files listed in file "../metrics/metric.files" and store the results into file "metrics.20040721" and file "../metrics/metric.totals" (assume command is run on July 21, 2004).

Output is the same as in example 17.


19. Command:

    listfiles -% /home/projects/CODE_RED;
    metrics4Fortran -%#rsd /home/projects/CODE_RED

Action:

First, list all files currently defined in project CODE_RED. For each file, indicate whether the file is unit tested or is a header file. This list is stored in "/home/projects/CODE_RED/metrics/metric.files".

Second, calculate software metrics, including test metrics, for all FORTRAN files listed in file "/home/projects/CODE_RED/metrics/metric.files", store results into files "metrics.project" (assume command is run on January 28, 2004) and file "/home/projects/CODE_RED/metrics/metric.totals", and display report on screen. Sample output follows:

                                  PROJECT METRICS
                          Wednesday -- January 28, 2004
    
    File                  LOC   #Comments    #Blanks   #Lines    #DE   v(g)    FO
    code_red.F*            97          25         19      141      3      4     4
    code_red.h             88          16         18      122      0      0     0
    draft.F                35          25          5       65      2      2     0
    few.F*                133          53         24      210      8      9     0
    good.F*               120          32         22      174      3      4     2
    men.F                 100          33         28      161      6      7     3
    Totals                573         184        116      873     22     26     9
    
    Number of Procedures/Functions = 5
    
    Number of Source Code Files    = 5
    Number of Header Files         = 1
    Total Number of Files          = 6
    
    LOC in Source Code Files       = 485
    LOC in Header Files            = 88
    Lines of Code (LOC)            = 573
    
    Average Cyclomatic Complexity  = 5.20
    Average Fan Out With Leafs     = 1.80
    Average Fan Out Without Leafs  = 3.00
    
    Number of Files Unit Tested    = 3
    LOC Unit Tested                = 350
    Percent of Files Unit Tested   = 60%
    Integration Test Percentage    = 72%
    
    
The following line is appended to "metrics.totals":
      20040128#223000#573#0#184#116#873#22#26#9#0#0#5#5#1#485#88#5.20#3#350#60#72
    
    where:
    
      Value Represents
    
      20040128 January 28, 2004
      223000 10:30 PM and 0 seconds
      573 Lines of code
      0 SQL lines of code
      184 Number of comment lines
      116 Number of blank lines
      873 Total number of lines
      22 Total number of decision elements
      26 Project cyclomatic complexity
      9 Project fan out
      0 Number of SQL statements
      0 Reserved field
      5 Number of functions
      5 Number of source code files
      1 Number of header files
      485 Lines of code in source files
      88 Lines of code in header files
      5.20 Average project cyclomatic complexity
      3 Number of files unit tested
      350 Lines of code unit tested
      60 Percent of files unit tested
      72 Integration Test Percentage
    


20. Command:

    listfiles -%p medic ../../john_workspace;
    metrics4c -%nrsd /home/projects/john_workspace

Action:

First, list all files currently in John's workspace for project medic. For each file, indicate whether the file is unit tested, is not unit tested, or is a header file.

Second, calculate software metrics, including test metrics, for all C files listed in file "/home/projects/john_workspace/metrics/metric.files", store results in files "metrics.project" and "metrics.totals" (assume command is run on May 20, 2004). File "metrics.project" is not displayed on the screen.

                                 PROJECT METRICS
                            Thursday -- May 20, 2004
    
    File                  LOC   #Comments    #Blanks   #Lines    #DE   v(g)    FO
    DrawCity.c*           120          25         10      155      8      9     2
    ReadData.c            167          26         22      215      6      7     0
    Totals                287          51         32      370     14     16     2
    
    Number of Functions            = 2
    
    Number of Source Code Files    = 2
    Number of Header Files         = 0
    Total Number of Files          = 2
    
    LOC in Source Code Files       = 287
    LOC in Header Files            = 0
    Lines of Code (LOC)            = 287
    
    Average Cyclomatic Complexity  = 8.00
    Average Fan Out With Leafs     = 1.00
    Average Fan Out Without Leafs  = 2.00
    
    Number of Files Unit Tested    = 1
    LOC Unit Tested                = 120
    Percent of Files Unit Tested   = 50%
    Integration Test Percentage    = 42%
    
    
The following line is appended to "metrics.totals":

    20040520 155012 287 0 51 32 370 14 16 2 0 0 2 2 0 287 0 8.00 1 120 50 42

where:

      Value Represents
    
      20040520 May 20, 2004
      155012 3:50 PM and 12 seconds
      287 Lines of code
      0 SQL lines of code
      51 Number of comment lines
      32 Number of blank lines
      370 Total number of lines in project
      14 Total number of decision elements
      16 Project cyclomatic complexity
      2 Project fan out
      0 Number of SQL statements
      0 Reserved Field
      2 Number of functions
      2 Number of source code files
      0 Number of header files
      287 Lines of code in source files
      0 Lines of code in header files
      8.00 Average project cyclomatic complexity
      1 Number of files unit tested
      120 Lines of code unit tested
      50 Percent of files unit tested
      42 Integration Test Percentage
    


3. Metrics4Project User Interface

Metrics4Project displays the number of open, closed, and total number of change requests for a project organized by status, priority, category, class, and longevity. All change requests or only those change requests satisfying the last change request query are displayed. Metrics4Project reads the change request database for a +1Environment project.

The command syntax for Metrics4Project is:

    metrics4project [-D] -d [directory_name] [-f] [-n] [-r] [-s] [-v] [-#|-,]

where:

    -DDate output file. Write output to cr.YYYYMMDD file instead.
    -DDate output file. Write output to cr.YYYYMMDD file instead of cr.metrics.
    -dCalculate metrics for change requests found in the "../cr" directory.
    -d directory_nameCalculate metrics for change requests found in "directory_name/cr" directory. For example, if "-d /home/john/projects/cp45" is specified, Metrics4Project will use directory "/home/john/projects/cp45/cr" to locate the change request database.
    -fCalculate metrics for all change requests found using the last Find Change Requests query command. The Find Change Requests command is found in +1CR's Change Request Menu. For example, to display how responsive the project is in resolving problem reports with a priority of "Urgent" or "Very High", run the +1CR's Find Change Requests command with Priority set to ">= Very High" and then run the metrics4project command with the "-f" option.
    -iDisplay system information and license file.
    -nDo not display report on screen.
    -rGenerate metrics report (default), e.g., "cr.20041225".
    -sGenerate metrics and append an entry to "cr.totals" summary file.
    -vVerbose mode displays informative messages.
    -# or -,Use the '#' or ',' character to separate fields in the "cr.totals" file. This option is supported to make it easier to import data contained in the "cr.totals" file into a spreadsheet program. By default, the tab character is used to separate fields in the "cr.totals" file.

3.1 Metrics4Project Examples

1. Command:

    metrics4project

Action:

Displays the following Metrics4Project help message:

    To run Metrics4Project, type:
    
       metrics4project -d [dir_name] [-f] [-n] [-r] [-s] [-v] [-#|-,]
    
    where:
    
       -D  Date output file.  Write output to cr.YYYYMMDD file instead
      of cr.metrics.
       -d  Calculate metrics for change requests found in the 
      "../cr" directory.
       -d dir_name Calculate metrics for change requests found in the 
      "dir_name/cr" directory.
       -f  Calculate metrics only for those change requests
      satisfying the last +1CR change request query.
       -i  Display system information and license file.
       -n  Do not display report on screen.
       -r  Generate metrics report (default).
       -s  Generate metrics and append an entry to "cr.totals" 
      summary file.
       -v  Verbose mode displays informative messages.
       -# or -, Use the '#' or ',' character to separate fields in the 
      "cr.totals" file.
    
    Please try again.
    
    Copyright © 1997-1998 +1 Software Engineering.  All Rights Reserved.
    


2. Command:

    metrics4project -X

Action:

Displays the above Metrics4Project help message and indicates that 'X' is an invalid option.


3. Command:

    metrics4project -d
Action:

Calculate metrics for change requests found in the "../cr" directory. The generated report is displayed on the screen.


4. Command:

    metrics4project -nd /home/projects/medic

Action:

Calculate metrics for change requests found in the "/home/projects/medic/cr" directory. A report is generated, but is not displayed on the screen.


5. Command:

    metrics4project -df

Action:

Calculate metrics only for those change requests found in the "../cr" directory that satisfied the last +1CR Find Change Request query. The generated report is displayed on the screen.


6. Command:

    metrics4project -sd /home/projects/CODE_RED

Action:

Calculate metrics for change requests found in the "/home/john/projects/CODE_RED/cr" directory and append an entry to the "cr.totals" file. No change request report is generated and no screen output is displayed.


7. Command:

    metrics4project -frsvd /home/john/projects/ACCESS

Action:

Calculate metrics only for those change requests found in the "/home/john/projects/ACCESS/cr" directory that satisfied the last +1CR Find Change Request query. Generate a report and display it on the screen. Also, append an entry to the "cr.totals" file.


3.2 Metrics4Project Report

A typical Metrics4Project report follows:

                            CHANGE REQUEST METRICS
                          Wednesday -- July 21, 2004
    
    There are 175 change requests: 61 are open and 114 are closed.
    
     Status
     1. Submitted       25
     2. Reviewed        14
     3. Approved         0
     4. Assigned        17
     5. Fixed            5
     6. Closed         114
     7. Not Approved     0
     Total             175
    
     Priority         Open    Closed    Total
     1. Urgent          25        40       65
     2. Very High       20        60       80
     3. High             9        11       20
     4. Nominal          5         3        8
     5. Low              2         0        2
     Total              61       114      175
    
     Category         Open    Closed    Total
     1. Requirement      0         0        0
     2. Design           3        11       14
     3. Documentation   11        24       35
     4. Software        42        77      119
     5. Enhancement      5         2        7
     Total              61       114      175
    
     Class            Open    Closed    Total
     1. Class 1         58       110      168
     2. Class 2          3         4        7
     3. Approval         0         0        0
     4. No Approval      0         0        0
     Total              61       114      175
    
     Longevity        Open    Closed    Total
     1. 0 - 7 days      20        16       36
     1. 8 - 14 days      9        10       19
     2. 15 - 30 days    15        70       85
     3. 31 - 60 days    10        15       25
     4. 61 - 90 days     5         3        8
     5. Over 90 days     2         0        2
     Total              61       114      175
    
    

3.3 Metrics4Project Summary Report

The format for a single line in the "cr.totals" Metrics4Project Summary Report follows. Each field is separated by a tab character (default) and each line is delimited by a new line character. The values below are based on the previous change request metrics report.

     Name               Type         Value
    
     Date               char[6]      20040721
     Time               char[4]      1425
     Total_CRs          integer      175
     Open_CRs           integer      61
     Closed_CRs         integer      114
    
     Submitted          integer      25
     Reviewed           integer      14
     Approved           integer      0
     Assigned           integer      17
     Fixed              integer      5
     Closed             integer      114
     Not_Approved       integer      0
     Deleted            integer      6
    
     Open_Urgent        integer      25
     Open_Very_High     integer      20
     Open_High          integer      9
     Open_Nominal       integer      5
     Open_Low           integer      2
    
     Open_Software      integer      42
     Open_Req.          integer      0
     Open_Doc.          integer      11
     Open_Design        integer      3
     Open_Enhance       integer      5
    
     Open_1_Approval    integer      58
     Open_2_No_Appr.    integer      3
    
     Open_1-7_Days      integer      29
     Open_7-14_Days     integer      29
     Open_15-30_Days    integer      15
     Open_31-60 Days    integer      10
     Open_61-90_Days    integer      5
     Open_Over_90       integer      2
    
     Closed_Urgent      integer      40
     Closed_Very_High   integer      60
     Closed_High        integer      11
     Closed_Nominal     integer      3
     Closed_Low         integer      0
    
     Closed_Software    integer      77
     Closed_Req.        integer     0
     Closed_Doc.        integer      24
     Closed_Design      integer      11
     Closed_Enhance     integer      2
    
     Closed_1_Approval  integer      110
     Closed_2_No_Appr.  integer      4
    
     Closed_1-7_Days    integer      16
     Closed_8-14_Days   integer      10
     Closed_30_Days     integer      70
     Closed_60 Days     integer      15
     Closed_90_Days     integer      3
     Closed_Over_90     integer      0
    
    

4. Metrics2GIF User Interface

The command syntax for Metrics2GIF is:

    metrics2gif [-cdilnprtxy] [-ddir_name] [-ofilename] [X-Attr] Y-Attr

where:

    -c Use cr.totals (not metric.totals) as input file.
    -d Use ../metrics/metrics.totals as input file.
    -dDirectory_Name Use "Directory_Name" as file name as input file.
    -f Fill in graph.
    -i Display system information and license file.
    -l Draw line.
    -n Do not display days.
    -oFilename Use file "Filename" as output file.
    -p Display number next to graph points.
    -r Round numbers along y-axis.
    -t Create a transparent background.
    -x Draw x lines.
    -y Draw y lines.
    X-Attr Specify attribute along x-axis. Defaults to Date.
    Y-Attr Specify attribute along y-axis (e.g., LOC).

Section 3.3 lists the possible change request X and Y attributes which can be graphed under the Name field (e.g., metrics2gif -cd Open_Urgent). Metrics2GIF can also be used to graph values found in the metric.totals file (e.g., metrics2gif -d LOC).

5. Running Software Metrics On A Daily, Weekly And Monthly Basis

To calculate software and project metrics automatically on a daily, weekly, or monthly basis, a cron job can be defined and run in the background. Cron jobs can be defined by any user. If all source code files are readable by a user, the user can edit their own crontab by running "crontab -e". If a user does not have read access to all source code files, the command can be executed by the root user. Running "crontab -e" not only edits the cron table, but also restarts the cron daemon so that your entry will run at its designated time. The syntax for a crontab entry is:

    minutes hour day-of-month month day-of-week Command-To-Run

where minutes can range from 0-59, hour from 0-23, day-of-month from 1-31, month from 1-12, and day-of-week from 0-6 (where 0 represents Sunday). The following examples illustrate how to run various metric programs on a daily, weekly, biweekly, and monthly basis.

Daily Example

The following crontab entry runs Monday through Friday at 2 a.m. in the morning:

    0 2 * * 1-5 (metrics4project -sd /home/projects/CODE_RED)

Weekly Example

The following crontab entry runs Monday at 3 a.m. in the morning:

    0 3 * * 1 (listfiles -% /home/projectA; metrics4Fortran -%nrsd /home/projectA)

Bimonthly Example

The following crontab entry runs on the first and sixteenth day of each month at 4 a.m. in the morning:

    0 4 1,16 * * (listfiles -% /home/projects/medic; metrics4c -% -d /home/projects/medic -s)

Monthly Example

The following crontab entry runs on the first day of each month at 2:30 a.m. in the morning:

    30 2 1 * * (listfiles -% /home/projects/ZEBRA; metrics4pascal -sd /home/projects/ZEBRA)

6. Integrating Software Metrics Into The +1Environment

+1Environment's Local Commands Menu allows you to define commands not part of the +1Environment. Local commands are defined in two parts: the name used to invoke the command (i.e., the "short command"), which can be anywhere between two to ten characters in length, and the actual command string to run, which can be up to 160 characters in length. To run a local command in the +1Environment menus, you only need to type the short command.

Local commands can reference file names used by the project. The character sequence for identifying the project's file name and the root module's file name currently displayed on the screen are:

    \F or \fFile name of the current root module
    \L or \lLanguage of current root module
    \RFile name of the project's root module
    \rLanguage of the project's root module
    \\The '\' character

For example to run Metrics4FORTRAN against the current root module's source code, the short command can be "mets" while the actual command to run is:

    metrics4Fortran \F.\L
To run Metrics4C against all source code and header files in the current directory, the short command could be "mets4c" while the actual command to run is:
    metrics4c *.h *.c

To run Metrics4Pascal for all files defined in project ZEBRA, the short command could be "pmets" while the actual command to run is:

    listfiles ../../ZEBRA; metrics4pascal -drs
To run Metrics4Project for change requests defined in the current project that satisfied the last +1CR's Find Change Request query, the short command could be "projmets" while the command to run is:
    metrics4project -df

7. Sofware Metrics Defined

This section defines the software metric values.

7.1 Lines Of Code

What is a line of code? In actual practice, there really is not a general consensus on what constitutes a line of code. For our metric programs, +1 Software Engineering followed the definition found in Software Engineering Metrics and Models. Their definition is:

    "A line of code is any line of program text that is not a comment or blank line, regardless of the number of statements or fragments of statements on the line. This specifically includes all lines containing program headers, declarations, and executable and non-executable statements."

In short, a line of code is every line but comment lines or blank lines. This definition is the most prevalent in the industry. The metric programs count the number of lines of code, comment lines, blank lines, and then sum these to provide the total number of lines found in a file.

7.2 Decision Elements

A decision element is the number of control statements found in a program. For example, the IF statement is a decision element.

For Metrics4C, the following symbols and keywords increment the number of decision elements found in a C function: &&, ||, if, for, default, do, and while. Also when using the switch statement, the number of decision elements is incremented for commas and colons found in case statements.

For Metrics4FORTRAN, the following keywords increment the number of decision elements found in a FORTRAN procedure or function: .AND., DO, FUNCTION, IF, .OR., and SUBROUTINE. Also, the number of decision elements is incremented one or more times for computed goto statements.

For Metrics4Pascal, the following keywords increment the number of decision elements found in a Pascal procedure or function: AND, FOR, IF, FUNCTION, OR, OTHERWISE, PROCEDURE, PROGRAM, REPEAT, and WHILE. Also, colons and commas in a CASE statement increment the total number of decision elements, while LABEL keywords and commas in a LABEL statement decrement the decision element count.

7.3 Cyclomatic Complexity

Cyclomatic complexity is simply the number of decision elements plus one. The more decisions the software makes, the more paths it can take, and hence, has a higher complexity. What should the maximum cyclomatic complexity measure be for a single module? This value varies, but 10 or less is generally accepted.

7.4 Average Cyclomatic Complexity

The average cyclomatic complexity is computed as follows:

    Project Cyclomatic Complexity / Number of Procedures and Functions

The Project Cyclomatic Complexity is the sum of cyclomatic complexity values for all procedures and functions.

7.5 Fan Out

The project fan out metric displays the average module fan out measurements with and without the leaf modules counted. Figure 6-1 shows a sample project.

Fan Out Metric Example

Figure 7-1. Fan Out Metric Example

When this command is run against the sample project, the following messages are displayed:

    Fan Out With Leafs = 0.83
    Fan Out Without Leafs = 2.50

The average module fan out including leafs is the sum of the fan out count for each module defined in the current model divided by the total number of modules in the model. For our sample project, the calculation is:

    FOwith = [2 (Main) + 0 (A) + 3 (B) + 0 (B1) + 0 (B2) + 0 (B3)] / 6 (modules)
    = 5 / 6
    = 0.83

The average module fan out not including leaf modules is the sum of the fan out count for each module with at least one child in the current model divided by the number of parent modules. For our sample project, the calculation is:

    FOwithout = [2 (Main) + 3 (B)] / 2 (parent modules)
    = 5 / 2
    = 2.50

A project manager may want to define allowable ranges for the project. For example, if FOwithout is too low, it may indicate that the project is not modular enough.

7.6 Percent of Files Unit Tested The percent of files unit tested is calculated as follows:

100% * # of Procedures and Functions Unit Tested / Total # of Procedures and Functions

The weakness of this metric is that it does not take into consideration the number of lines of code in each function. For example, say a project has 25 functions. Testing five functions each containing 10 lines of code is equivalent to testing five functions each containing 250 lines of code. For both, the percent of files unit tested is:

    Percent of Files Unit Tested = 100% * 5 / 25 = 20%

7.7 Integration Test Percentage

The Integration Test Percentage (ITP) provides a percentage indicating how much of the project's source code has been unit and integration tested. The formula for ITP follows:

    ITP = 100% * LOC Unit Tested / (LOC - LOC in Header Files)

As an example, Table 7-1 shows the number of lines of code for four files, one of which is a header file. Each ".p" file contains a single procedure.

ModuleLOC
file.h100
A.p25
B.p100
C.p200

Table 7-1. Four Files

If module A.p is the only file unit tested, the ITP is:

    ITP = 100% * 25 / (425 - 100) = 100% * 25 / 325 = 7.69%

If module C.p is the only file unit tested, the ITP is:

    ITP = 100% * 200 / (425 - 100) = 100% * 200 / 325 = 61.53%

If modules B.p and C.p are unit tested, the ITP is:

    ITP = 100% * (100 + 200) / (425 - 100) = 100% * 300 / 325 = 92.30%

And if all modules are unit tested, the ITP is:

    ITP = 100% * 325 / (425 - 100) = 100% * 325 / 325 = 100%

The ITP metric provides a more precise measurement as to how much unit and integration testing has been done. On actual projects, what constitutes a unit can vary. A unit can be defined as an individual function, a group of functions, or an entire Computer Software Unit (which can be several thousand lines of code). The ITP metric is not based on what constitutes a unit. Instead, the ITP metric is based on the actual number of lines of code tested with respect to the total number of lines defined in the project. The ITP can be used to better prepare for Formal Qualification Testing (FQT) by specifying how much of the source code should be unit and integration tested prior to testing. When using +1Test, the ITP metric accurately reflects the current state of the project after running the regression tests defined in the project and using the listfiles command. To run regression tests, see the Run Tests command in Test Menu.

8. Conclusion

Metrics4C, Metrics4FORTRAN, Metrics4Pascal, and Metrics4Project calculate software and project metrics based on the size, complexity, and other attributes of the source code and project attributes. Metrics2GIF generates GIF graphs for the metrics summary data which can be viewed using a web browser.

This user's guide is written to provide you with a detailed description of our metric products. If you have any questions or would like to receive additional information on these or our other products, please feel free to contact us.

+1 Software Engineering
2510-G Las Posas Road, Suite 438
Camarillo, California 93011
805-389-1778
http://www.plus-one.com

Additional Information

+1 Software Engineering is pleased to provide this user's guide, which is for information purposes only and is subject to change without notice. +1 Software Engineering makes no express or implied warranties in this user's guide.

+1 Software Engineering is a registered trademark of +1 Software Engineering.

Metrics4C, Metrics4FORTRAN, Metrics4Pascal, Metrics4Project, and +1Environment are trademarks of +1 Software Engineering.

UNIX is a registered trademark licensed exclusively through X/Open Company Limited. All other product names are trademarks of their respective holders.

To Top

Contact Us       Phone:
805-389-1778
8 AM-5 PM PST
Monday-Friday
  E-mail:
info4u@plus-one.com
sales4u@plus-one.com
support4u@plus-one.com
  Address:
+1 Software Engineering
2510-G Las Posas Road, Suite 438
Camarillo, California 93011
© Copyright 2008 +1 Software Engineering - All Rights Reserved