Monday, August 3, 2015

A little Software Engineering - Collect LOC metrics

To manage one's project, one thing is to collect metrics.

To count line of code in all project files, the CLOC [1] command line utility is easy to use.

For example, you can setup a batch file on windows for this purpose. On windows, you can put the cloc.exe executable in C:\windows\ so it's available anywhere in DOS.  Next, in general you need 2 files: 1) a exclude-list file, 2) a batch file to call the CLOC.exe utility.


-- cloc_exclude_list.txt --

c:\inetpub\wwwroot\my_site\backup
c:\inetpub\wwwroot\my_site\images

(Note you cannot put a back slash after the folder name.)


-- run_cloc.bat --

@echo off
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
echo Today is: %mydate%
echo.

cloc c:\inetpub\wwwroot\my_site --exclude-list-file=cloc_exclude_list.txt -out=cloc_log\short_%mydate%.txt
cloc c:\inetpub\wwwroot\my_site --exclude-list-file=cloc_exclude_list.txt -out=cloc_log\short_%mydate%.csv --csv

cloc c:\inetpub\wwwroot\my_site --exclude-list-file=cloc_exclude_list.txt --by-file -out=cloc_log\long_%mydate%.txt
cloc c:\inetpub\wwwroot\my_site --exclude-list-file=cloc_exclude_list.txt --by-file -out=cloc_log\long_%mydate%.csv --csv

(This will create 4 output files, for the combination of full/short list and txt/csv format,
prefixed by today's date. So you could setup a schedule task for this to run automatically everyday.)


[1] http://sourceforge.net/projects/cloc/
[2] http://stackoverflow.com/questions/203090/how-to-get-current-datetime-on-windows-command-line-in-a-suitable-format-for-us


1 comment:

Blogger said...

Quantum Binary Signals

Professional trading signals delivered to your cell phone daily.

Follow our signals NOW & earn up to 270% a day.

Blog Archive

Followers