Skip to main content

Overview

Highlights

Metrix++ is a tool to collect and analyse code metrics. Any metric is useless if it is not used. Metrix++ offers ease of introduction and integration with a variety of application use cases.

  • Monitoring trends (eg. on daily basis. In order to take actions or make right decisions earlier.)
  • Enforcing trends (eg. on hourly basis, at every commit of code changes.)
  • Automated asistance to review agains standards (eg. on per minute basis during code refactoring and code development.) The workflow sections below demonstarate these basic application usecases.

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 detects comments, strings and code for the preprocessor. The identified regions form a tree of nested source code blocks, which are subsequently refered to and scanned by metrics plugins. Thus the tool attributes metrics to regions, which provides fine grained data to analysis tools. The following example demonstrates the regions concept. The right side comments describe Metrix++ properties attributed to each source line: type of region, name of a region and type of a content of a region).

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

Metrics

The metrics highlighed in blue are per file metrics. The other metrics are per region metrics.

Metric (enable option)Brief descriptionMotivation / Potential use
std.general.sizeSize of a file in bytes.
  • Monitoring the growth of source code base.
  • Normalizing other metrics.
  • Preventing large files and regions (large things are difficult to maintain).
  • Predicting delivery dates by comparing S-shaped code base growth / change curves.
std.code.length.totalThe same as 'std.general.size' metric, but attributed to code regions.
std.code.filelines.totalNumber of non-blank lines of code of any content type (exectuable, comments, etc.) per file
std.code.lines.totalNumber of non-blank lines of code of any content type (exectuable, comments, etc.) per region
std.code.filelines.codeNumber of non-blank lines of code excluding preprocessor and comments per file.
std.code.lines.codeNumber of non-blank lines of code excluding preprocessor and comments per region.
std.code.filelines.preprocessorNumber of non-blank lines of preprocessor code per file.
  • Enforcing localisation of preprocessor code in a single place.
  • Encouraging usage of safer code structures instead of the preprocessor.
std.code.lines.preprocessorNumber of non-blank lines of preprocessor code per region.
std.code.filelines.commentsNumber of non-blank lines of comments per file.
  • Low number of comments may indicate maintainability problems.
std.code.lines.commentsNumber of non-blank lines of comments per region.
std.code.ratio.commentsRatio of non-empty lines of comments to non-empty lines of (code + comments) per region.
std.code.complexity.cyclomaticMcCabe 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.code.complexity.cyclomatic_switch_case_onceModified McCabe cyclomatic complexity metric which counts switch case constructs only once.
  • 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).
  • Switch case statements might be considered to be easier to read than other constructs. This metric encourages developers to use switch case where applicable.
std.code.complexity.maxindentMaximum level of indentation of blocks within a region.
std.code.magic.numbersNumber of magic numbers. There is an option to exclude 0, -1 and 1 numbers from counting.

Magic numbers are dangerous. The discussion on stackoverflow explains why.

std.code.todo.comments, std.code.todo.strings

Number of TODO/FIXME/etc markers in comments and strings accordingly. There is an option to configure a list of markers.

Manage potentially incomplete work. If project manager dispatches issues only in a tracker tool, todo markers are lost in the source code. The metric could make these 'lost' issues visible.

std.general.proctimeSeconds spent on processing a file.
  • Monitor and profile Metrix++ tool's performance.
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. There should be no false-positives to suppress with the right metric, but there 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 the application of a metric.

std.general.procerrorsNumber of errors detected by Metrix++ code parser.
  • Cleaning up errors to ensure reliable code scanning.
  • Errors, like mismatched brackets, may result in bad identification of regions.
std.code.maintindex.simple

Simple variant of maintainability index - a measure of maintainability. It uses std.code.lines:code and std.code.complexity:cyclomatic metrics to evaluate level of maintainability. Lower value of this index indicates better level maintainability

Identify code, which may benefit the most from refactoring.