package module
v0.0.0-...-0f4ba7e Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2017 License: MIT Imports: 11 Imported by: 0



A simple package for profiling deployed binaries.

Key features:

  • Does not require running any other scripts/tools, only the binary under monitoring.
  • Flame graphs for stack trace profiling.
  • Memory, GC pauses and goroutines line charts.
  • go-torch. go-torch does cpu profiling and represents it as a flame graph. We were directly inspired by this package. In contrast to goprofui, go-torch requires the go pprof tool and an external Perl script.

  • profile. profile does cpu and memory profiling, and saves them into a file. It is easy to setup and use. However, the cpu profiles would have to be further parsed for a flame graph.

  • flame graphs. Created by Brendan Gregg. An extremely succinct way to summarize stack traces.

go get
  1. Requires the net web-socket library

  2. The flame graph JS library is

  3. The line chart JS library is D3's.

  4. goprofui's internal package is forked from pprof's internal package. It is covered by the BSD-license in LICENSE_internal_pkg.

Usage and Code Structure

The quickest way to get started is to copy the handlers' setup from examples/web/web.go. Build the web.go application, and then serve the index.html file using a web server ( for example).

When you visit the example using your web browser, you will see some graphs:

  • Alt text
  • Alt text
  • Alt text

The cpu profiling code is in cpu.go. The memory, GC latency and goroutines stats are obtained in tickerHandlers.go.




This section is empty.


View Source
var ErrProfileFailed = errors.New("Could not start profiler")


func CPUProfile

func CPUProfile(duration time.Duration) chan *Profile

Non-blocking function to get a profile

func CollectGCStats

func CollectGCStats() collectFn

func CollectMemStats

func CollectMemStats() collectFn

func CollectRoutinesStats

func CollectRoutinesStats() collectFn

func CollectStats

func CollectStats(reader func() []byte) collectFn

func GCHandler

func GCHandler(freq time.Duration) func(*websocket.Conn)

func GoRoutinesHandler

func GoRoutinesHandler(freq time.Duration) func(*websocket.Conn)

func LocationsToFuncNames

func LocationsToFuncNames(locations []*profile.Location) map[uint64]string

func MemoryHandler

func MemoryHandler(freq time.Duration) func(*websocket.Conn)

func StartCPUProfHandler

func StartCPUProfHandler(w http.ResponseWriter, r *http.Request)

func StopCPUProfHandler

func StopCPUProfHandler(w http.ResponseWriter, r *http.Request)

func TickerHandler

func TickerHandler(freq time.Duration, fn collectFn) func(*websocket.Conn)


type Node

type Node struct {
	Name     string
	Value    int64
	Children map[string]*Node

Used to construct the d3 flame graph representation

func (*Node) Add

func (n *Node) Add(funcs []string, value int64)

Add will add a folded stack of functions to the node. Based on the stack convert node script which builds data for the d3 flame graph.

func (*Node) MarshalText

func (n *Node) MarshalText() ([]byte, error)

MarshalText will return JSON data of the node tree in the format required by the D3 flame graph. Note that the D3 library wants arrays of children.

type Profile

type Profile struct {
	TotalSamples        uint32 // count of samples
	TotalFuncCalls      uint32 // count of all funcs in all sample
	FuncFrequency       map[string]uint32
	UniqueFuncFrequency map[string]uint32
	FuncDict            map[uint64]string
	Prof                *profile.Profile

func EmptyProfile

func EmptyProfile(prof *profile.Profile) *Profile

func NewProfile

func NewProfile(p *profile.Profile) *Profile

func (*Profile) ParseForD3FlameGraph

func (p *Profile) ParseForD3FlameGraph(w io.Writer) error

The D3 Flame Graph is at:

The D3 lib expects the following tree struct: 1) root --> *children 2) child --> *children

Invariant: If a Func name appears at the same stack level in two samples and the call stack prefix is also the same, then there is exactly one node at that level in the tree to denote Func.


Path Synopsis
Package profile provides a representation of profile.proto and methods to encode/decode profiles in this format.
Package profile provides a representation of profile.proto and methods to encode/decode profiles in this format.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL