gostack

package module
v0.0.0-...-b261ed7 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2014 License: Apache-2.0 Imports: 9 Imported by: 0

README

Go Stack

Go Stack is a goroutine stack profile parsing library and accompanying gstack command for inspecting profiles.

Right now it's just a toy, but maybe someday it will be a useful way to quickly gather data from goroutine stack profiles.

See full documentation on godoc.

Or install the gstack tool:

go get -u github.com/schmichael/gostack/cmd/gstack

Documentation

Overview

Goroutine stack profile parser.

This is just a toy but might become something useful.

Example
// In this example we'll just create a stack profile from this process in a slice in memory. You
// could alternatively read a profile from a file or anywhere else.
buf := bytes.NewBuffer(nil)
if err := pprof.Lookup("goroutine").WriteTo(buf, 2); err != nil {
	fmt.Printf(err.Error())
	return
}

// fmt.Printf("profile is %s\n", buf.String())

profile, err := ReadProfile(buf)
if err != nil {
	fmt.Printf(err.Error())
	return
}

if len(profile.Goroutines) < 1 {
	fmt.Printf("Profile was parsed weirdly, how could there be no goroutines?")
	return
}

fmt.Printf("Success")
Output:

Success

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// GoroutineStates is a list of recognized goroutine states such as
	// "running" and "sleep".
	GoroutineStates = []GoroutineState{
		Running, Runnable, ChanRecv, ChanSend, Select, Sleep, Syscall, IOWait, FinalizerWait, SemAcquire,
	}
)

Functions

func Debug

func Debug(on bool)

Debug puts gostack into debug mode which outputs verbose logging.

Types

type Goroutine

type Goroutine struct {
	ID      int
	State   GoroutineState
	Blocked int
	Stack   []*StackFrame
}

Goroutine is a goroutine's metadata and stack.

type GoroutineState

type GoroutineState string

GoroutineState represents a recognized state of a goroutine.

const (
	Running       GoroutineState = "running"
	Runnable      GoroutineState = "runnable"
	ChanRecv      GoroutineState = "chan receive"
	ChanSend      GoroutineState = "chan send"
	FinalizerWait GoroutineState = "finalizer wait"
	Select        GoroutineState = "select"
	Sleep         GoroutineState = "sleep"
	Syscall       GoroutineState = "syscall"
	IOWait        GoroutineState = "IO wait"
	SemAcquire    GoroutineState = "semacquire"
)

Recognized goroutine states.

type Profile

type Profile struct {
	Created    time.Time
	Goroutines []*Goroutine
	StackCount map[string]int // Count of bottom call in stack frames
}

Profile is a goroutine stack profile.

func ReadProfile

func ReadProfile(r io.Reader) (*Profile, error)

ReadProfile parses a goroutine stack profile from an io.Reader and returns a Profile. A partial Profile is returned even when errors occur.

Currently, this function only supports goroutine profiles generated with verbosity/debug level of 2. This means that the code that originally generated the goroutine profile should look like myProfile.WriteTo(w, 2) . The example contained in this package demonstrates this. Also see the docs for runtime/pprof/*Profile.WriteTo in the standard library.

Call Debug(true) to see verbose output from profile parsing.

type StackFrame

type StackFrame struct {
	Line1      string
	Line2      string
	Package    string
	Method     string   //TODO use a struct to differentiate between func & method?
	Parameters []string //TODO uniptr? try to look it up in the heap?
	SourceFile string
	LineNumber int
}

StackFrame is a single frame in a goroutine's stack.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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