go-callvis:Go調用關系圖(call graph)


一、簡介

用過SourceInsight、understand等軟件的同學一定知道call graph的功能,轉go開發后我用的是vscode和goland,一直在尋找調用關系圖的功能。本文介紹的是go-callvis的使用。官網:https://github.com/ofabry/go-callvis

功能說明:

  • 支持Go模塊!
  • 重點關注程序中的特定程序包
  • 單擊程序包以使用交互式查看器快速切換焦點
  • 功能分組:按包和(或)方法類型
  • 通過路徑前綴過濾包
  • 可選忽略標准庫中的函數
  • 可選忽略各種類型的函數調用

運行要求:

  • go 版本:1.13+
  • Graphviz(可選,僅帶-graphviz標志才需要)

注:我在使用時發現對於使用了cgo的包分析時效果不好。

二、使用說明

2.1 快速安裝

go get -u github.com/ofabry/go-callvis # or git clone https://github.com/ofabry/go-callvis.git cd go-callvis && make install

2.2 使用說明

go-callvis [可選參數] <包路徑>

1)使用瀏覽器交互展示

默認情況下,HTTP服務器在http://localhost:7878/上偵聽,請使用選項-http="ADDR:PORT"更改HTTP服務器地址。

2)靜態輸出

要生成單個輸出文件,使用選項-file=<file path>選擇輸出文件目標。

輸出格式默認為svg,使用選項-format=<svg|png|jpg|...>選擇其他輸出格式。

3)其他參數

-debug
         輸出詳細日志
   -file string
         以文件新式輸出結果,並將忽略server交互模式
   -focus string
         Focus specific package using name or import path. (default "main")
   -format string
         輸出文件的格式 [svg | png | jpg | ...] (默認 "svg")
   -graphviz
         使用Graphviz渲染圖像
   -group string
         分組功能,根據包 與/或 類型分組 [pkg, type] (用逗號分開) (默認 "pkg"),例如 -group pkg,type
   -http string
         HTTP 服務地址 (默認 ":7878")
   -ignore string
        忽略包含給定前綴的包路徑(用逗號分開)
   -include string
         包含具有給定前綴的包路徑 (用逗號分開)
   -limit string
         Limit package paths to given prefixes (separated by comma)
   -minlen uint
         Minimum edge length (for wider output). (default 2)
   -nodesep float
         Minimum space between two adjacent nodes in the same rank (for taller output). (default 0.35)
   -nointer
         忽略對未導出函數的調用。
   -nostd
         忽略標准庫的調用
   -skipbrowser
         跳過打開瀏覽器
   -tags build tags
         a list of build tags to consider satisfied during the build. For more information about build tags, see the description of build constraints in the documentation for the go/build package
   -tests
         包含測試代碼
   -version
         顯示版本號

 

4、使用示例:
1)解析main包
go-callvis -skipbrowser -nostd ./


2)解析testPkg包
go-callvis -group pkg,type -focus testPkg github.com/項目具體路徑 

 

2.3 效果圖說明

2q==

效果圖說明:

UntitledImage

 

參考:

https://www.lagou.com/lgeduarticle/96545.html

https://github.com/ofabry/go-callvis


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM