This is the home page of "SLOCCount", a set of tools for counting physical Source Lines of Code (SLOC) in a large number of languages of a potentially large set of programs. This suite of tools was used in my papers More than a Gigabuck: Estimating GNU/Linux's Size and Estimating Linux's Size to measure the SLOC of entire GNU/Linux distributions, and my essay Linux Kernel 2.6: It's Worth More! Others have measured Debian GNU/Linux and the Perl CPAN library using this tool suite. SLOCCount runs on GNU/Linux, FreeBSD, Apple Mac OS X, Windows, and hopefully on other systems too. To run on Windows, you have to install Cygwin first to create a Unix-like environment for SLOCCount (Cygwin users: be sure to use ``Unix'' newlines, not ``DOS'' newlines, when you install Cygwin).
SLOCCount is released under the General Public License (GPL), so you can immediately download it -- at no cost! -- and you can modify it to suit your needs.
SLOCCount has a number of ease-of-use features. You can easily install it, particularly on RPM-based GNU/Linux systems. For most situations, once it's installed all you need to do is type this to measure all the code in a given directory (including its descendants):
sloccount directoryname
SLOCCount can automatically identify and measure the following languages (common extensions for the language are listed in parentheses):
SLOCCount includes a number of heuristics, so it can automatically detect file types, even those that don't use the "standard" extensions, and conversely, it can detect many files that have a standard extension but aren't really of that type. The SLOC counters have enough smarts to handle oddities of several languages. For example, SLOCCount examines assembly language files, determines the comment scheme, and then correctly counts the lines automatically. It also correctly handles language constructs that are often mishandled by other tools, such as Python's constant strings when used as comments and Perl's "perlpod" documentation.
SLOCCount will even automatically estimate the effort, time, and money it would take to develop the software (if it was developed as traditional proprietary software). Without options, it will use the basic COCOMO model, which makes these estimates solely from the count of lines of code. You can get better estimates if you have more information about the project; see the SLOCCount documentation for information on how to control the estimation formulas used in SLOCCount.
SLOCCount comes with extensive documentation - you should be able to just pick it up and use it.
I've received many nice comments about SLOCCount. Here are some:
And of course, simple use is a great testament to its utility. Krugle uses sloccount (here's an example), and I'm sure there are others. Thanks to everyone who enjoys the tool!
Here are some papers that reference SLOCCount:
You can:
SLOCCount is already packaged for Debian; you can just automatically download and install SLOCCount using Debian's normal tools (such as apt-get). You can see more information at the web page on Debian packages.
If you download the tar files, just follow the installation instructions in the README file. Let me head off one common email request: If you get error messages like "break_filelist: command not found", that means you didn't follow the installation directions. SLOCCount is actually a suite of programs, and you must make sure that your PATH environment variable includes the directory of the SLOCCount executable programs. That means you need to install the programs that your PATH variable already includes, or you need to modify your PATH variable. This is actually true for many programs, and isn't unique to SLOCCount at all.
SLOCCount currently only measures physical SLOC, and not the alternative logical SLOC. Adding logical SLOC should not be too difficult, it's just that I didn't need it for my purposes. If anyone wishes to add that capability, please do so; I accept patches.
It can only provide estimates, and if you don't calibrate it, it will use data from other programs that may or may not be representative.
Some versions of perl cause a problem in line 688 of break_filelist. Fixing this isn't as simple as it should be. If you replace:
open(FH, "-|", "md5sum", $filename) or return undef;with:
open(FH, "-|", "md5sum $filename") or return undef;it will "work" but create a massive security vulnerability. If the programs you analyze have nasty filenames like "x;rm -fr $HOME", the creator of the program can make you run arbitrary programs and cause bad things to happen (in this example, erasing all your files).
I have transitioned SLOCCount maintenance and support to SourceForge.net. It has a mailing list for discussion of use and modification, trackers for bugs and feature requests, and a publicly-accessible software configuration management system (using Subversion). If you use the tool significantly (or think you might), or are interested in making changes to it, please visit, join the mailing list, and become a part of the community.
To use sloc2html, first run sloccount using the --wide and --multiproject options, and store its results in a file. Then run sloc2html, with that filename as its own argument. Here's an example:
sloccount --wide --multiproject . > result.txt sloc2html.py result.txtBe sure to use the same filename for sloc2html.py that you stored on your system, and as always, make sure your PATH variable includes the directory where the executables are stored.
You can also view my home page.