protolambda / gocyto

Callgraph analysis and visualization for Go
MIT License
162 stars 20 forks source link

Gocyto

A Go SSA callgraph builder and visualizer, by @protolambda.

Features:

go get github.com/protolambda/gocyto

Example output

This is the web output of the callgraph of Gocyto, including unexported functions:

Callgraph of gocyto itself

Usage

Provide a Go package pattern to load the packages, and produce the call-graph.

# From the directory containing `index.gohtml` for templating
gocyto --out prysm_out.html --query-dir ../prysm/beacon-chain --web github.com/prysmaticlabs/prysm/beacon-chain/...

options

gocyto [options...] <package path(s)>

Options:

  -build string
        Build flags to pass to Go build tool. Separated with spaces
  -go-root
        Include packages part of the Go root
  -mode string
        Type of analysis to run. One of: pointer, cha, rta, static (default "pointer")
  -out string
        Output file, if none is specified, output to std out
  -query-dir string
        Directory to query from for go packages. Current dir if empty
  -tests
        Consider tests files as entry points for call-graph
  -unexported
        Include unexported function calls
  -web
        Output an index.html with graph data embedded instead of raw JSON

gocyto/analysis

To easily load packages into a SSA program, and construct callgraphs.

Loading packages:

program, err := analysis.RunAnalysis(withTests, buildFlags, packagePatterns)

Constructing a callgraph:

analysis.PointerAnalysis.ComputeCallgraph(program)

Supported callgraph analysis types:

gocyto/render

Loads call-graph into a Cyto-graph object. After loading your graph (or multiple), the data can be output to JSON to load with cytoscape.

Constructing a cyto graph:

// Base object, manages nodes, edges and keeps track of a [full-name -> ID] map for shorter IDs
cytoGraph := render.NewCytoGraph()

// more options to be decided on later, PRs welcome
opts := &render.RenderOptions{
    IncludeGoRoot: false,
    IncludeUnexported: false,
}

// add call graph from SSA analysis to cyto graph
err := cytoGraph.LoadCallGraph(callGraph, opts)

// add more call graphs if you like

Comparison

go-callvis

prospect

callgraph

godoc/analysis

License

MIT License, see LICENSE file.