[other] 代码量代码复杂度统计-lizard
lizard的可以用来统计下面的一些数据
- 不包含代码注释的代码行数
- CCN 代码的复杂度,也就是分支复杂度
- token的个数(关键字,标示符,常量,标点符号,操作符)
- 函数的参数个数
支持下列的一些语言
- C/C++ (works with C++14)
- Java
- C# (C Sharp)
- JavaScript
- Objective C
- Swift
- Python
- Ruby
- TTCN-3
- PHP
- Scala
- GDScript
downloadlink
https://github.com/terryyin/lizard
优点
- 不需要头文件全部指定(宏展开可能有失偏颇)
- 能够同时统计代码量和代码复杂度
- 能够产生和cppNCSS相同的报告
缺点
- c/c++的三字符组和双字符组
- c/c++的代码预处理和宏扩展没有实现
- c++的一些模版
对应的可以选择的参数
usage: lizard [options] [PATH or FILE] [PATH] ...
lizard is an extensible Cyclomatic Complexity Analyzer for many programming
languages including C/C++ (doesn't require all the header files). For more
information visit http://www.lizard.ws
positional arguments:
paths list of the filename/paths.
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
-l LANGUAGES, --languages LANGUAGES
List the programming languages you want to analyze. if
left empty, it'll search for all languages it knows.
`lizard -l cpp -l java`searches for C++ and Java code.
The available languages are: cpp, java, csharp,
javascript, python, objectivec, ttcn, ruby, php,
swift, scala, GDScript
-V, --verbose Output in verbose mode (long function name)
-C CCN, --CCN CCN Threshold for cyclomatic complexity number warning.
The default value is 15. Functions with CCN bigger
than it will generate warning
-f INPUT_FILE, --input_file INPUT_FILE
get a list of filenames from the given file
-L LENGTH, --length LENGTH
Threshold for maximum function length warning. The
default value is 1000. Functions length bigger than it
will generate warning
-a ARGUMENTS, --arguments ARGUMENTS
Limit for number of parameters
-w, --warnings_only Show warnings only, using clang/gcc's warning format
for printing warnings.
http://clang.llvm.org/docs/UsersManual.html#cmdoption-
fdiagnostics-format
--warning-msvs Show warnings only, using Visual Studio's warning
format for printing warnings.
https://msdn.microsoft.com/en-us/library/yxkt8b26.aspx
-i NUMBER, --ignore_warnings NUMBER
If the number of warnings is equal or less than the
number, the tool will exit normally; otherwise, it
will generate error. If the number is negative, the
tool exits normally regardless of the number of
warnings. Useful in makefile for legacy code.
-x EXCLUDE, --exclude EXCLUDE
Exclude files that match this pattern. * matches
everything, ? matches any single character,
"./folder/*" exclude everything in the folder
recursively. Multiple patterns can be specified. Don't
forget to add "" around the pattern.
-t WORKING_THREADS, --working_threads WORKING_THREADS
number of working threads. The default value is 1.
Using a bigger number can fully utilize the CPU and
often faster.
-X, --xml Generate XML in cppncss style instead of the tabular
output. Useful to generate report in Jenkins server
-H, --html Output HTML report
-m, --modified Calculate modified cyclomatic complexity number
-E EXTENSIONS, --extension EXTENSIONS
User the extensions. The available extensions are:
-Ecpre: it will ignore code in the #else branch.
-Ewordcount: count word frequencies and generate tag
cloud. -Eoutside: include the global code as one
function. -EIgnoreAssert: to ignore all code in
assert. -ENS: count nested control structures.
-s SORTING, --sort SORTING
Sort the warning with field. The field can be nloc,
cyclomatic_complexity, token_count, p#arameter_count,
etc. Or an customized field.
-T THRESHOLDS, --Threshold THRESHOLDS
Set the limit for a field. The field can be nloc,
cyclomatic_complexity, token_count, parameter_count,
etc. Or an customized file. Lizard will report warning
if a function exceed the limit
-W WHITELIST, --whitelist WHITELIST
The path and file name to the whitelist file. It's
'./whitelizard.txt' by default. Find more information
in README.
结果如下
(venv) ➜ fff git:(master) ✗ lizard
================================================
NLOC CCN token PARAM length location
------------------------------------------------
4 1 14 1 4 driver_write@6-9@./examples/driver_testing/driver.c
4 1 11 0 4 driver_read@11-14@./examples/driver_testing/driver.c
9 2 35 0 9 driver_init_device@16-24@./examples/driver_testing/driver.c
6 1 17 1 6 IO_MEM_RD8@15-20@./examples/driver_testing/driver.test.cpp
6 1 21 2 6 IO_MEM_WR8@25-30@./examples/driver_testing/driver.test.cpp
7 1 34 2 7 TEST@33-39@./examples/driver_testing/driver.test.cpp
8 1 40 2 8 TEST@42-49@./examples/driver_testing/driver.test.cpp
.........................................................................................
4 1 8 0 48 output_macro_counting_shortcuts@351-398@./fakegen.rb
8 1 9 0 9 output_c_and_cpp@400-408@./fakegen.rb
25 file analyzed.
==============================================================
NLOC Avg.NLOC AvgCCN Avg.token function_cnt file
--------------------------------------------------------------
19 5.7 1.3 20.0 3 ./examples/driver_testing/driver.c
4 0.0 0.0 0.0 0 ./examples/driver_testing/driver.h
43 6.8 1.0 28.0 4 ./examples/driver_testing/driver.test.cpp
47 8.5 1.0 57.8 4 ./examples/driver_testing/driver.test.fff.cpp
3 0.0 0.0 0.0 0 ./examples/driver_testing/hardware_abstraction.h
0 0.0 0.0 0.0 0 ./examples/driver_testing/registers.h
5 0.0 0.0 0.0 0 ./examples/embedded_ui/DISPLAY.h
2 0.0 0.0 0.0 0 ./examples/embedded_ui/SYSTEM.h
21 6.7 1.0 27.7 3 ./examples/embedded_ui/test_suite_template.c
41 7.0 1.4 22.8 5 ./examples/embedded_ui/UI.c
6 0.0 0.0 0.0 0 ./examples/embedded_ui/UI.h
129 8.7 1.0 49.8 13 ./examples/embedded_ui/UI_test_ansic.c
97 7.1 1.0 37.8 11 ./examples/embedded_ui/UI_test_cpp.cpp
4917 8.2 2.4 56.1 503 ./gtest/gtest-all.cc
5 4.0 1.0 27.0 1 ./gtest/gtest-main.cc
11679 5.5 1.3 63.7 774 ./gtest/gtest.h
4 0.0 0.0 0.0 0 ./test/c_test_framework.h
79 19.7 1.0 118.0 3 ./test/fff_test_c.c
25 6.5 1.0 34.0 2 ./test/fff_test_cpp.cpp
56 26.0 1.0 151.5 2 ./test/fff_test_global_c.c
17 7.0 1.0 24.0 1 ./test/fff_test_global_cpp.cpp
10 0.0 0.0 0.0 0 ./test/global_fakes.c
23 0.0 0.0 0.0 0 ./test/global_fakes.h
300 8.1 1.3 24.5 35 ./fakegen.rb
8 0.0 0.0 0.0 0 ./fff.h
=========================================================================================
!!!! Warnings (cyclomatic_complexity > 15 or parameter_count > 100 or length > 1000) !!!!
================================================
NLOC CCN token PARAM length location
------------------------------------------------
65 17 397 0 131 testing::internal::UnitTestImpl::RunAllTests@5449-5579@./gtest/gtest-all.cc
49 26 372 2 67 testing::internal::ParseGoogleTestFlagsOnlyImpl@6076-6142@./gtest/gtest-all.cc
19 16 147 3 20 testing::internal::AtomMatchesChar@8005-8024@./gtest/gtest-all.cc
==========================================================================================
Total nloc Avg.NLOC AvgCCN Avg.token Fun Cnt Warning cnt Fun Rt nloc Rt
------------------------------------------------------------------------------------------
17540 6.7 1.7 59.2 1364 3 0.00 0.01