Golang 代码调用可视化工具 go-callvis

说明

go-callvis 是一个可帮助使用交互式视图可视化 Go 程序调用图的开发工具。
这个工具的目的是为开发人员提供一个使用调用图数据及其与包和类型的关系的 Go 程序的可视化概览。
这在代码复杂度高的大型项目中或者试图理解其他人的代码时尤其有用。
gocallvis git地址: https://github.com/ofabry/go-callvis


安装使用

依赖

Go 1.17+
Graphviz (可选, 使用 -graphviz 标签时需要)

安装

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

安装好后 $GOBIN/bin目录下会生成可执行文件go-callvis

使用方法

命令行直接使用

go-callvis [可选项] <目标包>

运行后打开浏览器查看http://localhost:7878/即可
HTTP 服务器默认监听 http://localhost:7878/,使用选项 -http=“ADDR:PORT” 更改 HTTP 服务器地址。
如果想要生成单个输出文件,请使用选项 -file= < file path > 来选择输出文件目标。
输出格式默认为 svg,使用选项 -format=<svg|png|jpg|…> 选择不同的输出格式。
使用

go-callvis -h

查看所有可选项

Usage of go-callvis:
  -algo string
        The algorithm used to construct the call graph. Possible values inlcude: "static", "cha", "rta", "pointer" (default "pointer")
        用于构造调用图的算法。包括"static", "cha", "rta", "pointer" (默认"pointer")
  -cacheDir string
        Enable caching to avoid unnecessary re-rendering, you can force rendering by adding 'refresh=true' to the URL query or emptying the cache directory
        启用缓存以避免不必要的重新渲染,可以通过在 URL 查询中添加 'refresh=true' 或清空缓存目录来强制渲染
  -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")
        使用名称或导入路径关注特定包(默认为"main")
  -format string
        output file format [svg | png | jpg | ...] (default "svg")
        输出文件格式 [svg | png | .jpg | ...](默认“svg”)
  -graphviz
        Use Graphviz's dot program to render images.
        使用 Graphviz 的 dot 程序来渲染图像
  -group string
        Grouping functions by packages and/or types [pkg, type] (separated by comma) (default "pkg")
        按包和/或类型分组函数 [pkg, type](用逗号分隔)(默认为“pkg”)
  -http string
        HTTP service address. (default ":7878")
        HTTP 服务地址 (默认“: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)
        最小边长(用于更宽的输出)。 (默认 2-nodesep float
        Minimum space between two adjacent nodes in the same rank (for taller output). (default 0.35)
        同一等级的两个相邻节点之间的最小空间(用于更高的输出)。 (默认 0.35-nodeshape string
        graph node shape (see graphvis manpage for valid values) (default "box")
        图形节点形状(有关有效值,请参见 graphvis 手册页)(默认"box"-nodestyle string
        graph node style (see graphvis manpage for valid values) (default "filled,rounded")
        图形节点样式(有关有效值,请参见 graphvis 手册页)(默认"filled,rounded"-nointer
        Omit calls to unexported functions.
        省略对未导出函数的调用
  -nostd
        Omit calls to/from packages in standard library.
        省略对标准库中包的调用
  -rankdir string
        Direction of graph layout [LR | RL | TB | BT] (default "LR")
        图布局方向[LR | RL | TB | BT](默认“LR”)
  -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 build constraints in the documentation for the go/build package
        在构建过程中考虑满足的构建标签列表。有关构建标签的更多信息,请参阅 go/build 包的文档中的构建约束描述
  -tests
        Include test code.
        包括测试代码
  -version
        Show version and exit.
        显示版本并退出

例子

在这里插入图片描述

图例说明
Packages / Types 包/类型展示 (矩形)
focused 焦点包蓝色
stdlib 标准包绿色
other 其他包黄色
Functions / Methods 函数/方法展示 (圆角矩形/椭圆)
exported 导出粗体边框
unexported 未导出正常边框
anonymous 匿名虚线边框
Calls 调用展示 (箭线)
internal 包内函数黑色线
external 包外函数棕色线
static 静态函数实线
dynamic 动态函数虚线
regular 常规简单箭头
concurrent 并发带圆圈箭头
deferred defer延期带菱形箭头

本地测试使用

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值