Command Line Tools for Software Metrics

Learning Objectives

  • Identify tools for software metrics
  • Understand the techniques for using command line software metrics

Introduction

Command line tools are often the quickest way to start exploring software metrics. The installation process is easy, the commands are short and sweet and the text-based output is simple and understandable.

Command line tools often represent an interface to the operating system, so some of the following commands might only be available with certain OS flavours. The instructions have been verified to work on a Mac. Others, such as those that are written in Python, may feel similar to OS commands but likely have broader utility since they are less dependent on a specific OS.

Command line tools can be an efficient way to gain quick insights. They can be used to perform an initial risk assessment prior to procuring open source software or at consistent intervals throughout the development cycle. Both can be done on right in your desktop environment. They can even be baked right into a continuous integration pipeline.

Importance

The low barrier to get up and running with software metrics makes command line tools a desirable option for getting started. They are also the foundation upon which other tools can be built which means familiarity with the source can be established before things get abstracted away, behind a GUI.

Prerequisites

  • Familiarity with coding paradigms
  • Python 2.7 or 3.7 installed, basic Python knowledge
  • Access to a command line client (Terminal)
  • A locally hosted code repository
  • NOTE: some of the command line tool instructions may be specific to Mac OS / Linux

Goal and end-product

You’ll gain exposure to three command line tools for software metrics Radon, Graal and cloc. You’ll be familiar with the installation process and learn about some of the features and differences between the tools. Once you become familiar with the features and limitations, you may begin to make connections between which tool would be appropriate for different use cases.

Task Description

Exercise 1: Radon

Radon is a python tool that can be run on the command line. It is a Python library that evaluates only python code and produces a number of metrics including Cyclomatic Complexity, Maintainability Index and Halstead Complexity. It will also produce raw metrics such as LOC, LLOC, SLOC, and Comment Stats.

Prerequisites:

  • A local code base/repository with python code

Installation/Usage:

  1. Open up a command line client
  2. Move to the directory where your python code is, by typing `cd /path/to/my-python-project/`
  3. Install Radon, by typing `pip install radon`
  4. Verify it is installed, by typing `radon –version`
  5. Type your first Radon command! `radon raw . –summary`. You should expect to see an output similar to the one below.
  6. Use the documentation, or type `radon –help` to explore more features of Radon.

 

Screen shot of radon

Sample output from `radon raw . –summary`

Exercise 2: CLOC

cloc (Counting Lines of Code) is an open source tool that produces various outputs and, unlike Radon, is not limited to evaluating one language.

Installation/Usage:

  1. Open up a command line client
  2. Move to the directory where your python code is, by typing `cd /path/to/my-python-project/`
  3. Install cloc. Installation via package manager is the most straight forward way. `brew install cloc` works on a Mac.
  4. Verify it is installed, by typing `cloc –version`
  5. Type your first cloc command! `cloc .` You should see an output similar to the one below.
  6. Use the documentation, or type `man cloc`, or `cloc –help` to explore more features of cloc.
screen shot of output from cloc

Sample output from cloc using the command `cloc .`

Exercise 3: Graal

Graal is a Python library for ad hoc source code analysis that uses the git commit history

Prerequisites:

  • access to an open source github repository (replace my/repo below with an actual repo)

Installation:

  1. Open up a command line client
  2. Move to the directory where your python code is, by typing `cd /path/to/my-python-project/`
  3. Install graal. Type `pip install graal`
  4. Verify it is installed, by typing `graal –version`
  5. Run your first graal command! Type `graal cocom https://github.com/my/repo –git-path /tmp/graal-cocom`
  6. Use the documentation, or type `graal –help` to explore more features of graal.
screen shot of output from graal

Sample output from graal

Brad

A few of my favourite things: Agile software development with the potential for significant social impact combined with responsible and appropriate use of data, machine learning algorithms and systems that support research and evidence based decision making.

You may also like...