Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

Source Code Statistics

Source Code Statistics

Mike.Popoloski
Excursions into the Unknown · · 3 min read
1,337 11
I've always found it odd that Visual Studio does not include a good source code statistics counter, at least not in the Express, Standard, or Professional editions (I can't speak for any other versions). It's a relatively simple thing to do, so when I looked around the internet I was rather surprised to find a lack of line counter add-ins/programs that would work well with Visual Studio. Oh well, no source code line counting for me. I don't really need it, right?

Well, with each passing week I got more and more pissed off that I couldn't see a line count of my program. I don't know why; it's not like it's a critical feature necessary to complete my programs. It's just something I wanted to have. So after finally conquering my own laziness I sat down to write my own.

I quickly ruled out the possibility of making this an add-in for Visual Studio. Not only is the add-in model a nightmare to work with (and having to deal with multiple versions of Visual Studio extensibility models), but anyone using an Express edition would be out of luck right away. Obvious conclusion: make it a command line program. Josh Petrie had been telling me to do this for a while. As a command line program, it becomes trivial to integrate it into the build system to generate reports whenever the code is built.

I still wanted to avoid the hassle of messing with directories and configuring the program to do what I wanted, so I set it up to read from Visual Studio solution files. The program runs through each project in the solution, opens it up, reads out the list of files, and counts each one by hand. Getting all of this to work requires some XML trickery to read out the correct portions of each project, depending on whether it is a vcproj, a csproj, or a vbproj (or even a vdproj, for setup projects).

Right now the program only outputs some basic information to the console when it is done running. However, many more things are actually being tabulated and stored, so it's a relatively simple matter to generate a nice HTML report for all of it, which is what I'm working on now. Here is some example output after running it on SlimDX:

C:\Documents and Settings\mpopoloski\My Documents>linecounter SlimDX/build/SlimDX.slnWarning: Invalid project type: .vdprojWarning: Invalid project type: .vdprojProjects    : 19Files       : 896Directories : 172Total Lines : 138893Code Lines  : 70863Comments    : 47702Blank Lines : 20328C:\Documents and Settings\mpopoloski\My Documents>


People have been giving me some suggestions as to what else I should include. Two notable suggestions were a profanity counter and a cyclomatic complexity checker. One sounds fun and easy; the other, difficult and boring. I wonder what I should do [smile] If you have any suggestions of your own, let me know. It might be nice to have a good tool for all kinds of source code statistics.

If you want to try it out, it's quite easy to download and use. You can get the program here. Simply run it from a command prompt and pass the solution name as a parameter. Let me know how it goes. You could easily use this as an opportunity to show off your e-Penis (My source code is larger than your source code!)

EDIT: I made some tweaks to allow the use of a configuration file to determine which files get counted and how comments are determined. The download link is the same.

Discussion

Loading comments...