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

原文地址:https://www.cnblogs.com/realjimmy/p/13775842.html