diff options
Diffstat (limited to 'src/pkg/runtime/debug.go')
-rw-r--r-- | src/pkg/runtime/debug.go | 62 |
1 files changed, 46 insertions, 16 deletions
diff --git a/src/pkg/runtime/debug.go b/src/pkg/runtime/debug.go index 6370a57d8..b802fc63f 100644 --- a/src/pkg/runtime/debug.go +++ b/src/pkg/runtime/debug.go @@ -10,7 +10,6 @@ func Breakpoint() // LockOSThread wires the calling goroutine to its current operating system thread. // Until the calling goroutine exits or calls UnlockOSThread, it will always // execute in that thread, and no other goroutine can. -// LockOSThread cannot be used during init functions. func LockOSThread() // UnlockOSThread unwires the calling goroutine from its fixed operating system thread. @@ -20,26 +19,18 @@ func UnlockOSThread() // GOMAXPROCS sets the maximum number of CPUs that can be executing // simultaneously and returns the previous setting. If n < 1, it does not // change the current setting. +// The number of logical CPUs on the local machine can be queried with NumCPU. // This call will go away when the scheduler improves. func GOMAXPROCS(n int) int -// Cgocalls returns the number of cgo calls made by the current process. -func Cgocalls() int64 +// NumCPU returns the number of logical CPUs on the local machine. +func NumCPU() int -// Goroutines returns the number of goroutines that currently exist. -func Goroutines() int32 +// NumCgoCall returns the number of cgo calls made by the current process. +func NumCgoCall() int64 -// Alloc allocates a block of the given size. -// FOR TESTING AND DEBUGGING ONLY. -func Alloc(uintptr) *byte - -// Free frees the block starting at the given pointer. -// FOR TESTING AND DEBUGGING ONLY. -func Free(*byte) - -// Lookup returns the base and size of the block containing the given pointer. -// FOR TESTING AND DEBUGGING ONLY. -func Lookup(*byte) (*byte, uintptr) +// NumGoroutine returns the number of goroutines that currently exist. +func NumGoroutine() int // MemProfileRate controls the fraction of memory allocations // that are recorded and reported in the memory profile. @@ -92,11 +83,44 @@ func (r *MemProfileRecord) Stack() []uintptr { // where r.AllocBytes > 0 but r.AllocBytes == r.FreeBytes. // These are sites where memory was allocated, but it has all // been released back to the runtime. +// // Most clients should use the runtime/pprof package or // the testing package's -test.memprofile flag instead // of calling MemProfile directly. func MemProfile(p []MemProfileRecord, inuseZero bool) (n int, ok bool) +// 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 *StackRecord) Stack() []uintptr { + for i, v := range r.Stack0 { + if v == 0 { + return r.Stack0[0:i] + } + } + return r.Stack0[0:] +} + +// 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 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 // data accumulated while it was on has been returned, CPUProfile returns nil. @@ -113,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 |