GithubHelp home page GithubHelp logo

karnkaul / locc Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 1.0 150 KB

C++20 utility to count lines of code

License: GNU General Public License v3.0

CMake 8.11% C++ 91.89%
count-lines lines-of-code cpp cpp20

locc's Introduction

Lines of Code Counter

Build status

locc prints a small report summarising the counts of lines of code, given a root directory.

Usage

Syntax:

locc [options] <directory>

Output

Examples of output (may be out of date until release):

Linux kernel (20 million LOC)

$ time locc linux-master

 | File          |     Code |    Total | Comments | Files | Ratio |
 ------------------------------------------------------------------
 | C             | 16088983 | 19879024 |    35616 | 28969 | 0.748 |
 | C header      |  4909329 |  6079780 |   139577 | 21112 | 0.228 |
 | Plain Text    |   200603 |   242803 |        0 |  3230 | 0.009 |
 | JSON          |   175200 |   175200 |        0 |   328 | 0.008 |
 | Shell script  |    57795 |    82865 |    10413 |   517 | 0.003 |
 | Makefile      |    57108 |    66883 |        0 |  2581 | 0.003 |
 | Python        |    26771 |    34364 |     2778 |   113 | 0.001 |
 | C++           |     1993 |     2360 |       23 |     8 | 0.000 |
 | gitignore     |     1693 |     1716 |        0 |   254 | 0.000 |
 | CSV           |      209 |      210 |        0 |     6 | 0.000 |
 | CSS           |      105 |      138 |        0 |     1 | 0.000 |
 | C++ header    |       99 |      127 |        0 |     2 | 0.000 |
 | INI           |        7 |        8 |        0 |     1 | 0.000 |
 | gitattributes |        7 |        7 |        0 |     2 | 0.000 |
 | Total         | 21519902 | 26565485 |   188407 | 57124 | 1.000 |


real    0m0.729s
user    0m4.091s
sys     0m0.827s

This repo (v0.1)

$ ./locc --verbose -e=.md .

 | File                                         | LOC | Total | Comments |
 -------------------------------------------------------------------------
 | ./.appveyor.yml                              |  58 |    60 |        0 |
 | ./.gitattributes                             |   4 |     5 |        0 |
 | ./.gitignore                                 |  10 |    10 |        0 |
 | ./.gitmodules                                |  13 |    13 |        0 |
 | ./CMakeLists.txt                             |  61 |    72 |        0 |
 | ./CMakePresets.json                          |  45 |    45 |        0 |
 | ./README.md                                  |  95 |   126 |        0 |
 | ./compile_commands.json                      |  28 |    28 |        0 |
 | ./libs/clap/CMakeLists.txt                   |  13 |    18 |        0 |
 | ./libs/clap/README.md                        | 101 |   145 |        0 |
 | ./libs/clap/example/CMakeLists.txt           |   7 |     9 |        0 |
 | ./libs/clap/example/clapp.cpp                |  75 |    88 |        5 |
 | ./libs/clap/include/clap/interpreter.hpp     | 356 |   486 |       85 |
 | ./libs/clap/include/clap/parser.hpp          | 113 |   161 |       34 |
 | ./locc_settings.json                         |  81 |    81 |        0 |
 | ./out/db/cmake_install.cmake                 |  51 |    61 |        0 |
 | ./out/db/compile_commands.json               |  28 |    28 |        0 |
 | ./out/db/libs/clap/cmake_install.cmake       |  38 |    45 |        0 |
 | ./out/db/src/build_version.hpp               |  10 |    12 |        0 |
 | ./out/rl/cmake_install.cmake                 |  51 |    61 |        0 |
 | ./out/rl/libs/clap/cmake_install.cmake       |  38 |    45 |        0 |
 | ./out/rl/src/build_version.hpp               |  10 |    12 |        0 |
 | ./src/app/common.hpp                         |  81 |    97 |        0 |
 | ./src/app/config.cpp                         |  76 |    80 |        0 |
 | ./src/app/config.hpp                         |  76 |    88 |        2 |
 | ./src/app/line_counter.cpp                   | 144 |   155 |        0 |
 | ./src/app/line_counter.hpp                   |  24 |    31 |        0 |
 | ./src/kt/async_queue/async_queue.hpp         | 103 |   169 |       52 |
 | ./src/kt/async_queue/lockable.hpp            |  13 |    24 |        8 |
 | ./src/kt/async_queue/locker.hpp              |  53 |    86 |       16 |
 | ./src/kt/kthread/kthread.hpp                 |  52 |    78 |       18 |
 | ./src/kt/str_format/str_format.hpp           |  27 |    34 |        2 |
 | ./src/main.cpp                               |  51 |    53 |        0 |
 | ./src/ui/table_formatter/table_formatter.cpp |  83 |    91 |        0 |
 | ./src/ui/table_formatter/table_formatter.hpp | 109 |   127 |        0 |
 | ./src/ui/ui.cpp                              | 147 |   153 |        0 |
 | ./src/ui/ui.hpp                              |  51 |    62 |        0 |


 | File          | Code | Total | Comments | Files | Ratio |
 -----------------------------------------------------------
 | C++ header    | 1078 |  1467 |      217 |    14 | 0.454 |
 | C++           |  576 |   620 |        5 |     6 | 0.242 |
 | CMake script  |  259 |   311 |        0 |     7 | 0.109 |
 | Markdown      |  196 |   271 |        0 |     2 | 0.082 |
 | JSON          |  182 |   182 |        0 |     4 | 0.077 |
 | YAML          |   58 |    60 |        0 |     1 | 0.024 |
 | .gitmodules   |   13 |    13 |        0 |     1 | 0.005 |
 | gitignore     |   10 |    10 |        0 |     1 | 0.004 |
 | gitattributes |    4 |     5 |        0 |     1 | 0.002 |
 | Total         | 2376 |  2939 |      222 |    37 | 1.000 |

Performance

locc is incredibly lightweight when compared to loc / scc / etc (orders of magnitude smaller), and generally runs faster than them as well, albeit with the least amount of stats / customisation.

Stats on a 12 thread CPU with 32GB RAM, run on the Linux repo:

 | Program |    Size |     Execution Time     |
 ----------------------------------------------
 | loc     | 4786KiB |  758.000ms (+/-19.7ms) |
 | scc     | 4561KiB | 1135.667ms (+/-6.7ms)  |
 | locc    |  298KiB |  724.136ms (+/-4.7ms)  |

Options

locc supports a few command line parameters:

  • --skip-substr=<substr0>[,substr1,...]: Add path substring pattern to ignore
  • -e= / --extensions=<.ext0>[,.ext1,...]: Additional extensions to count in implicit mode
  • --sort-by=<column_name>: Sort results by column (lowercase, code by default)
  • -o / --one-thread: Run everything on the main thread
  • -b / --blanks: Include blank lines as lines of code
  • -q / --quiet: Print nothing but total lines of code
  • --verbose: Lots of output
  • -d / --debug: Misc debug output
  • -h / --help: Print help
  • --version: Print version

Building

Use CMake and a generator of your choice. Requirements:

  • Windows / Linux (any architecture)
  • C++20 compiler (and stdlib)

Contributing

Pull/merge requests are welcome.

Original Repository

locc's People

Contributors

karnkaul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

srijan-paul

locc's Issues

Table formatter

Create a simple formatting tool

Goals

  • Build columns/rows dynamically
  • Maintain running max width per column
  • Build output string / log directly

Possible approach:

  • add columns and optional headings: set max width = heading width
  • add row data:
    • add unnamed column if none exist
    • extract as many entries as columns
    • update max width

README

Add README.md to repo

Populate with:

  • project outline
  • binary usage
  • build setup

Logging module

Add a dedicated logging module/function

  • skip cerr if quiet
  • remove DOIF for logging, use param

Extension distribution table

Display distribution table per extension

Depends on #14

Build mapping of ext => line_counts, ratio, display table in regular mode.

Add new flag: q/quiet and move single-number output behaviour to that. Regular output should display summary table, including totals.

Refactor approach: instead of ignoring extensions, only count provided extensions. Two modes: explicit - file list passed, implicit - directory

  • Each extension will need a list of accompanying comment patterns
  • Use default patterns (stdin/built-in) for all, allow overriding per extension through config file
  • Use built-in extension config if none found
  • Explicit mode: count all files regardless of extension
  • Implicit mode: only count files in ext list

constexpr and noexcept

Add noexcept specification and use constexpr where applicable

Also add some comments, especially around file parsing

Improved threading

Add task system that uses a fixed number of worker threads and a thread safe queue

OS doesn't seem capable of launching arbitrary number of concurrent threads, so limit to hardware concurrency.

Have main thread work on tasks too

Let main thread be a "worker" too, popping tasks from the queue.

Misc

  • display per thread stats in debug

Help text

Add help text

Displays when prompted / when passed no input (logic already wired up, just edit the function).

Escaped comments not handled

"//comments" within quotes need to be counted as code

  • add escape logic and state:
    • find all quoted index pairs in line
      • if escaping, first index_pair.first will be null
      • if unterminated, last index_pair.second will be null and set escaping = true
    • if not escaping:
      • ignore comments within quoted index pairs
    • else:
      • count whole line

Configuration file

Introduce a config file that user may place in the working directory

Format: dumb simple (ini etc)
Data: all options: flags and values

Values:

  • ignores:
    • lines/blocks (comments)
    • substrings (directories / extensions, combine into one)

Rename repository

loc is already a Rust app that does the same thing, maybe rename to locc (LOC Counter)? ๐Ÿ˜Ž

Version

Add --version flag and CMake variable + generated header

Displays when prompted.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.