[LINUX] Count Source lines of code (SLOC)

Introduction

Here's how to count the Source lines of code (SLOC). Let's measure SLOC using the source code of busybox as an example. The PC OS is Ubuntu 14.04.

cloc Install cloc. cloc is a Perl script file.

console


sudo apt-get install cloc

Analyze busybox-1.26.2. The result is as follows.

console


$ cloc busybox-1.26.2
    2056 text files.
    1657 unique files.                                          
    1145 files ignored.

http://cloc.sourceforge.net v 1.60  T=17.35 s (50.8 files/s, 15274.9 lines/s)
--------------------------------------------------------------------------------
Language                      files          blank        comment           code
--------------------------------------------------------------------------------
C                               631          24595          53365         158590
Bourne Shell                    163           1317           1278           7419
C/C++ Header                     60           1155           2176           5370
HTML                              9            420             32           3934
C++                               1            166             62           1197
make                              5            306            441            900
yacc                              1             93             20            570
Perl                              3             97            166            315
lex                               1             40             12            303
NAnt scripts                      1             84              0            260
Bourne Again Shell                4             47             86            203
IDL                               1              0              0             33
awk                               1              2              8             30
--------------------------------------------------------------------------------
SUM:                            881          28322          57646         179124
--------------------------------------------------------------------------------

It will be aggregated by language. The number of lines is counted by the number of files, blanks, comments, and code.

The result of the "--by-file" option.

console


$ cloc --by-file busybox-1.26.2
    2056 text files.
    1657 unique files.                                          
    1145 files ignored.

http://cloc.sourceforge.net v 1.60  T=16.65 s (52.9 files/s, 15924.0 lines/s)
----------------------------------------------------------------------------------------------------------------------
File                                                                               blank        comment           code
----------------------------------------------------------------------------------------------------------------------
busybox-1.26.2/shell/ash.c                                                          1153           1969          10476
(...)
busybox-1.26.2/arch/i386/Makefile                                                      1              5              1
----------------------------------------------------------------------------------------------------------------------
SUM:                                                                               28322          57646         179124
----------------------------------------------------------------------------------------------------------------------

This is the execution result of the "--diff" option.

console


$ cloc --diff busybox-1.26.2 busybox-1.27.2
    2056 text files.
    2101 text files.s
    2303 files ignored.                                         

http://cloc.sourceforge.net v 1.60  T=101.38 s (0.0 files/s, 0.0 lines/s)
--------------------------------------------------------------------------------
Language                      files          blank        comment           code
--------------------------------------------------------------------------------
(...)
C++
 same                             1              0             62           1197
 modified                         0              0              0              0
 added                            0              0              0              0
 removed                          0              0              0              0
(...)
C/C++ Header
 same                            52              0           2162           5316
 modified                         8              0              5             33
 added                            5            169            298            673
 removed                          0              0              9             21
(...)
C
 same                           389              0          51434         155066
 modified                       227              0            574           1237
 added                           38           1305           3978           8354
 removed                         15            295           1357           2287
-------------------------------------------------------------------------------
SUM:
 same                           609              0          55690         175471
 modified                       256              0            586           1306
 added                           48           1515           4322           9190
 removed                         16            301           1370           2347
-------------------------------------------------------------------------------

sample Check the operation of cloc using the source code example.

test.c


  1 #if 0
  2 const int rodata = 10;
  3 int data = 20;
  4 int bss = 0;
  5 #endif
  6 
  7 /*-
  8  * main function
  9  */
 10 int main(int argc, char* argv[])
 11 {
 12     return 0; /* no count comment */
 13 }
 14 

console


$ cloc test.c
       1 text file.
       1 unique file.                              
       0 files ignored.

http://cloc.sourceforge.net v 1.60  T=0.02 s (60.8 files/s, 850.7 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
C                                1              2              3              9
-------------------------------------------------------------------------------
$ cloc test.c
       1 text file.
       1 unique file.                              
       0 files ignored.

http://cloc.sourceforge.net v 1.60  T=0.02 s (57.8 files/s, 808.7 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
C                                1              2              3              9
-------------------------------------------------------------------------------

code is 9. Lines with only comments and blanks are not counted. Preprocessor instructions are counted. ** \ # if 0 is counted. ** **

Recommended Posts

Count Source lines of code (SLOC)
[Python] Read the source code of Bottle Part 2
[Python] Read the source code of Bottle Part 1
Quickly list multiple lines of text in your code
10. Counting the number of lines
Install ansible from source code
2.x, 3.x character code of python
Follow the flow of QAOA (VQE) at the source code level of Blueqat