Search This Blog

Thursday, October 29, 2009

SLOC

Recently I was browsing some open source project's(as usual I forgot the name) web site and the author has put SLOC report for his project. It was pretty cool. I wanted to try it on some of my projects and tried sloccount(http://www.dwheeler.com/sloccount/) in my office but since my office PC doesnt have my personal project sources I was not able to get SLOC report for my projects.

Today I suddenly, I remembered about SLOC and tried it on my Ace project. And here is the output
Sam@samxp /cygdrive/e/Projects
$ sloccount ace_test/src
Creating filelist for app
Creating filelist for drivers
Creating filelist for include
Creating filelist for kernel
Creating filelist for lib
Have a non-directory at the top, so creating directory top_dir
Adding /cygdrive/e/Projects/ace_test/src/wscript to top_dir
Categorizing files.
Finding a working MD5 command....
Found a working MD5 command.
Computing results.


SLOC Directory SLOC-by-Language (Sorted)
13716 include ansic=13699,sh=17
9045 kernel ansic=8810,asm=221,python=14
3712 lib ansic=3691,sh=11,python=10
1062 drivers ansic=1051,python=11
41 top_dir python=41
10 app ansic=6,python=4


Totals grouped by language (dominant language first):
ansic: 27257 (98.81%)
asm: 221 (0.80%)
python: 80 (0.29%)
sh: 28 (0.10%)

Total Physical Source Lines of Code (SLOC) = 27,586
Development Effort Estimate, Person-Years (Person-Months) = 6.51 (78.15)
(Basic COCOMO model, Person-Months = 2.4 * (KSLOC**1.05))
Schedule Estimate, Years (Months) = 1.09 (13.10)
(Basic COCOMO model, Months = 2.5 * (person-months**0.38))
Estimated Average Number of Developers (Effort/Schedule) = 5.97
Total Estimated Cost to Develop = $ 879,761
(average salary = $56,286/year, overhead = 2.40).
SLOCCount, Copyright (C) 2001-2004 David A. Wheeler
SLOCCount is Open Source Software/Free Software, licensed under the GNU GPL.
SLOCCount comes with ABSOLUTELY NO WARRANTY, and you are welcome to
redistribute it under certain conditions as specified by the GNU GPL license;
see the documentation for details.
Please credit this data as "generated using David A. Wheeler's 'SLOCCount'."
Pretty cool isnt it? :)

Tuesday, October 27, 2009

Funny numbers

Freebsd kernel source files count vs Makefile count. Just from the numbers it looks like for every 4 source files there is an Makefile. I ran these commands when I thought of converting FreeBSD build system(make) to use waf(http://code.google.com/p/waf/) or scons(http://www.scons.org/).

root@freebsd-sam:/sys#find . -name "*.c" | wc -l
3171
root@freebsd-sam:/sys#find . -name "*.h" | wc -l
3004
root@freebsd-sam:/sys#find . -name "*.s" | wc -l
44

root@freebsd-sam:/sys#find . -name "Makefile*" | wc -l
746

And yes, after seeing this number I let me thought to stay inside for sometime.

Saturday, October 03, 2009

Call Trace without modifying the source


While investigating about gcc flag "-fprofile-arcs", I came to know about a new(to me) gcc flag and this blog entry is about it. For any large C project it is hard to learn/find call graph through code walk. From C prospective unless otherwise you put a printf in each function entry/exit it is hard to find the call trace. 

GCC and ICC has a wonderful option "-finstrument-functions" to solve this. This option instructs the compiler to emit instructions to call a external function on each function's entry/exit. Defining these two functions like the following and adding the above option -finstrument-function to your makefile will do the magic.

void noinstrument __cyg_profile_func_enter(void *this_fn, void *call_site)
{
printf("%p called from %p\n", this_fn, call_site);
}

void noinstrument __cyg_profile_func_exit(void *this_fn, void *call_site)
{
printf("%p returns\n", this_fn);
}

Of course, you can do anything in these functions, for simplicity sake I just defined them as printfs.