Management of source code quality is possible.

Highlights

Metrix++ is a tool to collect and analyse code metrics. Any metric is useless if it is not used. Metrix++ offers great usage capabilities and assists with variety of application use cases:

  • Monitoring trends on daily basis. In order to take actions or make right decisions earlier.
  • Enforcing trends on hourly basis, at every commit of code changes. In order to control quality in time, i.e. when it is not too late to redo.
  • Assisiting on per minute basis during code refactoring and code development, where coding and quality standards matter.

The workflow sections explain basic application principles.

Languages supported

The tool can parse C/C++, C# and Java source code files. The parser identifies certain regions in the code, such as classes, functions, namespaces, interfaces, etc. It obviously detects comments, strings and code for preprocessor. The identified regions form a tree of nested source code blocks, which are refered after and additionally scanned by metrics plugins. This concept allows to attribute metrics per regions, what gives fine grained data and rich input to analysis tools. The following example demonstrates this.

Source code Regions tree [type: name: content type]
// simple C++ code

#include <myapi.h>

// I explain the following class
class MyClass {
public:
    int m_var; // some member

    // I explain the following function
    MyClass(): m_var(0) {
        char str[] = "unused string"
        
        // nested region for good measure
        struct MyStruct {};
    }
    
    // Do not judge ugly code below
#define get_max(a,b) ((a)>(b)?(a):(b))
    set_max(int b) {
        m_var = get_max(m_var, b);
    }
};
// this is the last line
file: __global__: comment
file: __global__: code
file: __global__: preprocessor
file: __global__: code
    class: MyClass: comment
    class: MyClass: code
    class: MyClass: code
    class: MyClass: code, comment
    class: MyClass: code
        function: MyClass: comment
        function: MyClass: code
        function: MyClass: code, string
        function: MyClass: code
            struct: MyStruct: comment
            struct: MyStruct: code
        function: MyClass: code
    class: MyClass: code
        function: set_max: comment
        function: set_max: preprocessor
        function: set_max: code
        function: set_max: code
        function: set_max: code
    class: MyClass: code
file: __global__: comment

Metrics

Metrics highlighed in blue are per file metrics. Other metrics are per region metrics. Region term is explained in the previous chapter.

Metric (enable option) Brief description Motivation
std.general.size Size of a file in bytes.
  • Monitoring growth of source code base.
  • Normalizing other metrics.
  • Preventing large files and regions (large things difficult to maintain).
  • Predicting delivery dates by comparing S-shaped code base growth / change curves.
std.code.length.total The same as 'std.general.size' metric, but attributed to code regions.
std.code.lines.total Number of non-blank lines of code of any content type (exectuable, comments, etc.)
std.code.lines.code Number of non-blank lines of code excluding preprocessor, comments and strings.
std.code.lines.preprocessor Number of non-blank lines of preprocessor code.
  • Enforcing localisation of preprocessor code in a single place.
  • Encouraging usage of safer code structures instead of preprocessor.
std.code.lines.comments Number of non-blank lines of comments.
  • Low number of comments may indicate about maintainability problems.
std.code.complexity.cyclomatic McCabe cyclomatic complexity metric.
  • Identification of highly complex code for review and refactoring.
  • Preventing complex functions (complexity is a reason of many defects and a reason of expensive maintaintenance).
std.suppress An option enables collection of Metrix++ suppressions and 2 metrics: 'std.suppress:count' and 'std.suppress.file:count'. The first is number of suppressions per region. The second is the same but applies for file-scope metrics.
  • Suppressing false-positives.
  • Managing the amount of suppressions. Usually there are no false-positives to suppress with the right metric, but could be exceptions in specific cases. Managing suppressions is about managing exceptions. If there are many exceptional cases, maybe something is wrong with a metric or an application of a metric.
std.general.procerrors Number of errors detected by Metrix++ code parser. Errors, like mismatched brackets, may result in bad identification of regions.
  • Cleaning up errors to ensure reliable code scanning.
std.general.proctime Seconds spent on processing a file.
  • Monitor and profile tool's performance.

In order to get the tool working, dowload the archive with the latest stable version and unpack it to some folder. First run of the tool will trigger the installation within the folder, where it was launched.

Corresponding checkout from the version control system is the following:

svn checkout svn://svn.code.sf.net/p/metrixplusplus/code/releases/latest Metrix++

In order to checkout the latest version under development, use this command:

svn checkout svn://svn.code.sf.net/p/metrixplusplus/code/mainline Metrix++

Prerequisites

Python Runtime Environment (version 2.7.* or later, version 3.* has not been tested)

License

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 3 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the Metrix++; if not, contact Project Administrator

Collect data

...

View data

...

Apply thresholds

...

Suppressions

Metrix++ has got suppressions capability. Suppressions are collected from comments in code and used by post-processing tools, like 'limit'. It allows to take fine grained control over false-positive warnings, if there are.

New metric

describe METRIXPLUSPLUS_PATH environment variable

New language

...

New analysis tool

...

Feedback

...