2010-06-21 21:53:49 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package runtime
|
|
|
|
|
2012-11-16 05:09:37 -07:00
|
|
|
// Breakpoint executes a breakpoint trap.
|
2010-06-21 21:53:49 -06:00
|
|
|
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.
|
|
|
|
func LockOSThread()
|
|
|
|
|
|
|
|
// UnlockOSThread unwires the calling goroutine from its fixed operating system thread.
|
|
|
|
// If the calling goroutine has not called LockOSThread, UnlockOSThread is a no-op.
|
|
|
|
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.
|
2012-01-12 11:06:50 -07:00
|
|
|
// The number of logical CPUs on the local machine can be queried with NumCPU.
|
2010-06-21 21:53:49 -06:00
|
|
|
// This call will go away when the scheduler improves.
|
|
|
|
func GOMAXPROCS(n int) int
|
|
|
|
|
2012-01-24 20:13:11 -07:00
|
|
|
// NumCPU returns the number of logical CPUs on the local machine.
|
|
|
|
func NumCPU() int
|
|
|
|
|
2012-02-16 14:49:41 -07:00
|
|
|
// NumCgoCall returns the number of cgo calls made by the current process.
|
|
|
|
func NumCgoCall() int64
|
2010-06-21 21:53:49 -06:00
|
|
|
|
2012-02-16 14:49:41 -07:00
|
|
|
// NumGoroutine returns the number of goroutines that currently exist.
|
2012-02-22 19:45:01 -07:00
|
|
|
func NumGoroutine() int
|
2010-12-07 16:06:31 -07:00
|
|
|
|
2010-06-21 21:53:49 -06:00
|
|
|
// MemProfileRate controls the fraction of memory allocations
|
|
|
|
// that are recorded and reported in the memory profile.
|
|
|
|
// The profiler aims to sample an average of
|
|
|
|
// one allocation per MemProfileRate bytes allocated.
|
|
|
|
//
|
|
|
|
// To include every allocated block in the profile, set MemProfileRate to 1.
|
|
|
|
// To turn off profiling entirely, set MemProfileRate to 0.
|
|
|
|
//
|
|
|
|
// The tools that process the memory profiles assume that the
|
|
|
|
// profile rate is constant across the lifetime of the program
|
|
|
|
// and equal to the current value. Programs that change the
|
|
|
|
// memory profiling rate should do so just once, as early as
|
|
|
|
// possible in the execution of the program (for example,
|
|
|
|
// at the beginning of main).
|
|
|
|
var MemProfileRate int = 512 * 1024
|
|
|
|
|
|
|
|
// A MemProfileRecord describes the live objects allocated
|
|
|
|
// by a particular call sequence (stack trace).
|
|
|
|
type MemProfileRecord struct {
|
|
|
|
AllocBytes, FreeBytes int64 // number of bytes allocated, freed
|
|
|
|
AllocObjects, FreeObjects int64 // number of objects allocated, freed
|
|
|
|
Stack0 [32]uintptr // stack trace for this record; ends at first 0 entry
|
|
|
|
}
|
|
|
|
|
|
|
|
// InUseBytes returns the number of bytes in use (AllocBytes - FreeBytes).
|
|
|
|
func (r *MemProfileRecord) InUseBytes() int64 { return r.AllocBytes - r.FreeBytes }
|
|
|
|
|
|
|
|
// InUseObjects returns the number of objects in use (AllocObjects - FreeObjects).
|
|
|
|
func (r *MemProfileRecord) InUseObjects() int64 {
|
|
|
|
return r.AllocObjects - r.FreeObjects
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stack returns the stack trace associated with the record,
|
|
|
|
// a prefix of r.Stack0.
|
|
|
|
func (r *MemProfileRecord) Stack() []uintptr {
|
|
|
|
for i, v := range r.Stack0 {
|
|
|
|
if v == 0 {
|
|
|
|
return r.Stack0[0:i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return r.Stack0[0:]
|
|
|
|
}
|
|
|
|
|
2012-02-22 19:45:01 -07:00
|
|
|
// A StackRecord describes a single execution stack.
|
|
|
|
type StackRecord struct {
|
2012-02-08 08:33:54 -07:00
|
|
|
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.
|
2012-02-22 19:45:01 -07:00
|
|
|
func (r *StackRecord) Stack() []uintptr {
|
2012-02-08 08:33:54 -07:00
|
|
|
for i, v := range r.Stack0 {
|
|
|
|
if v == 0 {
|
|
|
|
return r.Stack0[0:i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return r.Stack0[0:]
|
|
|
|
}
|
|
|
|
|
2012-02-22 19:45:01 -07:00
|
|
|
// 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)
|
2012-02-08 08:33:54 -07:00
|
|
|
|
2011-03-23 09:43:37 -06:00
|
|
|
// 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.
|
|
|
|
// The caller must save the returned data before calling CPUProfile again.
|
2012-11-26 08:53:11 -07:00
|
|
|
//
|
2011-03-23 09:43:37 -06:00
|
|
|
// Most clients should use the runtime/pprof package or
|
|
|
|
// the testing package's -test.cpuprofile flag instead of calling
|
|
|
|
// CPUProfile directly.
|
|
|
|
func CPUProfile() []byte
|
|
|
|
|
|
|
|
// SetCPUProfileRate sets the CPU profiling rate to hz samples per second.
|
|
|
|
// If hz <= 0, SetCPUProfileRate turns off profiling.
|
|
|
|
// If the profiler is on, the rate cannot be changed without first turning it off.
|
2012-11-26 08:53:11 -07:00
|
|
|
//
|
2011-03-23 09:43:37 -06:00
|
|
|
// Most clients should use the runtime/pprof package or
|
|
|
|
// the testing package's -test.cpuprofile flag instead of calling
|
|
|
|
// SetCPUProfileRate directly.
|
|
|
|
func SetCPUProfileRate(hz int)
|
2012-02-22 19:45:01 -07:00
|
|
|
|
pprof: add goroutine blocking profiling
The profiler collects goroutine blocking information similar to Google Perf Tools.
You may see an example of the profile (converted to svg) attached to
http://code.google.com/p/go/issues/detail?id=3946
The public API changes are:
+pkg runtime, func BlockProfile([]BlockProfileRecord) (int, bool)
+pkg runtime, func SetBlockProfileRate(int)
+pkg runtime, method (*BlockProfileRecord) Stack() []uintptr
+pkg runtime, type BlockProfileRecord struct
+pkg runtime, type BlockProfileRecord struct, Count int64
+pkg runtime, type BlockProfileRecord struct, Cycles int64
+pkg runtime, type BlockProfileRecord struct, embedded StackRecord
R=rsc, dave, minux.ma, r
CC=gobot, golang-dev, r, remyoudompheng
https://golang.org/cl/6443115
2012-10-06 02:56:04 -06:00
|
|
|
// SetBlockProfileRate controls the fraction of goroutine blocking events
|
|
|
|
// that are reported in the blocking profile. The profiler aims to sample
|
|
|
|
// an average of one blocking event per rate nanoseconds spent blocked.
|
|
|
|
//
|
|
|
|
// To include every blocking event in the profile, pass rate = 1.
|
|
|
|
// To turn off profiling entirely, pass rate <= 0.
|
|
|
|
func SetBlockProfileRate(rate int)
|
|
|
|
|
|
|
|
// BlockProfileRecord describes blocking events originated
|
|
|
|
// at a particular call sequence (stack trace).
|
|
|
|
type BlockProfileRecord struct {
|
|
|
|
Count int64
|
|
|
|
Cycles int64
|
|
|
|
StackRecord
|
|
|
|
}
|