Giter Site home page Giter Site logo

go-torch's Introduction

go-torch Build Status Coverage Status GoDoc

Synopsis

Tool for stochastically profiling Go programs. Collects stack traces and synthesizes them into a flame graph. Uses Go's built in pprof library.

Example Flame Graph

Inception

Basic Usage

$ go-torch --help

NAME:
   go-torch - go-torch collects stack traces of a Go application and synthesizes them into into a [flame graph](http://www.brendangregg.com/FlameGraphs/cpuflamegraphs.html)

USAGE:
   go-torch [global options] command [command options] [arguments...]

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --url, -u "http://localhost:8080"   base url of your Go program
   --suffix, -s "/debug/pprof/profile" url path of pprof profile
   --binaryinput, -b          file path of raw binary profile; alternative to having go-torch query pprof endpoint (binary profile is anything accepted by https://golang.org/cmd/pprof)
   --binaryname               file path of the binary that the binaryinput is for, used for pprof inputs
   --time, -t "30"         time in seconds to profile for
   --file, -f "torch.svg"     ouput file name (must be .svg)
   --print, -p          print the generated svg to stdout instead of writing to file
   --raw, -r            print the raw call graph output to stdout instead of creating a flame graph; use with Brendan Gregg's flame graph perl script (see https://github.com/brendangregg/FlameGraph)
   --title              graph title to display in the output file
   --help, -h           show help
   --version, -v        print the version

File Example

$ go-torch --time=15 --file "torch.svg" --url http://localhost:8080
INFO[0000] Profiling ...
INFO[0015] flame graph has been created as torch.svg

Stdout Example

$ go-torch --time=15 --print --url http://localhost:8080
INFO[0000] Profiling ...
<svg>
...
</svg>
INFO[0015] flame graph has been printed to stdout

Raw Example

$ go-torch --time=15 --raw --url http://localhost:8080
INFO[0000] Profiling ...
function1;function2 3
...
INFO[0015] raw call graph output been printed to stdout

Local pprof Example

$ go test -cpuprofile=cpu.pprof
# This creates a cpu.pprof file, and the golang.test binary.
$ go-torch --binaryinput cpu.pprof --binaryname golang.test
INFO[0000] Profiling ...
INFO[0000] flame graph has been created as torch.svg

Installation

$ go get github.com/uber/go-torch

You can also use go-torch using docker:

$ docker run uber/go-torch -u http://[address-of-host] -p > torch.svg

Using -p will print the SVG to standard out, which can then be redirected to a file. This avoids mounting volumes to a container.

Install the Go dependencies:

$ go get github.com/Masterminds/glide
$ glide install

Get the flame graph script:

$ git clone https://github.com/brendangregg/FlameGraph.git

Integrating With Your Application

Expose a pprof endpoint. Official Go docs are here. If your application is already running a server on the DefaultServeMux, just add this import to your application.

import _ "net/http/pprof"

If your application is not using the DefaultServeMux, you can still easily expose pprof endpoints by manually registering the net/http/pprof handlers or by using a library like this one.

Run the Tests

$ go test ./...
ok    github.com/uber/go-torch   0.012s
ok    github.com/uber/go-torch/graph   0.017s
ok    github.com/uber/go-torch/visualization 0.052s

go-torch's People

Contributors

prashantv avatar sandlerben avatar ascandella avatar calavera avatar dcelasun avatar nanxiao avatar

Watchers

James Cloos avatar cjl 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.