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