[other] 代码量代码复杂度统计-lizard

lizard的可以用来统计下面的一些数据

  1. 不包含代码注释的代码行数
  2. CCN 代码的复杂度,也就是分支复杂度
  3. token的个数(关键字,标示符,常量,标点符号,操作符)
  4. 函数的参数个数

支持下列的一些语言

  • 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

优点

  1. 不需要头文件全部指定(宏展开可能有失偏颇)
  2. 能够同时统计代码量和代码复杂度
  3. 能够产生和cppNCSS相同的报告

缺点

  1. c/c++的三字符组和双字符组
  2. c/c++的代码预处理和宏扩展没有实现
  3. c++的一些模版

对应的可以选择的参数

  1. usage: lizard [options] [PATH or FILE] [PATH] ...
  2. lizard is an extensible Cyclomatic Complexity Analyzer for many programming
  3. languages including C/C++ (doesn't require all the header files). For more
  4. information visit http://www.lizard.ws
  5. positional arguments:
  6. paths list of the filename/paths.
  7. optional arguments:
  8. -h, --help show this help message and exit
  9. --version show program's version number and exit
  10. -l LANGUAGES, --languages LANGUAGES
  11. List the programming languages you want to analyze. if
  12. left empty, it'll search for all languages it knows.
  13. `lizard -l cpp -l java`searches for C++ and Java code.
  14. The available languages are: cpp, java, csharp,
  15. javascript, python, objectivec, ttcn, ruby, php,
  16. swift, scala, GDScript
  17. -V, --verbose Output in verbose mode (long function name)
  18. -C CCN, --CCN CCN Threshold for cyclomatic complexity number warning.
  19. The default value is 15. Functions with CCN bigger
  20. than it will generate warning
  21. -f INPUT_FILE, --input_file INPUT_FILE
  22. get a list of filenames from the given file
  23. -L LENGTH, --length LENGTH
  24. Threshold for maximum function length warning. The
  25. default value is 1000. Functions length bigger than it
  26. will generate warning
  27. -a ARGUMENTS, --arguments ARGUMENTS
  28. Limit for number of parameters
  29. -w, --warnings_only Show warnings only, using clang/gcc's warning format
  30. for printing warnings.
  31. http://clang.llvm.org/docs/UsersManual.html#cmdoption-
  32. fdiagnostics-format
  33. --warning-msvs Show warnings only, using Visual Studio's warning
  34. format for printing warnings.
  35. https://msdn.microsoft.com/en-us/library/yxkt8b26.aspx
  36. -i NUMBER, --ignore_warnings NUMBER
  37. If the number of warnings is equal or less than the
  38. number, the tool will exit normally; otherwise, it
  39. will generate error. If the number is negative, the
  40. tool exits normally regardless of the number of
  41. warnings. Useful in makefile for legacy code.
  42. -x EXCLUDE, --exclude EXCLUDE
  43. Exclude files that match this pattern. * matches
  44. everything, ? matches any single character,
  45. "./folder/*" exclude everything in the folder
  46. recursively. Multiple patterns can be specified. Don't
  47. forget to add "" around the pattern.
  48. -t WORKING_THREADS, --working_threads WORKING_THREADS
  49. number of working threads. The default value is 1.
  50. Using a bigger number can fully utilize the CPU and
  51. often faster.
  52. -X, --xml Generate XML in cppncss style instead of the tabular
  53. output. Useful to generate report in Jenkins server
  54. -H, --html Output HTML report
  55. -m, --modified Calculate modified cyclomatic complexity number
  56. -E EXTENSIONS, --extension EXTENSIONS
  57. User the extensions. The available extensions are:
  58. -Ecpre: it will ignore code in the #else branch.
  59. -Ewordcount: count word frequencies and generate tag
  60. cloud. -Eoutside: include the global code as one
  61. function. -EIgnoreAssert: to ignore all code in
  62. assert. -ENS: count nested control structures.
  63. -s SORTING, --sort SORTING
  64. Sort the warning with field. The field can be nloc,
  65. cyclomatic_complexity, token_count, p#arameter_count,
  66. etc. Or an customized field.
  67. -T THRESHOLDS, --Threshold THRESHOLDS
  68. Set the limit for a field. The field can be nloc,
  69. cyclomatic_complexity, token_count, parameter_count,
  70. etc. Or an customized file. Lizard will report warning
  71. if a function exceed the limit
  72. -W WHITELIST, --whitelist WHITELIST
  73. The path and file name to the whitelist file. It's
  74. './whitelizard.txt' by default. Find more information
  75. in README.

结果如下

  1. (venv) fff git:(master) lizard
  2. ================================================
  3. NLOC CCN token PARAM length location
  4. ------------------------------------------------
  5. 4 1 14 1 4 driver_write@6-9@./examples/driver_testing/driver.c
  6. 4 1 11 0 4 driver_read@11-14@./examples/driver_testing/driver.c
  7. 9 2 35 0 9 driver_init_device@16-24@./examples/driver_testing/driver.c
  8. 6 1 17 1 6 IO_MEM_RD8@15-20@./examples/driver_testing/driver.test.cpp
  9. 6 1 21 2 6 IO_MEM_WR8@25-30@./examples/driver_testing/driver.test.cpp
  10. 7 1 34 2 7 TEST@33-39@./examples/driver_testing/driver.test.cpp
  11. 8 1 40 2 8 TEST@42-49@./examples/driver_testing/driver.test.cpp
  12. .........................................................................................
  13. 4 1 8 0 48 output_macro_counting_shortcuts@351-398@./fakegen.rb
  14. 8 1 9 0 9 output_c_and_cpp@400-408@./fakegen.rb
  15. 25 file analyzed.
  16. ==============================================================
  17. NLOC Avg.NLOC AvgCCN Avg.token function_cnt file
  18. --------------------------------------------------------------
  19. 19 5.7 1.3 20.0 3 ./examples/driver_testing/driver.c
  20. 4 0.0 0.0 0.0 0 ./examples/driver_testing/driver.h
  21. 43 6.8 1.0 28.0 4 ./examples/driver_testing/driver.test.cpp
  22. 47 8.5 1.0 57.8 4 ./examples/driver_testing/driver.test.fff.cpp
  23. 3 0.0 0.0 0.0 0 ./examples/driver_testing/hardware_abstraction.h
  24. 0 0.0 0.0 0.0 0 ./examples/driver_testing/registers.h
  25. 5 0.0 0.0 0.0 0 ./examples/embedded_ui/DISPLAY.h
  26. 2 0.0 0.0 0.0 0 ./examples/embedded_ui/SYSTEM.h
  27. 21 6.7 1.0 27.7 3 ./examples/embedded_ui/test_suite_template.c
  28. 41 7.0 1.4 22.8 5 ./examples/embedded_ui/UI.c
  29. 6 0.0 0.0 0.0 0 ./examples/embedded_ui/UI.h
  30. 129 8.7 1.0 49.8 13 ./examples/embedded_ui/UI_test_ansic.c
  31. 97 7.1 1.0 37.8 11 ./examples/embedded_ui/UI_test_cpp.cpp
  32. 4917 8.2 2.4 56.1 503 ./gtest/gtest-all.cc
  33. 5 4.0 1.0 27.0 1 ./gtest/gtest-main.cc
  34. 11679 5.5 1.3 63.7 774 ./gtest/gtest.h
  35. 4 0.0 0.0 0.0 0 ./test/c_test_framework.h
  36. 79 19.7 1.0 118.0 3 ./test/fff_test_c.c
  37. 25 6.5 1.0 34.0 2 ./test/fff_test_cpp.cpp
  38. 56 26.0 1.0 151.5 2 ./test/fff_test_global_c.c
  39. 17 7.0 1.0 24.0 1 ./test/fff_test_global_cpp.cpp
  40. 10 0.0 0.0 0.0 0 ./test/global_fakes.c
  41. 23 0.0 0.0 0.0 0 ./test/global_fakes.h
  42. 300 8.1 1.3 24.5 35 ./fakegen.rb
  43. 8 0.0 0.0 0.0 0 ./fff.h
  44. =========================================================================================
  45. !!!! Warnings (cyclomatic_complexity > 15 or parameter_count > 100 or length > 1000) !!!!
  46. ================================================
  47. NLOC CCN token PARAM length location
  48. ------------------------------------------------
  49. 65 17 397 0 131 testing::internal::UnitTestImpl::RunAllTests@5449-5579@./gtest/gtest-all.cc
  50. 49 26 372 2 67 testing::internal::ParseGoogleTestFlagsOnlyImpl@6076-6142@./gtest/gtest-all.cc
  51. 19 16 147 3 20 testing::internal::AtomMatchesChar@8005-8024@./gtest/gtest-all.cc
  52. ==========================================================================================
  53. Total nloc Avg.NLOC AvgCCN Avg.token Fun Cnt Warning cnt Fun Rt nloc Rt
  54. ------------------------------------------------------------------------------------------
  55. 17540 6.7 1.7 59.2 1364 3 0.00 0.01

[other] 代码量代码复杂度统计-lizard的更多相关文章

  1. [statsvn]-svn代码量统计

    用statasvn进行代码量统计的时候,第一步需要获取到项目的日志,但是我本机的svn1.4没有安装命令行,重新运行1.4的安装包也没有命令行的选项... 那就升级到最新的svn1.8好了,下载最新的 ...

  2. Git 常用命令和统计代码量

    摘要 分享Git日常操作中常用的命令,分享如何统计在项目中贡献的代码量. 下面列出Git bash常用命令. 1. git clone **(项目地址) 克隆一个git项目到本地,将git项目拉取到本 ...

  3. 在windows 上统计git 代码量

    1 需要系统安装 git + gawk git 安装自行百度 gawk 到官网下载 http://gnuwin32.sourceforge.net/packages/gawk.htm 1.2 下载好后 ...

  4. Python 统计代码量

    #统计代码量,显示离10W行代码还有多远 #递归搜索各个文件夹 #显示各个类型的源文件和源代码数量 #显示总行数与百分比 import os import easygui as g #查找文件 def ...

  5. git 统计代码量 shell脚本

    #!/bin/bash # 统计代码量 # 使用方法: sh gitstat.sh "2017-11-01" "2017-11-30" "JamKon ...

  6. git统计项目中成员代码量

    查看git上个人代码量 git log --author="username" --pretty=tformat: --numstat | awk '{ add += $1; su ...

  7. IDEA 代码量统计(Statistic)

    IDEA 代码量统计(Statistic) 1.1 前言 项目到了一定阶段,都会想要看看项目的代码量情况,这里主要使用插件Statistic进行代码统计查看. 1.2 安装插件步骤 找到插件市场入口并 ...

  8. “代码量统计脚本”

    概述 本文从一段统计C/C++程序脚本入手,记录shell脚本常用和重要的知识点. 代码量统计程序 文件名称,count_code_line.sh 12345678910111213141516171 ...

  9. (转)通过gitlab统计git提交的代码量

    git的代码量大多数都是根据命令行统计,或者根据第三方插件统计.但是都不满足我的需求,因为我们代码都由gitlab管理,于是想到了通过gitlab暴露出来的接口获取数据. 第一步,生成私钥 登录你的g ...

随机推荐

  1. FPGA各大厂商,不可不知

    引言: FPGA市场前景诱人,但是门槛之高在芯片行业里无出其右.全球有60多家公司先后斥资数十亿美元,前赴后继地尝试登顶FPGA高地,其中不乏英特尔.IBM.德州仪器.摩托罗拉.飞利浦.东芝.三星这样 ...

  2. npm国内镜像介绍

    这个也是网上搜的,亲自试过,非常好用! 镜像使用方法(三种办法任意一种都能解决问题,建议使用第三种,将配置写死,下次用的时候配置还在): 1.通过config命令 npm config set reg ...

  3. Mysql参见SHOW命令总结

    Mysql参见SHOW命令总结 MySQL Show命令的用法大全

  4. Spring缓存源码剖析:(一)工具选择

    从本篇开始对Spring 4.3.6版本中Cache部分做一次深度剖析.剖析过程中会对其中使用到的设计模式以及原则进行分析.相信对设计内功修炼必定大有好处. 一.环境及工具 IntelliJ IDEA ...

  5. 三个线程打印ABC10次,ABCABCABC....

    // ConsoleApplication2.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream&g ...

  6. STM32使用printf丢失第一个字母的问题

    STM32使用printf函数给串口打印信息的执行步骤为: 1.重定向printf函数 给uart.c文件中增加如下函数: //重定向c库函数printf到USART1 int fputc(int c ...

  7. 1.1.Task Queue

      任务队列是一种跨线程.跨机器工作的一种机制.   任务队列中包含称作任务的工作单元.有专门的工作进程持续不断的监视任务队列,并从中获得新的任务并处理.   celery通过消息进行通信,通常使用一 ...

  8. BeX5 常见问题解决办法

    1.获取当前Activity的名称 Activity activity = ProcessUtils.getActivityInProcessContext(); String activityNam ...

  9. jqurey datatable tableTools 自定义button元素 以及按钮定义事件

    版本 1.10.4 "dom": 'T<"clear">lfrtip', "tableTools": { //"sSw ...

  10. Python绘图matplotlib

    转自http://blog.csdn.net/ywjun0919/article/details/8692018 Python图表绘制:matplotlib绘图库入门 matplotlib 是pyth ...