drtools-metric

How can I measure the health of source code?

Description

The DR-Tools Metric was born from the need to be a simple tool that could help developers in their daily work by presenting metrics and statistics related to the code.

The vast majority of metric tools are server-side, requiring multiple configurations and environments to be used. The DR-Tools Metric is a straightforward command-line interface (CLI) tool. We believe that the command line holds great power and flexibility.

We studied and selected some contextualized metrics that, when combined, can provide many insights to developers before they even analyze the code. We also aim to present these metrics in a way that facilitates analysis for developers. Additionally, we defined a set of analysis heuristics based on these metrics to ease the process and educate developers in their investigations.

drtools-metric in action

Requirements and Install Instruction

  • Unique requirement: JRE version 8
  • Download the tool version and unzip it to a directory
  • We suggest placing the directory reference in the system PATH, and Done!

Main Features

  • Command-line (CLI) usage
  • Flexibility
  • Download and run!
  • Context-selected and sorted metrics
  • Supported languages: Java (for now)
  • Outputs in different formats: console, CSV, and JSON
  • ease of filtering results (using the --top option)
  • Several statistics of metrics, like average, median, standard deviation, first quartile, third quartile, amplitude, min/max values, and upper fence (to detect outliers)
  • Contextualized results, to facilitate the analysis and investigation (metric thresholds are available here)
  • To visualize graphs of project data, simply use drtools-metric visualization. To do so, you can generate the data using the -mv option and --save output format.

Context and Metrics

The DR-Tools Metric presents the 44 contextualized metrics by summary, namespaces, types, methods, dependencies, and coupling. The following is the list of metrics by context:

  • Summary (15): Total of namespaces, total of types, mean number of types/namespaces, total of lines of code (SLOC), average number of SLOC/types (with median and standard deviation), total of methods, average number of methods/types (with median and standard deviation), total of complexity (CYCLO), and average number of complexity/types (with median and standard deviation)
  • Namespaces (2): Number of classes/types (NOC) and number of abstract classes (NAC)
  • Types (10): Lines of code (SLOC), number of methods (NOM), number of public methods (NPM), class complexity (WMC), number of dependencies (DEP), number of internal dependencies (I-DEP), Number of other types that depend on a given type (FAN-IN), number of other types referenced by a type (FAN-OUT), number of fields/attributes (NOA), and lack of cohesion in methods (LCOM3)
  • Methods (5): Lines of code (MLOC), cyclomatic complexity (CYCLO), number of invocations (CALLS), nested block depth (NBD), and number of parameters (PARAM)
  • Namespace Coupling (5): Afferent coupling (CA), efferent coupling (CE), instability (I), abstractness degree (A), and normalized distance (D)
  • Type Coupling (4): number of dependencies (DEP), number of internal dependencies (I-DEP), Number of other types that depend on a given type (FAN-IN), and number of other types referenced by a type (FAN-OUT)
  • Dependencies (3): General dependencies (DEP), internal dependencies (I-DEP), and cyclic dependencies

Video Demonstration

Usage examples

Below we list many examples of using DR-Tools Metric features.

  • Viewing tool usage options
  • prompt> drtools-metric

  • Viewing metric thresholds (console), using the option -mt
  • prompt> drtools-metric \repo\DrToolsMetric\src -mt --console

  • Viewing project summary information (console), using the option -s
  • prompt> drtools-metric \repo\DrToolsMetric\src -s --console

  • Viewing information about namespaces (console), using the option -n
  • prompt> drtools-metric \repo\DrToolsMetric\src -n --console

  • Viewing information about types (console), using the option -t
  • prompt> drtools-metric \repo\DrToolsMetric\src -t --console

  • Viewing information about the top 10 complex types (console), using the option --top
  • prompt> drtools-metric \repo\DrToolsMetric\src -t --console --top 10

  • Viewing information about types (CSV), using the option --csv
  • prompt> drtools-metric \repo\DrToolsMetric\src -t --csv > drtools-metric-types.csv

  • Viewing information about types (JSON), using the option --json
  • prompt> drtools-metric \repo\DrToolsMetric\src -t --json > drtools-metric-types.json

  • Generating all files needed for viewing with drtools-metric-visualization, using the -mv option and --save output
  • prompt> drtools-metric \repo\DrToolsMetric\src -mv --save

  • Viewing information about methods (console), using the option -m
  • prompt> drtools-metric \repo\DrToolsMetric\src -m --console

  • Verifying if the project has cyclic dependencies, using the option -cd
  • prompt> drtools-metric \repo\DrToolsMetric\src -cd --console

  • Viewing information about all dependencies (console), using the option -d
  • prompt> drtools-metric \repo\DrToolsMetric\src -d --console

  • Viewing information about internal dependencies (console), using the option -id
  • prompt> drtools-metric \repo\DrToolsMetric\src -id --console

  • Viewing information about namespace coupling (console), using the option -nc
  • prompt> drtools-metric \repo\DrToolsMetric\src -nc --console

  • Viewing information about type coupling (console), using the option -tc
  • prompt> drtools-metric \repo\DrToolsMetric\src -tc --console

  • Viewing information about statistic of method metrics (console), using the option -sm
  • prompt> drtools-metric \repo\DrToolsMetric\src -sm --console

  • Viewing information about statistic and type metrics (console), using the option -sat
  • prompt> drtools-metric \repo\DrToolsMetric\src -sat --console

References used to Metric Thresholds /

References
Danijel Radjenović, Marjan Heričko, Richard Torkar, Aleš Živkovič, Software fault prediction metrics: A systematic literature review, Information and Software Technology, Volume 55, Issue 8, 2013
Mariza A.S. Bigonha, Kecia Ferreira, Priscila Souza, Bruno Sousa, Marcela Januário, Daniele Lima, The usefulness of software metric thresholds for detection of bad smells and fault prediction, Information and Software Technology, Volume 115, 2019
T. Filo, M. Bigonha, and K. Ferreira, A catalogue of thresholds for object-oriented software metrics, in Advances and Trends in Software Engineering, 2015 The First International Conference on. IARIA, 2015
Kecia A.M. Ferreira, Mariza A.S. Bigonha, Roberto S. Bigonha, Luiz F.O. Mendes, Heitor C. Almeida, Identifying thresholds for object-oriented software metrics, Journal of Systems and Software, Volume 85, Issue 2, 2012
Rangasamy, R.Selvarani & Nair, T.R. & Ramachandran, Muthu & Prasad, Kamakshi. Software Metrics Evaluation Based on Entropy. Handbook of Research on Software Engineering and Productivity Technologies: Implications of Globalization, 2010
Robert C. Martin and Micah Martin. 2006. Agile Principles, Patterns, and Practices in C# (Robert C. Martin). Prentice Hall PTR, Upper Saddle River, NJ, USA
P. Oliveira, M. T. Valente and F. P. Lima, Extracting relative thresholds for source code metrics, 2014 Software Evolution Week - IEEE Conference on Software Maintenance, Reengineering, and Reverse Engineering (CSMR-WCRE), Antwerp, 2014
G. Vale, A benchmark-based method to derive metric thresholds, Master's Dissertation, UFMG, 2015
E. Lima, A. Resende, T. Lethbridge, The Uncomfortable Discrepancies of Software Metric Thresholds and Reference Values in Literature, ICSEA 2016 : The Eleventh International Conference on Software Engineering Advances, 2016
Checkstyle - Size Violations. https://checkstyle.sourceforge.io/config_sizes.html, 2019