drtools-metric

How can I measure the health of source code?

Description

DR-Tools Metric was born out of the need for a simple tool that could support developers in their daily work by presenting meaningful metrics and statistics related to the code.

The vast majority of metric tools are server-side, requiring multiple configurations and complex environments to run. DR-Tools Metric, on the other hand, is a lightweight and straightforward command-line interface (CLI) tool. We believe the command line offers great power and flexibility.

We studied and selected a set of contextualized metrics that, when combined, can provide valuable insights to developers—even before they start analyzing the code. Our goal is also to present these metrics in a way that makes analysis easier and more intuitive. Additionally, we’ve defined a set of analysis heuristics based on these metrics to streamline the process and help educate developers during their investigations.

drtools-metric in action

Requirements and Install Instruction

  • Only requirement: JRE version 8
  • Download the tool and unzip it to a directory
  • We recommend adding the directory to your system PATH — and you're all set!

Main Features

  • Command-line (CLI) usage
  • Flexible
  • Download and run!
  • Context-selected and sorted metrics
  • Supported languages: Java (for now)
  • Output formats: console, CSV, and JSON
  • Easy filtering of results using the --top option
  • Various metric statistics, including average, median, standard deviation, first quartile, third quartile, range, min/max values, and upper fence (for outlier detection)
  • Contextualized results to facilitate analysis and investigation (metric thresholds are available here)
  • To visualize project data graphs, simply use drtools-metric visualization. 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