1. 程式人生 > >cloc代碼統計工具使用方法

cloc代碼統計工具使用方法

接下來 svn star 工作 ror 兩個文件 命令 lock ont

1.cloc簡介

cloc是用perl開發的代碼行數統計工具,支持多種編程語言,同樣也支持verilog。
之前在sourceforge上開發,現在已經轉移到github上。
目前的開發版本為1.66
代碼下載網址為:https://github.com/AlDanial/cloc/releases/tag/v1.66

2.cloc使用介紹

cloc的tar包中自帶一個README.md,這個文件用markdown語法寫的,已經詳細介紹了怎樣使用,下面簡要說一下怎樣使用cloc統計verilog的代碼行數

2.1exe文件放置

將下載好的文件放到常用工具目錄,並且將該目錄添加到環境變量path中

2.2命令行說明

f:\test\cloc_res.txt存放的是統計結果

1.統計單個文件
prompt > cloc --force-lang=Verilog-SystemVerilog f:\test\UE_TMP.v > f:\test\cloc_res.txt

       1 text file.
       1 unique file.                              
       0 files ignored.

https://github.com/AlDanial/cloc v 1.66  T=0.01 s (189.5 files/s, 11178.7 lines/s)
-----------------------------------------------------------------------------------
Language                         files          blank        comment           code
-----------------------------------------------------------------------------------
Verilog-SystemVerilog                1             11             38             10
-----------------------------------------------------------------------------------

2.統計目錄以及子目錄文件
prompt > cloc --force-lang=Verilog-SystemVerilog f:\test > f:\test\cloc_res.txt

      20 text files.
classified 20 files
      20 unique files.                              
       4 files ignored.

https://github.com/AlDanial/cloc v 1.66  T=0.32 s (62.2 files/s, 10019.9 lines/s)
-----------------------------------------------------------------------------------
Language                         files          blank        comment           code
-----------------------------------------------------------------------------------
Verilog-SystemVerilog               20            173            475           2573
-----------------------------------------------------------------------------------
SUM:                                20            173            475           2573
-----------------------------------------------------------------------------------

3.對比兩個目錄的文件
prompt > cloc --force-lang=Verilog-SystemVerilog --diff f:\test\src1 f:\test\src2 > f:\test\cloc_res.txt

      20 text files.
classified 20 files
      20 text files.
classified 20 files
 1:        1 unique file.                          
 2:        2 unique files.                          
       8 files ignored.                           

https://github.com/AlDanial/cloc v 1.66  T=0.32 s (3.1 files/s, 3.1 lines/s)
-----------------------------------------------------------------------------------
Language                         files          blank        comment           code
-----------------------------------------------------------------------------------
Verilog-SystemVerilog
 same                               19              0            475           2566
 modified                            1              0              0              4
 added                               0              0              0              4
 removed                             0              0              0              3
-----------------------------------------------------------------------------------
SUM:
 same                               19              0            475           2566
 modified                            1              0              0              4
 added                               0              0              0              4
 removed                             0              0              0              3
-----------------------------------------------------------------------------------

可以看到,對比的還是比較全面,修改了1個文件,修改4行代碼,增加了4行代碼,刪除了3行代碼

3.cloc與UE結合

3.1快速統計正在編寫的代碼行數

配置

打開UE的高級工具選項卡,添加cloc的命令,配置如下
技術分享
技術分享
技術分享

使用

打開一個verilog文件,執行cloc的高級工具或者,按 ctrl+shift+2的快捷鍵,就可以快速統計出該文件的代碼註釋等信息
技術分享

3.2 快速對比兩個文件或者兩個文件夾的源代碼

配置

要實現該功能,需要依靠腳本做一些工作,我做了一個cloc的腳本,添加到了腳本列表當中,並且該腳本的快捷鍵為 alt+f9
技術分享
腳本的代碼在
http://www.micrortl.com/svn/repos/zme/backup/UE/HDL_script/
用戶名和密碼都是 viewer

腳本默認要使用f:\test\cloc_cmd.bat的文件,第一次使用的話,請在該目錄新建一個空文件

實現

在ue中執行 clock.js 的腳本,首先腳本彈出的是是否要對比,點擊y確認。
接下來分別輸出兩個文件或者文件夾的路徑,確定之後,輸出框就會彈出對比結果。
技術分享

cloc代碼統計工具使用方法