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:
- Open up a command line client
- Move to the directory where your python code is, by typing `cd /path/to/my-python-project/`
- Install Radon, by typing `pip install radon`
- Verify it is installed, by typing `radon –version`
- Type your first Radon command! `radon raw . –summary`. You should expect to see an output similar to the one below.
- Use the documentation, or type `radon –help` to explore more features 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:
- Open up a command line client
- Move to the directory where your python code is, by typing `cd /path/to/my-python-project/`
- Install cloc. Installation via package manager is the most straight forward way. `brew install cloc` works on a Mac.
- Verify it is installed, by typing `cloc –version`
- Type your first cloc command! `cloc .` You should see an output similar to the one below.
- Use the documentation, or type `man cloc`, or `cloc –help` to explore more features of 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:
- Open up a command line client
- Move to the directory where your python code is, by typing `cd /path/to/my-python-project/`
- Install graal. Type `pip install graal`
- Verify it is installed, by typing `graal –version`
- Run your first graal command! Type `graal cocom https://github.com/my/repo –git-path /tmp/graal-cocom`
- Use the documentation, or type `graal –help` to explore more features of graal.

Sample output from graal