skip to navigation
skip to content

metrics 0.2.8

metrics produces metrics for C, C++, Javascript, and Python programs


The original idea of metrics was a platform that can be extended with many different metrics. At the time I will focus only on SLOC and McCabe complexity metrics but keep its extensibility. metrics is build in a way to support many, many languages supported languages. Currently we test support for C, C++, JavaScript, and Python.

The SLOC metric counts the lines but excludes empty lines and comments. This is sometimes referred to as the source lines of code (SLOC). In literature this is often also referred as physical lines of code. I simplified it to something which to my understanding is the common denominator for the metric packages I looked into (CCCC, SLOCCount, PyMetrics, Eclipse-Metrics, Ohcount).

Another thing I wanted to mention is that I borrowed the sample programming language files for the test cases from Ohcount and Firefox.

Sample use

Get an overview on a package (number of files, used languages, and metrics):

$ metrics **/*
Metrics Summary:
Files                       Language        SLOC Comment McCabe
----- ------------------------------ ----------- ------- ------
    6                              C          14       3      0
    3                            C++        1114     236    108
    1                            INI           5       0      0
    2                           Java          27       8      1
    3                     JavaScript        1453      54    169
    1                       markdown           7       0      0
   18                         Python        1038     425    238
   11                      Text only           0       0      0
----- ------------------------------ ----------- ------- ------
   45                          Total        3658     726    516

Note how you can use glob file pattern or a list of files…

Usage help:

$ metrics --help
  --version             show program's version number and exit
  -h, --help            show this help message and exit
                        File containing list of path names to modules for
                        list of metrics to include in run. This is a comma
                        separated list of metric module names with no
                        whitespace. Optionally, you can specify the class name
                        of the metric by following the module name with a
                        colon (:) and the metric class name. (Default metrics
                        are 'mccabe:McCabeMetric,sloc:SLOCMetric'. Default
                        metric class name for metric module 'wxYz' is
                        'WxYzMetric' when only module name given -- note
                        capitalized metric class name.)
  -l LIB_NAME, --library=LIB_NAME
                        user-defined name applied to collection of modules
                        (Default is '')
  -q, --quiet           suppress normal summary output to stdout. (Default is
                        Choose an output format for a parser to read. Valid
                        choices: xml, csv

Get a detailed report:

$ metrics -q --format=csv metrics/

Same detailed report but output to csv file:

$ metrics -q --format=csv metrics/ > output.csv


Copyright (c) 2017 Fink Labs GmbH and others. metrics is released under the MIT License (see MIT_LICENSE).

File Type Py Version Uploaded on Size
metrics-0.2.8.tar.gz (md5) Source 2017-10-21 12KB