3

I'm the current owner of a legacy C++ codebase. It's got a few dozen source & header files. The project is typically developed, built, and deployed on linux. In linux, the build system is scons/gcc, and the product is a single executable.

I want to generate Maintainability Index (MI) for various parts of the code, to help show that an update to the architecture in an area of the code is more maintainable than the previous architecture. So, I did some research and found that Visual Studio 2013 (for which I have an Ultimate license) will do this.

I successfully imported all of the source into a new VS2013 "Win32 Console Application." I have also gotten the source to build by making some changes to accomodate differences between gcc & VS2013.

I attempted to run "Analyze | Calculate Code Metrics for [project]" and VS2013 produced this error:

Project: [omitted]
Configuration: Debug
Scope: None
Assembly: [omitted]
Maintainability Index: 
Cyclomatic Complexity: 
Depth of Inheritance: 
Class Coupling: 
Lines of Code: 
Message: The project target file '[omitted]' contains no managed code.

So I changed the value of "Properties | Configuration Properties | General | Common Language Runtime Support" from "No CLR Support" to "Pure MSIL CLR Support", reran it, and got this in the "Code Metrics Results" window (doing my best to show what was output because I can't post images yet):

Hierarchy                       Maintainability Index   Cyclomatic Complexity ... 
----------------------------------------------------------------------------------
* [executable] (Debug)                             36                      31
  * Global                                         36                      31
    * main(int, char** const): int                 36                      31

I can't get more detail than main(), there's just no way to expand main() like there is with [executable] or Global. I thought that I'd be able to get a score on a per file, per-function, or per-class level.

Can anyone tell me:

  • Can VS2013 produce MI at a per- file, function, or class level?
  • How to do that?
  • Is there any software < $50 that I can run on the code in linux to generate MI?

I want to make minimal changes to the code, but I can easily make changes to project type, project properties, create a new project & re-import the source, change the build product to .dll or .lib, etc.

Avi Tevet
  • 778
  • 1
  • 7
  • 13
  • 1
    What's maintainability index? There might be a well known tool for Linux using different naming (for example [c++check](http://sourceforge.net/apps/mediawiki/cppcheck/index.php?title=Main_Page) [disclaimer - I haven't used the tool - I've just googled it]). – Maciej Piechotka Jan 10 '14 at 22:15
  • Maintainability Index is basically a metric that indicates the relative ease of maintaining code. More details: http://msdn.microsoft.com/en-us/library/bb385914.aspx & http://www.projectcodemeter.com/cost_estimation/help/GL_maintainability.htm. Thanks for the link to c++check, looking at it now. – Avi Tevet Jan 10 '14 at 22:35
  • Just looked at c++check - it's a good tool for static analysis but not what I'm looking for... what I'm looking for is something that can quantify how one way of implementing a complex math algorithm is easier to read and maintain than another way of implementing it. – Avi Tevet Jan 10 '14 at 22:39
  • Quick Googling has shown https://code.google.com/p/headerfile-free-cyclomatic-complexity-analyzer/ which have at least some keywords matching (cyclomatic complexity number) and counts nloc. Loc you can get with `wc -l` so you are left with Halstead Volume to get this number. – Maciej Piechotka Jan 10 '14 at 22:42
  • I think this is happening because my code is unmanaged C++, and I've found documentation that code metrics only runs on managed code. Apparently adding one of the /clr* options is not enough to generate useful results. One of my coworkers told me that I can generate MI using some custom scripts he wrote for Klocwork, which I also have a license for, so I am going to try that. – Avi Tevet Jan 15 '14 at 06:56

1 Answers1

2

As noted in my comment, this is happening because my code is unmanaged C++, and I've found documentation that code metrics only runs on managed code. Even adding one of the /clr options is not enough to get the metrics generated at a function level.

Avi Tevet
  • 778
  • 1
  • 7
  • 13
  • 2
    I think that you simply need to use a different tool. It's true that it's much easier to create one for managed code, but there are also some code analyzers for C++. If it isn't very complex metric, it should be easy to find. However, in C++, since templates and preprocessor can really sometimes wreak havoc, the code analyzers often are severely confused. Careful there ;) – quetzalcoatl Jan 16 '14 at 22:37
  • 3
    That's ultimately what I ended up doing... I was able to use Klocwork and some python scripts a coworker wrote to generate the metric. I think that, after this ordeal, I'm going to create a new Metric Metric, which is an index describing how easy it is to generate metrics on a particular codebase. – Avi Tevet Jan 17 '14 at 09:13