Callgraph analysis and visualization for Go

Overview

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...] 

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.

Comments
  • null output

    null output

    If I have this file:

    package main
    
    func a() {
       c()
       d()
    }
    
    func b() {
       e()
       f()
    }
    
    func c() {}
    func d() {}
    func e() {}
    func f() {}
    
    func main() {
       a()
       b()
    }
    

    I get this result:

    PS C:\test> .\gocyto.exe .
    {"nodes":null,"edges":null}
    
    opened by 89z 1
  • Fix empty buildflags

    Fix empty buildflags

    When using CLI If no build flags were passed then underlying command for listing packages will contain empty argument - like go list "-e" "-json" "-compiled=true" "-test=false" "-export=true" "-deps=true" "-find=false" "" "--" "some/pkg/..." - note third from the end argument.

    This PR excludes passing down empty build argument

    opened by burkostya 0
  • panic: open index.gohtml: no such file or directory

    panic: open index.gohtml: no such file or directory

    I really like this tool :)

    But, when I run gocyto --out out.html -web github.com/org/repo/... from within the module repository directory, I receive a panic:

    panic: open index.gohtml: no such file or directory
    
    goroutine 1 [running]:
    html/template.Must(...)
            /usr/local/Cellar/go/1.17.2/libexec/src/html/template/template.go:374
    main.main.func2({0x13aa400, 0xc010d21080})
            /Users/nick/dev/gocyto/main.go:97 +0x37f
    main.main()
            /Users/nick/dev/gocyto/main.go:132 +0x6b4
    

    It only works when I copy the index.gohtml file from the protolambda/gocyto repo into the current directory.

    opened by NickLarsenNZ 0
  • Pointer analysis failed no main/test packages to analyze

    Pointer analysis failed no main/test packages to analyze

    Hello,

    I can run gocyto on the latest version of the postgres-operator package but when I am trying to run gocyto on an older version of a package it throws -> panic: pointer analysis failed no main/test packages to analyze (check $GOROOT/$GOPATH)

    The command, I am trying to run is :

    gocyto --out output_graph_postgres35.json --query-dir /home/XXXX/go/pkg/mod/github.com/crunchydata/[email protected]+incompatible github.com/crunchydata/[email protected]+incompatible/...

    opened by ableocardo 1
  • could not determine GOARCH and Go compiler

    could not determine GOARCH and Go compiler

    I have the gocyto bash file in my gocyto directory. From that directory, I was using the following command:

    ./gocyto --out test.html directory-of-my-package

    I got the error "failed packages load: could not determine GOARCH and Go compiler". When I checked for go env, I found that I have the following:

    GOARCH="amd64" GCCGO="gccgo"

    opened by Shahanewaz 2
  • gocyto showing package load errors - how to debug it

    gocyto showing package load errors - how to debug it

    cmd $ gocyto github.com/bsingarayan/services/monitoring/cmd -web 2020/08/05 13:03:01 failed packages load: JSON decoding failed: invalid character 'g' looking for beginning of value

    If possible, can you share a working example? I find this tool to be promising, so would like to try it out

    Thanks

    opened by babu-s2 0
Owner
Diederik Loerakker
Platform architect, specialized in Ethereum R&D. Building Eth2. Twitter: @protolambda
Diederik Loerakker
gosivy - Another visualization tool for Go process metrics

gosivy Another visualization tool for Go process metrics. Gosivy tracks Go process's metrics and plot their evolution over time right into your termin

Ryo Nakao 449 Sep 17, 2022
🚀Statsview is a real-time Golang runtime stats visualization profiler

Statsview is a real-time Golang runtime stats visualization profiler. It is built top on another open-source project, go-echarts, which helps statsview to show its graphs on the browser.

go-echarts 496 Sep 18, 2022
entviz is an ent extension that provides visualization of the schema graph

entviz entviz is an ent extension that creates visual graph (html file) of your ent's schema. install go get github.com/hedwigz/entviz add this exten

Amit Shani 77 Aug 25, 2022
Sloop - Kubernetes History Visualization

Sloop - Kubernetes History Visualization Sloop monitors Kubernetes, recording histories of events and resource state changes and providing visualizati

Salesforce 1.2k Sep 24, 2022
Interactive dependency graph visualization tool for golang

Interactive dependency graph visualization tool for golang using the awesome cytoscape graph visualizer.

Armin Becher 6 Sep 1, 2022
Data visualization with chart, Create CSV file, Read Write CSV file

Data visualization with chart, Create CSV file, Read Write CSV file, Read from json file and many more in single project ......

MD FAISAL PORAG 1 Jan 13, 2022
A repository for plotting and visualizing data

gonum/plot is the new, official fork of code.google.com/p/plotinum. It provides an API for building and drawing plots in Go

null 2.3k Sep 16, 2022
Tool that can parse Go files into an abstract syntax tree and translate it to several programming languages.

GoDMT GoDMT, the one and only Go Data Model Translator. The goal of this project is to provide a tool that can parse Go files that include var, const,

Josep Jesus Bigorra Algaba 42 Jan 29, 2022
A repository for plotting and visualizing data

Gonum Plot gonum/plot is the new, official fork of code.google.com/p/plotinum. It provides an API for building and drawing plots in Go. Note that this

null 19.1k Jun 3, 2021
Ltree Visualizer - A golang library to visualize postgres ltree type data using DOT language and Graphviz

Ltree Visualizer A golang library to visualize postgres ltree type data using DOT language and Graphviz What is Ltree? Ltree is a data type which is u

Vasubabu Jinagam 8 Jun 12, 2022
termdbms: A TUI for viewing and editing databases, written in Go

termdbms: A TUI for viewing and editing databases, written in Go Database Support SQLite made with modernc.org/sqlite, charmbracelet/bubbletea, and c

Matt Farstad 1.2k Sep 25, 2022
pprof is a tool for visualization and analysis of profiling data

Introduction pprof is a tool for visualization and analysis of profiling data. pprof reads a collection of profiling samples in profile.proto format a

Google 5.8k Sep 20, 2022
k6-to-honeycomb is a program that sends k6 results into Honeycomb for visualization and analysis.

k6-to-honeycomb k6-to-honeycomb is a program that sends k6 results into Honeycomb for visualization and analysis. Getting Started k6-to-honeycomb is a

Travis Cline 3 Jul 14, 2022
The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.

The open-source platform for monitoring and observability. Grafana allows you to query, visualize, alert on and understand your metrics no matter wher

Grafana Labs 51k Sep 20, 2022
A golang framework helps gopher to build a data visualization and admin panel in ten minutes

the missing golang data admin panel builder tool. Documentation | 中文介绍 | DEMO | 中文DEMO | Twitter | Forum Inspired by laravel-admin Preface GoAdmin is

GoAdmin 6.3k Sep 25, 2022
Tool for shell commands execution, visualization and alerting. Configured with a simple YAML file.

Sampler. Visualization for any shell command. Sampler is a tool for shell commands execution, visualization and alerting. Configured with a simple YAM

Alexander Lukyanchikov 10.6k Sep 19, 2022
Interactive Terraform visualization. State and configuration explorer.

Rover - Terraform Visualizer Rover is a Terraform visualizer. In order to do this, Rover: generates a plan file and parses the configuration in the ro

Tu Nguyen 2.1k Sep 21, 2022
A tool for visualization and monitoring Redis cluster realtime

Redat is a tool for visualize Redis-cluster on terminal Features: Visualize master-replicas relations in the Redis cluster Monitor with metrics: memor

Alex Nguyen 6 Nov 15, 2021