Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.
A background
In golang, we can use tools to achieve this. Go-callvis shows the call relationship of the GO program in the form of pictures, which is especially useful when looking at complex projects.
2 the go – callvies profile
2.1 Tool Overview
Go-callvis is a development tool that helps visualize call diagrams of Go programs using interactive views.
The purpose of this tool is to provide developers with a visual overview of the Go program, using data from the call diagram and its relationship to packages and types. This is especially useful in large projects where the code is much more complex, or simply trying to understand someone else’s code.
2.2 features
- Support the go mod
- A specific focus package in a program
- Click on the package to quickly switch focus using the interactive viewer
- Group functions by type by package and/or method
- Filter packets to a specific import path prefix
- Ignore library functions
- Omit various types of function calls
Three installation
- Go get the installation
$ go get -u github.com/ofabry/go-callvis
Copy the code
- Source code compilation and installation
$ git clone https://github.com/ofabry/go-callvis.git cd go-callvis && make install
Copy the code
4 Output Examples
It runs pointer analysis to construct the program’s call graph and uses the output in data generation point format, which can be rendered using the Graphviz tool.
Five installation
go get -u github.com/ofabry/go-callvis
# or
git clone https://github.com/ofabry/go-callvis.git
cd go-callvis && make install
Copy the code
Six use
Go-callvis [Optional] < Package path >
1) Interactive display by browser
By default, the HTTP server listens at http://localhost:7878/. Change the HTTP server address using the option ‘-http=”ADDR:PORT”.
2) Static output
To generate a single output file, use the option -file=
to select the output file destination.
The default for SVG output format, use the option – the format = < SVG | PNG | JPG |… > Select another output format.
3) Other parameters
-debug Displays detailed logs. -file string Displays new results in a file. -focus String Focus specific package using name or import path. (default "main") -format string Format of the output file [svg | png | jpg | ...] (default "SVG ") -Graphviz renders images using Graphviz -group String grouping by package and/or type [PKG, type] (separated by comma) (default" PKG ") For example, -group PKG,type -http string HTTP service address (default :7878) -ignore string Ignores the package path containing the given prefix (separated by commas) -include string Includes the package path with the given prefix (Separated by comma) - LIMIT String Limit package paths to given prefixes (Separated by 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 ignores calls to unexported functions. -nostd ignores the call to the library - SkipBrowser skips opening the 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 contains the test code -version displays the version number 1) Parse main package go-callvis-skipbrowser-nostd. / 2) parse testPkg go-callvis-group PKG, type-focus testPkg github.com/ Project pathCopy the code
A simple example
$ go-callvis -format png -group pkg,type -focus github.com/kaliarch/linux_agent
/cmd/app github.com/kaliarch/linux_agent
2021/08/18 11:22:12 http serving at http://localhost:7878
2021/08/18 11:22:21 converting dot to png..
2021/08/18 11:22:22 serving file: /var/folders/wn/367g1v9n1bv0sg1k8qldzym80000gn/T/go-callvis_export.png
Copy the code
Refer to the link
- Github.com/TrueFurby/g…