1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
7 // Breakpoint executes a breakpoint trap.
10 // LockOSThread wires the calling goroutine to its current operating system thread.
11 // Until the calling goroutine exits or calls UnlockOSThread, it will always
12 // execute in that thread, and no other goroutine can.
15 // UnlockOSThread unwires the calling goroutine from its fixed operating system thread.
16 // If the calling goroutine has not called LockOSThread, UnlockOSThread is a no-op.
19 // GOMAXPROCS sets the maximum number of CPUs that can be executing
20 // simultaneously and returns the previous setting. If n < 1, it does not
21 // change the current setting.
22 // The number of logical CPUs on the local machine can be queried with NumCPU.
23 // This call will go away when the scheduler improves.
24 func GOMAXPROCS(n
int) int
26 // NumCPU returns the number of logical CPUs on the local machine.
29 // NumCgoCall returns the number of cgo calls made by the current process.
30 func NumCgoCall() int64
32 // NumGoroutine returns the number of goroutines that currently exist.
33 func NumGoroutine() int
35 // MemProfileRate controls the fraction of memory allocations
36 // that are recorded and reported in the memory profile.
37 // The profiler aims to sample an average of
38 // one allocation per MemProfileRate bytes allocated.
40 // To include every allocated block in the profile, set MemProfileRate to 1.
41 // To turn off profiling entirely, set MemProfileRate to 0.
43 // The tools that process the memory profiles assume that the
44 // profile rate is constant across the lifetime of the program
45 // and equal to the current value. Programs that change the
46 // memory profiling rate should do so just once, as early as
47 // possible in the execution of the program (for example,
48 // at the beginning of main).
49 var MemProfileRate
int = 512 * 1024
51 // A MemProfileRecord describes the live objects allocated
52 // by a particular call sequence (stack trace).
53 type MemProfileRecord
struct {
54 AllocBytes
, FreeBytes
int64 // number of bytes allocated, freed
55 AllocObjects
, FreeObjects
int64 // number of objects allocated, freed
56 Stack0
[32]uintptr // stack trace for this record; ends at first 0 entry
59 // InUseBytes returns the number of bytes in use (AllocBytes - FreeBytes).
60 func (r
*MemProfileRecord
) InUseBytes() int64 { return r
.AllocBytes
- r
.FreeBytes
}
62 // InUseObjects returns the number of objects in use (AllocObjects - FreeObjects).
63 func (r
*MemProfileRecord
) InUseObjects() int64 {
64 return r
.AllocObjects
- r
.FreeObjects
67 // Stack returns the stack trace associated with the record,
68 // a prefix of r.Stack0.
69 func (r
*MemProfileRecord
) Stack() []uintptr {
70 for i
, v
:= range r
.Stack0
{
78 // MemProfile returns n, the number of records in the current memory profile.
79 // If len(p) >= n, MemProfile copies the profile into p and returns n, true.
80 // If len(p) < n, MemProfile does not change p and returns n, false.
82 // If inuseZero is true, the profile includes allocation records
83 // where r.AllocBytes > 0 but r.AllocBytes == r.FreeBytes.
84 // These are sites where memory was allocated, but it has all
85 // been released back to the runtime.
87 // Most clients should use the runtime/pprof package or
88 // the testing package's -test.memprofile flag instead
89 // of calling MemProfile directly.
90 func MemProfile(p
[]MemProfileRecord
, inuseZero
bool) (n
int, ok
bool)
92 // A StackRecord describes a single execution stack.
93 type StackRecord
struct {
94 Stack0
[32]uintptr // stack trace for this record; ends at first 0 entry
97 // Stack returns the stack trace associated with the record,
98 // a prefix of r.Stack0.
99 func (r
*StackRecord
) Stack() []uintptr {
100 for i
, v
:= range r
.Stack0
{
108 // ThreadCreateProfile returns n, the number of records in the thread creation profile.
109 // If len(p) >= n, ThreadCreateProfile copies the profile into p and returns n, true.
110 // If len(p) < n, ThreadCreateProfile does not change p and returns n, false.
112 // Most clients should use the runtime/pprof package instead
113 // of calling ThreadCreateProfile directly.
114 func ThreadCreateProfile(p
[]StackRecord
) (n
int, ok
bool)
116 // GoroutineProfile returns n, the number of records in the active goroutine stack profile.
117 // If len(p) >= n, GoroutineProfile copies the profile into p and returns n, true.
118 // If len(p) < n, GoroutineProfile does not change p and returns n, false.
120 // Most clients should use the runtime/pprof package instead
121 // of calling GoroutineProfile directly.
122 func GoroutineProfile(p
[]StackRecord
) (n
int, ok
bool)
124 // CPUProfile returns the next chunk of binary CPU profiling stack trace data,
125 // blocking until data is available. If profiling is turned off and all the profile
126 // data accumulated while it was on has been returned, CPUProfile returns nil.
127 // The caller must save the returned data before calling CPUProfile again.
129 // Most clients should use the runtime/pprof package or
130 // the testing package's -test.cpuprofile flag instead of calling
131 // CPUProfile directly.
132 func CPUProfile() []byte
134 // SetCPUProfileRate sets the CPU profiling rate to hz samples per second.
135 // If hz <= 0, SetCPUProfileRate turns off profiling.
136 // If the profiler is on, the rate cannot be changed without first turning it off.
138 // Most clients should use the runtime/pprof package or
139 // the testing package's -test.cpuprofile flag instead of calling
140 // SetCPUProfileRate directly.
141 func SetCPUProfileRate(hz
int)
143 // SetBlockProfileRate controls the fraction of goroutine blocking events
144 // that are reported in the blocking profile. The profiler aims to sample
145 // an average of one blocking event per rate nanoseconds spent blocked.
147 // To include every blocking event in the profile, pass rate = 1.
148 // To turn off profiling entirely, pass rate <= 0.
149 func SetBlockProfileRate(rate
int)
151 // BlockProfileRecord describes blocking events originated
152 // at a particular call sequence (stack trace).
153 type BlockProfileRecord
struct {
159 // BlockProfile returns n, the number of records in the current blocking profile.
160 // If len(p) >= n, BlockProfile copies the profile into p and returns n, true.
161 // If len(p) < n, BlockProfile does not change p and returns n, false.
163 // Most clients should use the runtime/pprof package or
164 // the testing package's -test.blockprofile flag instead
165 // of calling BlockProfile directly.
166 func BlockProfile(p
[]BlockProfileRecord
) (n
int, ok
bool)
168 // Stack formats a stack trace of the calling goroutine into buf
169 // and returns the number of bytes written to buf.
170 // If all is true, Stack formats stack traces of all other goroutines
171 // into buf after the trace for the current goroutine.
172 func Stack(buf
[]byte, all
bool) int
174 // Get field tracking information. Only fields with a tag go:"track"
175 // are tracked. This function will add every such field that is
176 // referenced to the map. The keys in the map will be
177 // PkgPath.Name.FieldName. The value will be true for each field
179 func Fieldtrack(map[string]bool)