go-callvis

ondrajzMIT更新放缓 有专家点评

用 Graphviz 把 Go 程序的函数调用关系画成可视化调用图,方便排查代码结构和依赖。

Visualize call graph of a Go program using Graphviz

v0.7.1发布于 2025-01-02 12:17 UTC6,528star +1 / 7 天429fork同步于 2026-11-11 23:33 UTC

专家点评

上手难度:进阶更新于 2026-11-11

把 Go 程序的调用图渲染成可点击的 Graphviz 视图,用来读陌生代码库或排查跨包调用

适用场景

  • 接手一个几十万行的 Go 仓库、想先摸清包之间的调用方向:跑一遍拿到全局图,比 grep 逐个追函数快得多,也比 IDE 的 find usages 更能看出层次
  • 排查「这个 handler 到底经由哪条路径调到那个 DB 层」这类跨包链路:用 -focus 指定包、按接收者类型分组,把无关的 stdlib 调用滤掉
  • 做重构前的依赖摸底:按导入路径前缀过滤,确认要拆的模块被谁引用,避免拆完才发现反向依赖
  • 代码审查里解释一处间接调用:把 dot 文件贴进现有 Graphviz 流水线,和架构图放一起看

踩坑

  • 模块解析是历史遗留的薄弱点:issue 里 support for modules、Not looking for packages in 'mod' location 这类反复被提,在 GOPATH 之外、多 module workspace 或 vendor 目录下跑,很可能拿不到完整调用图,先确认目标包能被 go list 正常解析
  • 新版 Go 工具链上出现过 nil pointer panic(v0.7.0 + go1.23.2 的 issue 有 11 条评论),升级 Go 后第一次跑建议先用小包验证,别直接对着大仓库跑
  • 默认行为是起 web 服务监听 localhost:7878,CI 或脚本里用必须显式加 -file 输出 dot,否则进程不退出;另外只有加 -graphviz 才需要装 Graphviz,纯 dot 输出不需要
  • 指针分析在超大仓库上耗时和内存都不小,README 没给规模上限,仓库越大越要先用 -ignore 和导入前缀把范围收窄

同类对比

想要更精确的跨过程分析可以看 golang.org/x/tools 里的 callgraph/pointer 包自己搭;只要包级依赖图、不需要函数级调用,go mod graph 或 goda 更轻。

怎么上手

由 README 提炼,执行前请确认
go install github.com/ofabry/go-callvis@latest
go-callvis <target package>
硬件要求按 README 说明

README 未说明,纯 Go 工具,无 GPU 或显存要求

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

用 Graphviz 把 Go 程序的调用图可视化出来,帮你看懂大型项目或别人的代码

用 Graphviz 把 Go 程序的函数调用关系画成可视化调用图,方便排查代码结构和依赖。

核心能力

  • 运行指针分析构建调用图并输出 dot 格式
  • 内置 Web 交互视图,点击包即可切换焦点
  • 支持按包或接收者类型对函数分组
  • 可按导入路径前缀过滤、忽略标准库调用
  • 可省略未导出函数及多种调用类型

容易踩的坑

需要 Go 1.19+;只有加 -graphviz 参数时才需要额外安装 Graphviz;默认以服务模式监听 localhost:7878,要输出单文件需显式指定 -file

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v0.7.1
  1. v0.7.1最新正式版2025-01-02 · 2025-01-02 12:17 UTC

    What's Changed

    New Contributors

    Full Changelog: https://github.com/ondrajz/go-callvis/compare/v0.7.0...v0.7.1

  2. v0.7.02023-05-08 · 2023-05-08 23:15 UTC
    查看更新说明

    What's Changed

    Many thanks to all new contributors! 🥇

    New Contributors

    Full Changelog: https://github.com/ofabry/go-callvis/compare/v0.6.1...v0.7.0

  3. v0.6.12020-08-05 · 2020-08-05 02:06 UTC
    查看更新说明
    • use Go library to render images (no need to install Graphviz)
    • by default group by packages
  4. v0.6.00.6.02020-03-06 · 2020-03-06 10:48 UTC
    查看更新说明
    • update changed username TrueFurby -> ofabry
  5. v0.5.00.5.02019-09-04 · 2019-09-04 07:30 UTC
    查看更新说明
    • support for Go modules #49

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Introduction

    The purpose of this tool is to provide developers with a visual overview of a Go program using data from call graph and its relations with packages and types. This is especially useful in larger projects where the complexity of the code much higher or when you are just simply trying to understand code of somebody else.

    Features

    • click on package to quickly switch the focus using interactive viewer
    • focus specific package in the program
    • group functions by package
    • group methods by their receiver type
    • filter packages to specific import path prefixes
    • ignore calls to/from standard library
    • omit various types of function calls

    Output preview

    main

    Check out the source code for the above image.

    How it works

    It runs pointer analysis to construct the call graph of the program and uses the data to generate output in dot format, which can be rendered with Graphviz tools.

    Quick start

    Installation

    Requirements
    • Go 1.19+
    • Graphviz (optional, required only with -graphviz flag)

    To install go-callvis, run:

    # Latest release
    go install github.com/ofabry/go-callvis@latest
    
    # Development version
    go install github.com/ofabry/go-callvis@master
    

    Alternatively, clone the repository and compile the source code:

    # Clone repository
    git clone https://github.com/ofabry/go-callvis.git
    cd go-callvis
    
    # Compile and install
    make install
    

    Usage

    Interactive viewer

    To use the interactive view provided by a web server that serves SVG images of focused packages, you can simply run:

    go-callvis <target package>

    HTTP server is listening on http://localhost:7878/ by default, use option -http="ADDR:PORT" to change HTTP server address.

    Render static output

    To generate a single output file use option -file=<file path> to choose output file destination.

    The output format defaults to svg, use option -format=<svg|png|jpg|...> to pick a different output format.

    Options
    Usage of go-callvis:
      -debug
        	Enable verbose log.
      -file string
        	output filename - omit to use server mode
      -cacheDir string
        	Enable caching to avoid unnecessary re-rendering.
      -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.
      -rankdir
            Direction of graph layout [LR | RL | TB | BT] (default "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
      -tests
        	Include test code.
      -algo string
            Use specific algorithm for package analyzer: static, cha, rta or vta (default "static")
      -version
        	Show version and exit.
    

    Run go-callvis -h to list all supported options.

    Reference guide

    Here you can find descriptions for various types of output.

    Packages / Types

    RepresentsStyle
    focusedblue color
    stdlibgreen color
    otheryellow color

    Functions / Methods

    RepresentsStyle
    exportedbold border
    unexportednormal border
    anonymousdotted border

    Calls

    RepresentsStyle
    internalblack color
    externalbrown color
    staticsolid line
    dynamicdashed line
    regularsimple arrow
    concurrentarrow with circle
    deferredarrow with diamond

    Examples

    Here is an example for the project syncthing.

    syncthing example

    Check out more examples and used command options.

    Community

    Join #go-callvis channel at gophers.slack.com. (not a member yet? get invitation)

    How to help

    Did you find any bugs or have some suggestions?

    • Feel free to open new issue or start discussion in the slack channel.

    Do you want to contribute to the project?

    • Fork the repository and open a pull request. Here you can find TODO features.

    Roadmap
    The interactive tool described below has been published as a separate project called goexplorer!

    Ideal goal of this project is to make web app that would locally store the call graph data and then provide quick access of the call graphs for any package of your dependency tree. At first it would show an interactive map of overall dependencies between packages and then by selecting particular package it would show the call graph and provide various options to alter the output dynamically.