成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

一款好用的 Go 調用鏈可視化工具

開發 前端
go-callvis 工具將 Go 程序函數調用關系通過圖形可視化出來,它能幫助開發人員更好地梳理程序脈絡。且 go-callvis 的使用非常簡單,可以開箱即用。

在接手他人代碼或調研一些開源項目時,如果能夠理清其中的代碼調用鏈路,這將加速我們對實現的理解。

本文介紹一款工具 go-callvis,它能夠將 Go 代碼的調用關系可視化出來,并提供了可交互式的 web 服務。

go-callvis 使用

依賴

  • Go 1.17+
  • Graphviz (可選,當工具指定了 ??-graphviz?? 時需要)

工具安裝

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

示例

package main

import (

func main() {
// Part 1: create a listener
l, err := net.Listen("tcp", ":8000")
if err != nil {
log.Fatalf("Error listener returned: %s", err)
}
defer l.Close()

for {
// Part 2: accept new connection
c, err := l.Accept()
if err != nil {
log.Fatalf("Error to accept new connection: %s", err)
}

// Part 3: create a goroutine that reads and write back data
go func() {
log.Printf("TCP session open")
defer c.Close()

for {
d := make([]byte, 1024)

// Read from TCP buffer
_, err := c.Read(d)
if err != nil {
log.Printf("Error reading TCP session: %s", err)
break
}
log.Printf("reading data from client: %s\n", string(d))

// write back data to TCP client
_, err = c.Write(d)
if err != nil {
log.Printf("Error writing TCP session: %s", err)
break
}
}
}()
}
}

以上是一個簡單的TCP服務端代碼,通過 go-callvis 工具,可將其代碼調用關系梳理出來。

$ go-callvis main.go
2022/08/14 21:23:03 http serving at http://localhost:7878
2022/08/14 21:23:03 converting dot to svg..
2022/08/14 21:23:03 serving file: /var/folders/xk/gn46n46d503dsztbc6_9qb2h0000gn/T/go-callvis_export.svg

go-callvis 默認將代碼調用關系存儲成 svg 格式的圖形,并會在 http://localhost:7878 服務上進行展示。

圖片

?瀏覽器界面上,如果點擊 log 單元,將會進入 log 模塊的代碼調用交互圖中。

圖片

使用參數

go-callvis 默認以 main 作為鏈路起點進行分析,因此 package 需要為 main 包。

go-callvis [flags] package

如果不想從 main 方法開始,那么需要使用 -tests 參數,并且在 yourpackage 下創建單元測試,在測試中調用你想要的起始點方法。

go-callvis -tests yourpackage

詳細使用說明可通過執行 go-callvis 命令查看

$ go-callvis
go-callvis: visualize call graph of a Go program.

Usage:

go-callvis [flags] package

Package should be main package, otherwise -tests flag must be used.

Flags:

-algo string
The algorithm used to construct the call graph. Possible values inlcude: "static", "cha", "rta", "pointer" (default "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
-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")
-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)
-nodeshape string
graph node shape (see graphvis manpage for valid values) (default "box")
-nodestyle string
graph node style (see graphvis manpage for valid values) (default "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")
-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.
-version
Show version and exit.
[slp@slpdeMacBook-Pro:] ~/repo/MongoShake/cmd/collector $ go-callvis --help
Usage of go-callvis:
-algo string
The algorithm used to construct the call graph. Possible values inlcude: "static", "cha", "rta", "pointer" (default "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
-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")
-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)
-nodeshape string
graph node shape (see graphvis manpage for valid values) (default "box")
-nodestyle string
graph node style (see graphvis manpage for valid values) (default "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")
-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.
-version
Show version and exit.

每個參數都有對應的說明,無需詳細介紹。

有幾個比較有用的參數可以注意:nostd?用以忽略標準庫的調用;group?用以對函數分類;include?、limit?、ignore參數則用以控制過濾或保留調用關系。

總結

go-callvis 工具將 Go 程序函數調用關系通過圖形可視化出來,它能幫助開發人員更好地梳理程序脈絡。且 go-callvis 的使用非常簡單,可以開箱即用。

之后同學們在接觸復雜項目時,不妨用 go-callvis 試試看。?

責任編輯:武曉燕 來源: Golang技術分享
相關推薦

2019-12-23 14:17:46

數據可視化工具

2022-07-12 09:35:59

JSON可視化工具

2020-03-24 09:50:33

工具代碼開發

2024-02-26 12:02:37

Python數據可視化D3blocks

2024-02-19 00:00:00

Git可視化工具

2024-11-04 08:49:11

2022-09-14 08:49:01

Kubernetes

2021-04-11 09:51:25

Redis可視化工具

2015-12-02 09:44:04

Python視化工具

2021-01-27 13:16:39

ScreenLinux命令

2021-02-16 10:58:50

ScreenLinux命令

2021-06-11 17:45:57

大數據可視化工具

2024-01-11 18:55:37

3D可視化AI

2021-04-14 16:20:39

可視化大數據工具

2022-05-24 15:03:44

開源工具可視化

2019-10-10 08:46:02

Docker可視化技術瀏覽器

2023-03-08 07:45:50

可視化編程工具SpringBoot

2019-06-11 09:35:34

可視化工具圖形

2022-01-17 11:09:46

數據可視化工具開發

2018-09-09 23:07:17

物聯網可視化編程工具
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 久久精品国产久精国产 | 91精品国产综合久久婷婷香蕉 | 激情国产 | 国产精品一区久久久 | 精品国产亚洲一区二区三区大结局 | 亚洲狠狠| 国产在线精品一区二区 | 欧美精品video | 亚洲精品字幕 | 久久久久国产一区二区三区四区 | 国产电影一区二区三区爱妃记 | 色天天综合| 三级欧美 | 日韩在线精品强乱中文字幕 | 福利网站导航 | 国产精品久久久久久影院8一贰佰 | 欧美在线视频网站 | 国产精品视频免费观看 | 成人黄色电影在线播放 | 久久久久国产 | 亚洲高清视频一区二区 | 欧美一区二区三区,视频 | 欧美日韩一区在线观看 | 日韩精品影院 | 欧美一级二级三级视频 | 精品国产乱码一区二区三 | 天天爽综合网 | 久久久夜色精品亚洲 | 黄色小视频入口 | 欧美成ee人免费视频 | 国产91网站在线观看 | 日韩在线欧美 | 性高湖久久久久久久久aaaaa | 日韩中文字幕在线观看 | 奇米超碰 | av在线一区二区三区 | 久久免费视频在线 | 国产清纯白嫩初高生视频在线观看 | 久久精品欧美一区二区三区不卡 | 黄色亚洲网站 | 国产免费观看一区 |