Calculate code metrics [closed]

Are there any tools available that will calculate code metrics (for example number of code lines, cyclomatic complexity, coupling, cohesion) for your project and over time produce a graph showing the trends?


On my latest project I used SourceMonitor. It's a nice free tool for code metrics analysis.
Here is an excerpt from SourceMonitor official site:

  • Collects metrics in a fast, single pass through source files.
  • Measures metrics for source code written in C++, C, C#, VB.NET, Java, Delphi, Visual Basic (VB6) or HTML.
  • Includes method and function level metrics for C++, C, C#, VB.NET, Java, and Delphi.
  • Saves metrics in checkpoints for comparison during software development projects.
  • Displays and prints metrics in tables and charts.
  • Operates within a standard Windows GUI or inside your scripts using XML command files.
  • Exports metrics to XML or CSV (comma-separated-value) files for further processing with other tools.

For .NET beside NDepend which is simply the best tool, I can recommend vil.

Following tools can perform trend analysis:

  • CAST
  • Klocwork Insight

Sonar is definitively a tool that you must consider, especially for Java projects. However it will also handle PHP or C/C++, Flex and Cobol code.

Here is a screenshot that show some metrics on a project:

alt text http://sonar.codehaus.org/wp-content/uploads/2009/05/squid-metrics.png

Note that you can try the tool by using their demo site at http://nemo.sonarsource.org


NDepend for .net


I was also looking for a code metrics tool/plugin for my IDE but as far as I know there are none (for eclipse that is) that also show a graph of the complexity over a specified time period. However, I did find the eclipse metrics plugin, it can handle:

  • McCabe's Cyclomatic Complexity
  • Efferent Couplings
  • Lack of Cohesion in Methods
  • Lines Of Code in Method
  • Number Of Fields
  • Number Of Levels
  • Number Of Locals In Scope
  • Number Of Parameters
  • Number Of Statements
  • Weighted Methods Per Class

And while using it, I didn't miss the graphing option you are seeking as well.
I think that, if you don't find any plugins/tools that can handle the graphing over time, you should look at the tool that suits you most and offers you all the information you need; even if the given information is only for the current build of your project.

As a side note, the eclipse metrics plugin allows you to export the data to an external file (link goes to an example), so if you use a source control tool, and you should!, you can always export the data for the specific build and store the file along with the source code, that way you still have a (basic) way to go back in time and check the differences.


keep in mind, What you measure is what you get. loc says nothing about productivity or efficency.

rate a programmer by lines of code and you will get.. lines of code. the same argument goes for other metrics.

otoh.. http://www.crap4j.org/ is a very conservative and useful metric. it sets complexity in relation with coverage.