C Quality Metrics

C Code Quality Metrics

Build Status Coverity Scan Build Status DOI

The program qmcalc will read a C source code file from its standard input and print on its standard output a single line containing tens of metrics regarding size, complexity, used keywords, comments and documentation, use of the C preprocessor, and observed formatting style. The full set of the metrics is documented in the file metrics.md.

The code has been written to run efficiently and reliably. The program receives the code to analyze from its standard input, so that it can process data coming e.g. directly out of a git show command, without having intermediate data touch the disk. Also, the program can process code that may not be easy (or possible) to fully parse using a compiler front-end, due e.g. to missing header files or an unknown compiler configuration.

Furthermore, the software is designed in a way that should allow its easy extension to other languages with C-like syntax, such as Java, C++, C#, and Go. The main thing you need to add is an XMetricsCalculator and an XKeyword class. Pull requests for such extensions are more than welcomed.

Building

Prerequisites

  • C++ compiler
  • GNU make
  • CppUnit for running make test

To build type change the directory to src (cd src) and run make. This will also generate the files header.tab and header.txt, which can be used for loading the output into other programs for further processing.

Install

cd src && make install

Running

  • The cmcalc program can process its standard input or report metrics on each of the specified files
  • The qmcalc-showstyle wrapper takes as a single argument a directory, and reports the metrics for each C file in the directory
  • The qmcalc-sumstyle wrapper takes as a single argument a directory, processes all C files in the directory, and for each metric from ncpp_directive and onward it reports
    • the metric's ordinal number,
    • the sum of the metric's values over all files, and
    • the percentage of files for which the metric is non-zero.

Further reading

The style checks performed are based on the following guidelines.

Citation

Owner
Diomidis Spinellis
Professor of Software Engineering and technology author.
Diomidis Spinellis
Comments
  • Incorrect metrics result from different brace positions at start of function

    Incorrect metrics result from different brace positions at start of function

    The software incorrectly computes metrics such as nstatement and cyclomatic_max when C code is formatted in certain ways. In the attached ZIP file are two copies of d1_lib.c, one from OpenSSL 0.9.8ze and the other from OpenSSL 0.9.8zf, along with qmcalc output for both. While the two files are approximately the same size (518 and 508 lines respectively), the number of statements computed for the 0.9.8ze version is 9, while the number of statements computed for the 0.9.8zf version is 169. Several other metrics like cyclomatic complexity show similar differences between the two files. Large differences in these metrics can be found in all .c files in those two versions of OpenSSL.

    When measuring size of these two files with cloc and sloccount, the results are quite similar. For example, cloc sees 75 blank lines, 92 comments, 351 lines of code in the 0.9.8ze version and 74 blank lines, 98 comment lines, and 336 lines of code in the 0.9.8zf version.

    The only major difference between the two files is formatting. The OpenSSL project reformatted code between the 0.9.8ze and 0.9.8zf releases. Functions in the 0.9.8e code have the beginning and end curly braces on their own lines preceded by a tab, while functions in the 0.9.8f code place curly braces at the beginning of lines. There are many indentation differences between files in the two versions too.

    example-file.zip

  • Implausibly high values for maximum statement nesting and cyclomatic complexity

    Implausibly high values for maximum statement nesting and cyclomatic complexity

    • Maximum nesting comes out at 57 when processing the kernel of FreeBSD 1.0.
    • Maximum cyclomatic complexity comes out 810 when processing used commands of FreeBSD 2.0.
  • Add Unix man page for cqmetrics

    Add Unix man page for cqmetrics

    • make-metrics-list-man.sh produces the cqmetrics.1 file based on metrics that are calculated by QualityMetrics.cpp and QualityMetrics.h
    • install-man rule is added to Makefile to download the man page to the system
  • qmcalc needs documentation

    qmcalc needs documentation

    The README file doesn't provide sufficient documentation to use qmcalc, either in the form of an expanded README or a man page. For example, the meaning of empty strings as NA isn't documented anywhere. I'm willing to help write documentation, but I don't know everything about qmcalc.

  • cqmetrics prints empty strings instead of zeros for metrics in some cases

    cqmetrics prints empty strings instead of zeros for metrics in some cases

    When running qmcalc on win2posix/sys/types.h from the BSDCoreUtils repository (https://github.com/DiegoMagdaleno/BSDCoreUtils), qmcalc prints several fields like statement_nesting_min as blanks instead of zeros. This particular file contains no statements. Here is the output of the command piped through "cat -vet" to show sequences of tabs with no numbers between them.

    qmcalc win2posix/sys/types.h | cat -vet 133^I9^I0^I13.7778^I13^I31^I9.56589^I1^I1^I0^I^I^I^I^I^I0^I0^I1^I0^I0^I0^I0^I0^I0^I0^I0^I0^I0^I0^I0^I0^I0^I0^I0^I0^I0^I2^I0^I0^I0^I0^I0^I1^I30^I30^I30^I30^I0^I1^I1^I1^I1^I1^I0^I7^I8^I10^I11^I11^I1.30931^I6^I8^I9.83333^I10.5^I11^I1.34371^I1^I4^I4^I4^I4^I0^I0^I1^I0^I0^I0^I0^I0^I0^I1^I0^I0^I0^I0^I0^I0^I0^I0^I0^I0^I0^I1^I0^I3^I1^I0^I0^I0^I1^I0^I0^I0^I0^I0^I0^I0^I0^I3^I0^I1$

    The full text of types.h is given below:

    enum { DEV_NULL, DEV_ZERO, DEV_URANDOM, NOT_DEVICE = -1 };

    #define DEFAULT_UID 4095 #define DEFAULT_GID DEFAULT_UID

  • Add invocation checking and usage information in sumstyle and showstyle files

    Add invocation checking and usage information in sumstyle and showstyle files

    This PR adds invocation checking and usage information in sumstyle and showstyle files.

    1. Check if qmcalc is installed
    2. Add -h argument with usage message
    3. Check if target directory exists.
  • Recreate metric files when QualityMetric.h is updated

    Recreate metric files when QualityMetric.h is updated

    That's a minor fix on make rules.

    Apart from QualityMetric.cpp, the make-header.sh script relies on the corresponding header file to generate the header.tab and header.txt files.

    So, this commit adds this dependency.

  • Two columns have name nfunction

    Two columns have name nfunction

    Two of the column headers have the same name "nfunction" and there is also a column named "nfunction2", all of which contain the function count. The duplicate name produces an error for some TSV parsers. While removing the duplicate columns would break scripts that parse data out of qmcalc by column position, renaming the second "nfunction" column to "nfunction1" would prevent the error and likely not cause any problems.

  • Issue #9 fixes complete

    Issue #9 fixes complete

    I apologize for the long delay. Events conspired to keep me from this project last semester, but I believe this pull request has all of your requested changes. If it doesn't, please let me know and I'll respond quickly.

    I plan to assign your paper on C programming practices in Unix for a reading and use cqmetrics for a software metrics assignment in my graduate software engineering class this semester.

  • Issue #2: Count parameters per function

    Issue #2: Count parameters per function

    This pull request also changes the heuristic of function detection. Specifically:

    An identifier which is followed by '(' is considered a function. This can be a function declaration (e.g. prototype):

    int foo(int x);
    

    or a function definition (with body):

    int foo(int x)
    {
        // Code here ...
    }
    

    This commit handles both cases and it introduces two metrics:

    • Number of function declarations (prototypes).
    • Number of function definitions.
  • Add metric which counts empty lines

    Add metric which counts empty lines

    To become familiar with the code, I start with something very simple. A counter of empty lines (contain only whitespace characters).

    I will continue with https://github.com/dspinellis/cqmetrics/issues/2.

  • Feature Request: Per Function Statistics

    Feature Request: Per Function Statistics

    I'm currently writing a research work including code quality metrics for linux tcp and lwip tcp. For this I want per-function metrics. I wrote a small perl script which split the functions appart and fed them to cqmetrics seperately.

    But for future uses such a cqmetrics built in functionality would be nice.

KDevelop plugin for automatic time tracking and metrics generated from your programming activity.

Wakatime KDevelop Plugin Installation instructions Make sure the project is configured to install to the directory of your choice: In KDevelop, select

Oct 13, 2021
Small library helping you with basic stuff like getting metrics out of your code, thread naming, etc.

CommonPP commonpp is a multi purpose library easing very few operations like: Getting metrics out of your program (counter, gauge, statistical descrip

Apr 11, 2022
An implementation of Actor, Publish-Subscribe, and CSP models in one rather small C++ framework. With performance, quality, and stability proved by years in the production.
An implementation of Actor, Publish-Subscribe, and CSP models in one rather small C++ framework. With performance, quality, and stability proved by years in the production.

What is SObjectizer? What distinguishes SObjectizer? SObjectizer is not like TBB, taskflow or HPX Show me the code! HelloWorld example Ping-Pong examp

Jun 17, 2022
Mumble is an Open Source, low-latency, high quality voice chat software
Mumble is an Open Source, low-latency, high quality voice chat software

Mumble is an Open Source, low-latency and high-quality voice-chat program written on top of Qt and Opus.

Jun 18, 2022
Nagios Plugin to check Call Quality in SIP VoIP (compatible checkmk, etc)

sipnagios Nagios Plugin to check Call Quality in SIP VoIP (compatible with check_mk, Zabbix, etc) sipnagios implements the Nagios plugin API for monit

Nov 16, 2021
High Quality DeNoise 3D is an AviSynth port of the MPlayer filter of the same name

High Quality DeNoise 3D is an AviSynth port of the MPlayer filter of the same name. It performs a 3-way low-pass filter, which can completely remove high-frequency noise while minimizing blending artifacts.

Jun 7, 2022
proftest is a C application for testing the quality of different operating system APIs for profiling.

proftest is a C application for testing the quality of different operating system APIs for profiling.

Jul 23, 2021
Wifi MQTT Data Logging via an esp8266 for the Ikea VINDRIKTNING PM2.5 air quality sensor
Wifi MQTT Data Logging via an esp8266 for the Ikea VINDRIKTNING PM2.5 air quality sensor

MQTT connectivity for the Ikea VINDRIKTNING This repository contains an ESP8266 firmware, which adds MQTT to the Ikea VINDRIKTNING PM2.5 air quality s

Jun 24, 2022
Guetzli is a JPEG encoder that aims for excellent compression density at high visual quality
Guetzli is a JPEG encoder that aims for excellent compression density at high visual quality

Guetzli is a JPEG encoder that aims for excellent compression density at high visual quality. Guetzli-generated images are typically 20-30% smaller than images of equivalent quality generated by libjpeg. Guetzli generates only sequential (nonprogressive) JPEGs due to faster decompression speeds they offer.

Jun 20, 2022
Video stabilization is a software-based approach in real-time to eliminating environmental effects (wind, heavy vehicle etc.) and enhance the visual performance that degrade video streaming quality.
Video stabilization is a software-based approach in real-time to eliminating environmental effects (wind, heavy vehicle etc.) and enhance the visual performance that degrade video streaming quality.

Video Stabilization Contents General Info Installation To Do General Info Video stabilization is a software-based approach in real-time to eliminating

Mar 7, 2022
Open source Altium Database Library with over 147,000 high quality components and full 3d models.
Open source Altium Database Library with over 147,000 high quality components and full 3d models.

Open source Altium Database Library with over 147,000 high quality components and full 3d models.

Jun 20, 2022
Visual odometry package based on hardware-accelerated NVIDIA Elbrus library with world class quality and performance.
Visual odometry package based on hardware-accelerated NVIDIA Elbrus library with world class quality and performance.

Isaac ROS Visual Odometry This repository provides a ROS2 package that estimates stereo visual inertial odometry using the Isaac Elbrus GPU-accelerate

Jun 19, 2022
Quality of Life Psych Engine Fork.
Quality of Life Psych Engine Fork.

ProjectFNF Quality of Life Psych Engine Fork "I Live My Life a Quarter Mile at a Time" - EastDeveloper WARNING: This engine is still very early in dev

Oct 26, 2021
Like the Vulkan C API but with quality of life improvements of C++

vk-simple-cpp Takes the current C headers and adds a few quality of life improvements while staying faithful to the original C API. Improvements: Enum

Feb 18, 2022
Sword Engine is a fork of Psych Engine that plans on adding more features and quality of life improvements.
Sword Engine is a fork of Psych Engine that plans on adding more features and quality of life improvements.

⚠️ WARNING: This README is currently incomplete, This warning will be removed once it's complete. Friday Night Funkin' - Sword Engine Sword Engine is

Mar 13, 2022
An AI for playing NES Tetris at a high level. Based primarily on search & heuristic, with high quality board evaluation through value iteration.

StackRabbit An AI that plays NES Tetris at a high level. Primarily based on search & heuristic, with high-quality board eval through value iteration.

Jun 14, 2022
Anti-Grain Evolution. 2D graphics engine for Speed and Quality in C++.

Anti-Grain Evolution This project is based on ideas found in Maxim (mcseem) Shemanarev's Anti-Grain Geometry library, but oriented towards maximizing

Apr 18, 2022
Cinder is a community-developed, free and open source library for professional-quality creative coding in C++.

Cinder 0.9.3dev: libcinder.org Cinder is a peer-reviewed, free, open source C++ library for creative coding. Please note that Cinder depends on a few

Jun 21, 2022
Get air quality & CO2 data from SM300D2 & Senseair S8 with ESP32, and export as OpenMetrics (Prometheus exporter) via WiFi.

ESP Air Sensor Get air quality & CO2 data from SM300D2 & Senseair S8 with ESP32, and export as OpenMetrics (Prometheus exporter) via WiFi. I used to h

Feb 6, 2022
DB Browser for SQLite (DB4S) is a high quality, visual, open source tool to create, design, and edit database files compatible with SQLite.
DB Browser for SQLite (DB4S) is a high quality, visual, open source tool to create, design, and edit database files compatible with SQLite.

DB Browser for SQLite What it is DB Browser for SQLite (DB4S) is a high quality, visual, open source tool to create, design, and edit database files c

Jun 16, 2022