GoLang調(diào)用鏈可視化go-callvis使用介紹
本文介紹一款工具 go-callvis,它能夠?qū)?Go 代碼的調(diào)用關(guān)系可視化出來(lái),并提供了可交互式的 web 服務(wù)。
go get -u github.com/ofabry/go-callvis
在windows系統(tǒng)上并沒(méi)有自動(dòng)安裝,需要進(jìn)入下載的目錄go install
在linux系統(tǒng)上自動(dòng)安裝了
> go-callvis
go-callvis: visualize call graph of a Go program.
Usage:
go-callvis [flags] package
Package should be main package, otherwise -tests flag must be used.
Flags:
-debug
Enable verbose log.
-file string
output filename - omit to use server mode
-focus string
Focus specific package using name or import path. (default "main")
-format string
output file format [svg | png | jpg | ...] (default "svg")
-graphviz
Use Graphviz's dot program to render images.
-group string
Grouping functions by packages and/or types [pkg, type] (separated by comma) (default "pkg")
-http string
HTTP service address. (default ":7878")
-ignore string
Ignore package paths containing given prefixes (separated by comma)
-include string
Include package paths with given prefixes (separated by comma)
-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
Omit calls to unexported functions.
-nostd
Omit calls to/from packages in standard library.
-skipbrowser
Skip opening browser.
-tags build tags
a list of build tags to consider satisfied during the build. For more information about build tags, see the description of buil
d constraints in the documentation for the go/build package
-tests
Include test code.
-version
Show version and exit.
依賴
- Go 1.17+
- Graphviz (可選,當(dāng)工具指定了
-graphviz時(shí)需要)
測(cè)試代碼
package main
import (
"log"
"net"
)
func main() {
// Part 1: create a listener
l, err := net.Listen("tcp", ":8000")
if err != nil {
log.Fatalf("Error listener returned: %s", err)
}
defer l.Close()
for {
// Part 2: accept new connection
c, err := l.Accept()
if err != nil {
log.Fatalf("Error to accept new connection: %s", err)
}
// Part 3: create a goroutine that reads and write back data
go func() {
log.Printf("TCP session open")
defer c.Close()
for {
d := make([]byte, 1024)
// Read from TCP buffer
_, err := c.Read(d)
if err != nil {
log.Printf("Error reading TCP session: %s", err)
break
}
log.Printf("reading data from client: %s\n", string(d))
// write back data to TCP client
_, err = c.Write(d)
if err != nil {
log.Printf("Error writing TCP session: %s", err)
break
}
}
}()
}
}
在linux上可以正常運(yùn)行,windows上會(huì)報(bào)錯(cuò)
> go-callvis main67.go
2022/09/21 15:28:50 http serving at http://localhost:7878
go-callvis 默認(rèn)將代碼調(diào)用關(guān)系存儲(chǔ)成 svg 格式的圖形。
在瀏覽器中訪問(wèn) http://localhost:7878

點(diǎn)擊上面的 log 模塊,將會(huì)進(jìn)入 log 模塊的代碼調(diào)用交互圖中

它主要是作用是清晰的列出了包與包之間的依賴以及調(diào)用關(guān)系,用來(lái)理解項(xiàng)目的大致架構(gòu)。
到此這篇關(guān)于GoLang調(diào)用鏈可視化go-callvis使用介紹的文章就介紹到這了,更多相關(guān)Go callvis內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
使用Go語(yǔ)言實(shí)現(xiàn)Yaml編碼和解碼的方法詳解
在這篇文章中,我們將介紹如何使用Go語(yǔ)言編寫代碼來(lái)實(shí)現(xiàn)Yaml編碼和解碼,文中有詳細(xì)的代碼示例供大家參考,對(duì)大家的學(xué)習(xí)和工作有一定的幫助,需要的朋友可以參考下2023-11-11
Golang微服務(wù)框架Kratos實(shí)現(xiàn)分布式任務(wù)隊(duì)列Asynq的方法詳解
任務(wù)隊(duì)列(Task Queue) 一般用于跨線程或跨計(jì)算機(jī)分配工作的一種機(jī)制,在Golang語(yǔ)言里面,我們有像Asynq和Machinery這樣的類似于Celery的分布式任務(wù)隊(duì)列,本文就給大家詳細(xì)介紹一下Golang微服務(wù)框架Kratos實(shí)現(xiàn)分布式任務(wù)隊(duì)列Asynq的方法,需要的朋友可以參考下2023-09-09
Go語(yǔ)言中一定要知道的切片使用注意事項(xiàng)總結(jié)
了解和掌握切片的使用注意事項(xiàng),可以避免意外的程序行為,所以本文就來(lái)和大家深入探討一下Go語(yǔ)言切片常見的注意事項(xiàng),希望對(duì)大家有所幫助2023-06-06
一篇文章說(shuō)清楚?go?get?使用私有庫(kù)的方法
這篇文章主要介紹了go?get?如何使用私有庫(kù),本文會(huì)明確指出Git?、golang的配置項(xiàng),附送TortoiseGit?+?Git混合配置,需要的朋友可以參考下2022-09-09
go build 通過(guò)文件名后綴實(shí)現(xiàn)不同平臺(tái)的條件編譯操作
這篇文章主要介紹了go build 通過(guò)文件名后綴實(shí)現(xiàn)不同平臺(tái)的條件編譯操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-12-12

