Making cmetrics more user (and research) friendly

Making cmetrics more user (and research) friendly
Published by lcanas on Wed, 2011-03-09 16:37

Israel Herraiz made some changes in the master branch of cmetrics and created a tag for the code that will be part of a new release of CMetrics in the next weeks.

This new version of CMetrics is now more easy to use. Install as usual, and just run cmetrics on a directory contain C source code files, using the following command:

cmetrics target_directory
It will give you a table with all the size and complexity metrics for all the files under that directory (recursively scanned).

If you want information at the function level:

cmetrics -f target_directory
This is the first time cmetrics can be used using one unique tool instead of having to use a bunch of scripts that spit numbers out without telling anything else about what those numbers are.

However, this version still needs more documentation, and above all, more testing. So if you are interested, get the latest sources in the Git repository, or this snapshot:

You will need autotools (automake from 1.9 to 1.11), Python (>= 2.7, < 3.0), flex and gcc. Follow the INSTALL instructions in the above snapshot.

Finally have a look at the result of executing cmetrics to analyze itselft:

$ cmetrics cmetrics/
FILE           SLOC    LOC  FUNCS  BLANK  COM.L  COM.N  H LEN  H VOL    H LEVEL  H MEN. D.  MAXCY  MINCY  AVGCY  MEDCY
c_halsfilt.c    545   1265     26    341    379    206   7103  64358  4.953e-03  1.299e+07     87      1      5      1
argfiles.h       11     14      0      1      2      2     41    197  6.410e-01  3.070e+02      1      1      1      1
bdr.h             6     19      0      8      5      4     91    467  1.247e-01  3.744e+03      1      1      1      1
stripcom.c      256    288      5     16     16     13    844   5438  1.251e-02  4.348e+05     26      1     16     15
stripstr.c      128    156      2     14     14     10    516   3325  1.333e-02  2.495e+05     22      1     15     15
argfiles.c       98    119      2      9     12     15    391   2545  2.253e-02  1.129e+05     22      1     16     16
kdsi.c          147    200      3     21     32     11    646   4355  1.424e-02  3.059e+05     20      1     14      8

Legend:

  • FUNCS number of functions
  • BLANK number of blank lines
  • COM.L number of lines with comments
  • COM.N number of comments (they can be longer than a line)
  • H LEN Halstead’s Length
  • H VOL Halstead’s Volume
  • H LEVEL Halstead’s Level
  • H MEN. D. Halstead’s Mental Discriminations
  • MAXCY Maximum Cyclomatic Complexity
  • MINCY Minimum Cyclomatic Complexity
  • AVGCY Average Cyclomatic Complexity
  • MEDCY Median Cyclomatic Complexity
$ cmetrics -f cmetrics/
FILE          FUNC              SLOC  CYCLO  RETURN
c_halsfilt    yyset_in             1      1      0
c_halsfilt    *yyget_out           1      1      1
c_halsfilt    yy_flex_strlen       5      2      1
c_halsfilt    yypush_buffer_s     21      4      0
c_halsfilt    yyset_debug          1      1      0
c_halsfilt    yyset_out            1      1      0
c_halsfilt    yyset_lineno         2      1      0
c_halsfilt    *yyget_text          1      1      1
c_halsfilt    yy_scan_buffer      25      3      2
c_halsfilt    yyfree               1      1      0
c_halsfilt    *yyalloc             1      1      1
c_halsfilt    yyget_lineno         2      1      1
c_halsfilt    yypop_buffer_st     11      4      0
c_halsfilt    yy_fatal_error       2      1      1
c_halsfilt    yy_scan_bytes       24      4      1
c_halsfilt    yy_flex_strncpy      3      2      0
c_halsfilt    yylex_destroy       15      2      1
c_halsfilt    yy_init_globals     17      1      1
c_halsfilt    ***               1170     87      7
c_halsfilt    *yyrealloc           2      1      1
c_halsfilt    yyensure_buffer     34      5      0
c_halsfilt    yy_get_next_buf    112     21      3
c_halsfilt    yyget_leng           1      1      1
c_halsfilt    *yyget_in            1      1      1
c_halsfilt    yy_scan_string       2      1      1
c_halsfilt    yyget_debug          1      1      1
c_halsfilt    yy_load_buffer_      4      1      0
argfiles.h    ***                  3      1      0
bdr.h         ***                 13      1      0
stripcom.c    vmenustrip           5      2      0
stripcom.c    cstrip              68     26      0
stripcom.c    main                55     15      1
stripcom.c    shstrip             69     25      0
stripcom.c    poundstrip          39     16      0
stripstr.c    main                88     22      2
stripstr.c    nextfp              33      8      2
argfiles.c    filetype            61     22      1
argfiles.c    nextfp              39     10      2
kdsi.c        main                81     20      2
kdsi.c        nextfp              35      8      2
kdsi.c        GetChar             52     15      1

Lengend:

  • FUNC truncated function name
  • CYCLO cyclomatic complexity of the function
  • RETURN number of return statements