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

I am a developer with an 18-year career in the Information Technology sector. Over the last half-decade, I’ve dedicated myself to advancing my expertise in the realm of intelligent information systems with a Master of Science in Information Systems (MScIS) degree. Notably, I recently completed a substantial socio-technical study, examining the feasibility of implementing responsible AI (RAI) within the public sector. Prior to my role in the public service, I undertook diverse software development roles as a contractor, a team lead and providing valuable services to post-secondary institutions. My driving passion revolves around the convergence of technology and the law, with a particular focus on the capacity of ethical AI systems to shed light on critical issues.

You may also like...