GoLang调用链可视化go-callvis使用介绍
作者:raoxiaoya 时间:2023-07-16 06:39:59
本文介绍一款工具 go-callvis,它能够将 Go 代码的调用关系可视化出来,并提供了可交互式的 web 服务。
go get -u github.com/ofabry/go-callvis
在windows系统上并没有自动安装,需要进入下载的目录go install
在linux系统上自动安装了
> 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 (可选,当工具指定了
-graphviz
时需要)
测试代码
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上可以正常运行,windows上会报错
> go-callvis main67.go
2022/09/21 15:28:50 http serving at http://localhost:7878
go-callvis 默认将代码调用关系存储成 svg 格式的图形。
在浏览器中访问 http://localhost:7878
点击上面的 log 模块,将会进入 log 模块的代码调用交互图中
它主要是作用是清晰的列出了包与包之间的依赖以及调用关系,用来理解项目的大致架构。
来源:https://blog.csdn.net/raoxiaoya/article/details/126974420
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
sql with as用法详解
详解Go strconv包
Python实现自动玩贪吃蛇程序
![](https://img.aspxhome.com/file/2023/0/127630_0s.gif)
pycharm使用anaconda全过程
![](https://img.aspxhome.com/file/2023/3/63873_0s.jpg)
SQL中 patindex函数的用法详解
Python实现基于HTTP文件传输实例
日期垂直排列的两种技巧
![](https://img.aspxhome.com/file/UploadPic/20098/28/01-16s.jpg)
php自定义函数call_user_func和call_user_func_array详解
小白讲座:在win下mysql备份恢复命令概括
pycharm中如何使用快捷键按出代码提示框
![](https://img.aspxhome.com/file/2023/8/84928_0s.jpg)
Python图像处理之图像的缩放、旋转与翻转实现方法示例
![](https://img.aspxhome.com/file/2023/4/93794_0s.jpg)
ASP编码问题的深入研究与解决方案(MSDN)
超全面的JavaScript开发规范(推荐)
![](https://img.aspxhome.com/file/2023/7/136477_0s.jpg)
php引用返回与取消引用的详解
sqlserver清空service broker中的队列的语句分享
Python中的filter()函数的用法
MySQL中存储的数据查询的时候如何区分大小写
![](https://img.aspxhome.com/file/2023/9/124089_0s.png)
mysql基础架构教程之查询语句执行的流程详解
![](https://img.aspxhome.com/file/2023/9/107439_0s.jpg)
Python爬虫新手入门之初学lxml库
![](https://img.aspxhome.com/file/2023/2/124952_0s.jpg)