最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Go調(diào)用鏈可視化工具使用實(shí)例探究

 更新時(shí)間:2024年01月18日 10:02:17   作者:機(jī)器鈴砍菜刀  
本文介紹一款工具?go-callvis,它能夠?qū)?Go?代碼的調(diào)用關(guān)系可視化出來,并提供了可交互式的?web?服務(wù),在接手他人代碼或調(diào)研一些開源項(xiàng)目時(shí),如果能夠理清其中的代碼調(diào)用鏈路,這將加速我們對(duì)實(shí)現(xiàn)的理解

go-callvis 使用

依賴

  • Go 1.17+
  • Graphviz (可選,當(dāng)工具指定了 -graphviz 時(shí)需要)

工具安裝

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
    }
   }
  }()
 }
}

以上是一個(gè)簡(jiǎn)單的TCP服務(wù)端代碼,通過 go-callvis 工具,可將其代碼調(diào)用關(guān)系梳理出來。

$ 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 默認(rèn)將代碼調(diào)用關(guān)系存儲(chǔ)成 svg 格式的圖形,并會(huì)在 http://localhost:7878 服務(wù)上進(jìn)行展示。

在瀏覽器界面上,如果點(diǎn)擊 log 單元,將會(huì)進(jìn)入 log 模塊的代碼調(diào)用交互圖中。

使用參數(shù)

go-callvis 默認(rèn)以 main 作為鏈路起點(diǎn)進(jìn)行分析,因此 package 需要為 main 包。

go-callvis [flags] package

如果不想從 main 方法開始,那么需要使用 -tests 參數(shù),并且在 yourpackage 下創(chuàng)建單元測(cè)試,在測(cè)試中調(diào)用你想要的起始點(diǎn)方法。

go-callvis -tests yourpackage

詳細(xì)使用說明可通過執(zhí)行 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.

每個(gè)參數(shù)都有對(duì)應(yīng)的說明,無需詳細(xì)介紹。

有幾個(gè)比較有用的參數(shù)可以注意:nostd用以忽略標(biāo)準(zhǔn)庫(kù)的調(diào)用;group用以對(duì)函數(shù)分類;include、limitignore參數(shù)則用以控制過濾或保留調(diào)用關(guān)系。

總結(jié)

go-callvis 工具將 Go 程序函數(shù)調(diào)用關(guān)系通過圖形可視化出來,它能幫助開發(fā)人員更好地梳理程序脈絡(luò)。且 go-callvis 的使用非常簡(jiǎn)單,可以開箱即用。

之后同學(xué)們?cè)诮佑|復(fù)雜項(xiàng)目時(shí),不妨用 go-callvis 試試看。

以上就是Go調(diào)用鏈可視化工具使用實(shí)例探究的詳細(xì)內(nèi)容,更多關(guān)于Go調(diào)用鏈可視化的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Go語言快速入門圖文教程

    Go語言快速入門圖文教程

    Go是 Goolge 開發(fā)的一種靜態(tài)型、編譯型、并發(fā)型,并具有垃圾回收功能的語言,Go 語言上手非常容易,它的風(fēng)格類似于 C 語言,Go 語言號(hào)稱是互聯(lián)網(wǎng)時(shí)代的 C 語言,那么它到底有多火呢,一起看看吧
    2021-05-05
  • Go語言的緩存策略與實(shí)現(xiàn)方法代碼示例

    Go語言的緩存策略與實(shí)現(xiàn)方法代碼示例

    在Go語言中緩存是一種常見的優(yōu)化技術(shù),用于減少重復(fù)計(jì)算或I/O操作,提高程序性能,這篇文章主要介紹了Go語言緩存策略與實(shí)現(xiàn)方法的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2026-04-04
  • Go基礎(chǔ)教程之正則表達(dá)式regexp庫(kù)示例詳解

    Go基礎(chǔ)教程之正則表達(dá)式regexp庫(kù)示例詳解

    Go語言中的正則表達(dá)式功能強(qiáng)大,但也具有一定的復(fù)雜性,理解和掌握其基本語法和用法能夠幫助我們?cè)陂_發(fā)中更高效地處理文本數(shù)據(jù),這篇文章主要介紹了Go基礎(chǔ)教程之正則表達(dá)式regexp庫(kù)的相關(guān)資料,需要的朋友可以參考下
    2025-10-10
  • Go1.18新特性工作區(qū)模糊測(cè)試及泛型的使用詳解

    Go1.18新特性工作區(qū)模糊測(cè)試及泛型的使用詳解

    這篇文章主要為大家介紹了Go?1.18新特性中的工作區(qū)?模糊測(cè)試?泛型使用進(jìn)行詳細(xì)講解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-07-07
  • 詳解Golang中的Mutex并發(fā)原語

    詳解Golang中的Mutex并發(fā)原語

    Mutex?是?Go?語言中互斥鎖的實(shí)現(xiàn),它是一種同步機(jī)制,用于控制多個(gè)?goroutine?之間的并發(fā)訪問。本文將著重介紹?Go?的?Mutex?并發(fā)原語,希望對(duì)大家有所幫助
    2023-03-03
  • go語言的初始化順序,包,變量,init詳解

    go語言的初始化順序,包,變量,init詳解

    這篇文章主要介紹了go語言的初始化順序,包,變量,init詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-12-12
  • Go??iota?常量基本語法介紹

    Go??iota?常量基本語法介紹

    這篇文章主要介紹了Go?為什么要設(shè)計(jì)?iota?常量,我們介紹了 Go 中 iota 的基本語法。同時(shí)基于歷史資料針對(duì) iota 到底是什么,為什么要這么叫,又有什么用進(jìn)行了一番研究,需要的朋友可以參考下
    2022-06-06
  • Go語言獲取本機(jī)邏輯CPU數(shù)量的方法

    Go語言獲取本機(jī)邏輯CPU數(shù)量的方法

    這篇文章主要介紹了Go語言獲取本機(jī)邏輯CPU數(shù)量的方法,實(shí)例分析了runtime庫(kù)的操作技巧,需要的朋友可以參考下
    2015-03-03
  • go值賦值和引用賦值的使用

    go值賦值和引用賦值的使用

    本文將介紹Go語言中的值賦值和引用賦值,并比較它們之間的差異,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-10-10
  • Go語言并發(fā)編程之控制并發(fā)數(shù)量實(shí)現(xiàn)實(shí)例

    Go語言并發(fā)編程之控制并發(fā)數(shù)量實(shí)現(xiàn)實(shí)例

    這篇文章主要為大家介紹了Go語言并發(fā)編程之控制并發(fā)數(shù)量實(shí)例探究,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2024-01-01

最新評(píng)論

景泰县| 泰兴市| 顺平县| 平湖市| 西丰县| 长治县| 静海县| 张家界市| 康马县| 松潘县| 东城区| 雷州市| 拜泉县| 武清区| 舞阳县| 敦煌市| 西盟| 吉首市| 麻阳| 泰安市| 枣强县| 泰来县| 泰兴市| 禹州市| 木兰县| 卓资县| 万盛区| 洱源县| 区。| 马边| 海晏县| 岢岚县| 河曲县| 巩留县| 泾川县| 策勒县| 钦州市| 甘孜县| 太仆寺旗| 芮城县| 增城市|