项目作者: ofabry

项目描述 :
Visualize call graph of a Go program using Graphviz
高级语言: Go
项目地址: git://github.com/ofabry/go-callvis.git
创建时间: 2016-09-03T11:31:46Z
项目社区:https://github.com/ofabry/go-callvis

开源协议:MIT License

下载


gopher

go-callvis


Github release
Build status
go-recipes
Slack channel

go-callvis is a development tool to help visualize call graph of a Go program using interactive view.


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:

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

Alternatively, clone the repository and compile the source code:

  1. # Clone repository
  2. git clone https://github.com/ofabry/go-callvis.git
  3. cd go-callvis
  4. # Compile and install
  5. 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

  1. Usage of go-callvis:
  2. -debug
  3. Enable verbose log.
  4. -file string
  5. output filename - omit to use server mode
  6. -cacheDir string
  7. Enable caching to avoid unnecessary re-rendering.
  8. -focus string
  9. Focus specific package using name or import path. (default "main")
  10. -format string
  11. output file format [svg | png | jpg | ...] (default "svg")
  12. -graphviz
  13. Use Graphviz's dot program to render images.
  14. -group string
  15. Grouping functions by packages and/or types [pkg, type] (separated by comma) (default "pkg")
  16. -http string
  17. HTTP service address. (default ":7878")
  18. -ignore string
  19. Ignore package paths containing given prefixes (separated by comma)
  20. -include string
  21. Include package paths with given prefixes (separated by comma)
  22. -limit string
  23. Limit package paths to given prefixes (separated by comma)
  24. -minlen uint
  25. Minimum edge length (for wider output). (default 2)
  26. -nodesep float
  27. Minimum space between two adjacent nodes in the same rank (for taller output). (default 0.35)
  28. -nointer
  29. Omit calls to unexported functions.
  30. -nostd
  31. Omit calls to/from packages in standard library.
  32. -rankdir
  33. Direction of graph layout [LR | RL | TB | BT] (default "LR")
  34. -skipbrowser
  35. Skip opening browser.
  36. -tags build tags
  37. 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
  38. -tests
  39. Include test code.
  40. -algo string
  41. Use specific algorithm for package analyzer: static, cha or rta (default "static")
  42. -version
  43. 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

Represents Style
focused blue color
stdlib green color
other yellow color

Functions / Methods

Represents Style
exported bold border
unexported normal border
anonymous dotted border

Calls

Represents Style
internal black color
external brown color
static solid line
dynamic dashed line
regular simple arrow
concurrent arrow with circle
deferred arrow 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.