GithubHelp home page GithubHelp logo

gocyto's Introduction

Gocyto

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

Features:

  • output to generic Cytoscape JSON format. (list of nodes, list of edges)
  • output to a single html file, with js dependencies in unpkg, and graph data embedded.
  • outputs can be written to program output, or to a file.
  • use different SSA analysis types
  • support for Go-modules (powered by golang.org/x/tools/go/packages)
  • graph data is nested: packages > types / globals > attached functions
  • nodes are colored based on signature (50% parameters blend, 50% results blend)
  • all edges/nodes enhanced with classes to style/filter the graph with
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

  • Similar purpose
  • bloated/hacky code
  • uses deprecated SSA package loading
  • no re-usable library code
  • an ugly non-go Graphviz dependency
  • no Go module support.
  • limited styling
  • hacky build-tags support (overwriting the default Go build flags during runtime...)

prospect

  • minimal
  • outdated, 4 years old
  • limited callgraph information extracted
  • looks like the origin of godoc callgraph tool (???)

callgraph

  • digraph and graphviz output support
  • doesn't add extra information (description/classes) to the calls
  • supports same set of analysis algorithms

godoc/analysis

License

MIT License, see LICENSE file.

gocyto's People

Contributors

protolambda avatar burkostya avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.