diff options
| author | Russ Cox <rsc@golang.org> | 2012-02-22 21:45:01 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2012-02-22 21:45:01 -0500 |
| commit | e4b02bfdc09ce9e1307250382f3b985f35ca9723 (patch) | |
| tree | 26c3e8fa3832ef2aed5aace2cf12d5d8329d5bd5 /src/pkg/runtime/debug.go | |
| parent | 133c6bf77fffcbfa38ed58cf06808b38bbc374e0 (diff) | |
| download | go-e4b02bfdc09ce9e1307250382f3b985f35ca9723.tar.xz | |
runtime: goroutine profile, stack dumps
R=golang-dev, r, r
CC=golang-dev
https://golang.org/cl/5687076
Diffstat (limited to 'src/pkg/runtime/debug.go')
| -rw-r--r-- | src/pkg/runtime/debug.go | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/pkg/runtime/debug.go b/src/pkg/runtime/debug.go index 6526f16a04..b802fc63f7 100644 --- a/src/pkg/runtime/debug.go +++ b/src/pkg/runtime/debug.go @@ -30,7 +30,7 @@ func NumCPU() int func NumCgoCall() int64 // NumGoroutine returns the number of goroutines that currently exist. -func NumGoroutine() int32 +func NumGoroutine() int // MemProfileRate controls the fraction of memory allocations // that are recorded and reported in the memory profile. @@ -89,15 +89,14 @@ func (r *MemProfileRecord) Stack() []uintptr { // of calling MemProfile directly. func MemProfile(p []MemProfileRecord, inuseZero bool) (n int, ok bool) -// A ThreadProfileRecord describes the execution stack that -// caused a new thread to be created. -type ThreadProfileRecord struct { +// A StackRecord describes a single execution stack. +type StackRecord struct { Stack0 [32]uintptr // stack trace for this record; ends at first 0 entry } // Stack returns the stack trace associated with the record, // a prefix of r.Stack0. -func (r *ThreadProfileRecord) Stack() []uintptr { +func (r *StackRecord) Stack() []uintptr { for i, v := range r.Stack0 { if v == 0 { return r.Stack0[0:i] @@ -106,13 +105,21 @@ func (r *ThreadProfileRecord) Stack() []uintptr { return r.Stack0[0:] } -// ThreadProfile returns n, the number of records in the current thread profile. -// If len(p) >= n, ThreadProfile copies the profile into p and returns n, true. -// If len(p) < n, ThreadProfile does not change p and returns n, false. +// ThreadCreateProfile returns n, the number of records in the thread creation profile. +// If len(p) >= n, ThreadCreateProfile copies the profile into p and returns n, true. +// If len(p) < n, ThreadCreateProfile does not change p and returns n, false. // // Most clients should use the runtime/pprof package instead -// of calling ThreadProfile directly. -func ThreadProfile(p []ThreadProfileRecord) (n int, ok bool) +// of calling ThreadCreateProfile directly. +func ThreadCreateProfile(p []StackRecord) (n int, ok bool) + +// GoroutineProfile returns n, the number of records in the active goroutine stack profile. +// If len(p) >= n, GoroutineProfile copies the profile into p and returns n, true. +// If len(p) < n, GoroutineProfile does not change p and returns n, false. +// +// Most clients should use the runtime/pprof package instead +// of calling GoroutineProfile directly. +func GoroutineProfile(p []StackRecord) (n int, ok bool) // CPUProfile returns the next chunk of binary CPU profiling stack trace data, // blocking until data is available. If profiling is turned off and all the profile @@ -130,3 +137,9 @@ func CPUProfile() []byte // the testing package's -test.cpuprofile flag instead of calling // SetCPUProfileRate directly. func SetCPUProfileRate(hz int) + +// Stack formats a stack trace of the calling goroutine into buf +// and returns the number of bytes written to buf. +// If all is true, Stack formats stack traces of all other goroutines +// into buf after the trace for the current goroutine. +func Stack(buf []byte, all bool) int |
