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.
9 // Breakpoint() executes a breakpoint trap.
12 // LockOSThread wires the calling goroutine to its current operating system thread.
13 // Until the calling goroutine exits or calls UnlockOSThread, it will always
14 // execute in that thread, and no other goroutine can.
15 // LockOSThread cannot be used during init functions.
18 // UnlockOSThread unwires the calling goroutine from its fixed operating system thread.
19 // If the calling goroutine has not called LockOSThread, UnlockOSThread is a no-op.
22 // GOMAXPROCS sets the maximum number of CPUs that can be executing
23 // simultaneously and returns the previous setting. If n < 1, it does not
24 // change the current setting.
25 // This call will go away when the scheduler improves.
26 func GOMAXPROCS(n int) int
28 // Cgocalls returns the number of cgo calls made by the current process.
31 // Goroutines returns the number of goroutines that currently exist.
32 func Goroutines() int32
34 type MemStatsType struct {
35 // General statistics.
36 // Not locked during update; approximate.
37 Alloc uint64 // bytes allocated and still in use
38 TotalAlloc uint64 // bytes allocated (even if freed)
39 Sys uint64 // bytes obtained from system (should be sum of XxxSys below)
40 Lookups uint64 // number of pointer lookups
41 Mallocs uint64 // number of mallocs
42 Frees uint64 // number of frees
44 // Main allocation heap statistics.
45 HeapAlloc uint64 // bytes allocated and still in use
46 HeapSys uint64 // bytes obtained from system
47 HeapIdle uint64 // bytes in idle spans
48 HeapInuse uint64 // bytes in non-idle span
49 HeapObjects uint64 // total number of allocated objects
51 // Low-level fixed-size structure allocator statistics.
52 // Inuse is bytes used now.
53 // Sys is bytes obtained from system.
54 StackInuse uint64 // bootstrap stacks
56 MSpanInuse uint64 // mspan structures
58 MCacheInuse uint64 // mcache structures
60 BuckHashSys uint64 // profiling bucket hash table
62 // Garbage collector statistics.
65 PauseNs [256]uint64 // most recent GC pause times
70 // Per-size allocation statistics.
71 // Not locked during update; approximate.
72 // 61 is NumSizeClasses in the C code.
80 var Sizeof_C_MStats int // filled in by malloc.goc
83 if Sizeof_C_MStats != unsafe.Sizeof(MemStats) {
84 println(Sizeof_C_MStats, unsafe.Sizeof(MemStats))
85 panic("MStats vs MemStatsType size mismatch")
89 // MemStats holds statistics about the memory system.
90 // The statistics are only approximate, as they are not interlocked on update.
91 var MemStats MemStatsType
93 // Alloc allocates a block of the given size.
94 // FOR TESTING AND DEBUGGING ONLY.
95 func Alloc(uintptr) *byte
97 // Free frees the block starting at the given pointer.
98 // FOR TESTING AND DEBUGGING ONLY.
101 // Lookup returns the base and size of the block containing the given pointer.
102 // FOR TESTING AND DEBUGGING ONLY.
103 func Lookup(*byte) (*byte, uintptr)
105 // GC runs a garbage collection.
108 // MemProfileRate controls the fraction of memory allocations
109 // that are recorded and reported in the memory profile.
110 // The profiler aims to sample an average of
111 // one allocation per MemProfileRate bytes allocated.
113 // To include every allocated block in the profile, set MemProfileRate to 1.
114 // To turn off profiling entirely, set MemProfileRate to 0.
116 // The tools that process the memory profiles assume that the
117 // profile rate is constant across the lifetime of the program
118 // and equal to the current value. Programs that change the
119 // memory profiling rate should do so just once, as early as
120 // possible in the execution of the program (for example,
121 // at the beginning of main).
122 var MemProfileRate int = 512 * 1024
124 // A MemProfileRecord describes the live objects allocated
125 // by a particular call sequence (stack trace).
126 type MemProfileRecord struct {
127 AllocBytes, FreeBytes int64 // number of bytes allocated, freed
128 AllocObjects, FreeObjects int64 // number of objects allocated, freed
129 Stack0 [32]uintptr // stack trace for this record; ends at first 0 entry
132 // InUseBytes returns the number of bytes in use (AllocBytes - FreeBytes).
133 func (r *MemProfileRecord) InUseBytes() int64 { return r.AllocBytes - r.FreeBytes }
135 // InUseObjects returns the number of objects in use (AllocObjects - FreeObjects).
136 func (r *MemProfileRecord) InUseObjects() int64 {
137 return r.AllocObjects - r.FreeObjects
140 // Stack returns the stack trace associated with the record,
141 // a prefix of r.Stack0.
142 func (r *MemProfileRecord) Stack() []uintptr {
143 for i, v := range r.Stack0 {
151 // MemProfile returns n, the number of records in the current memory profile.
152 // If len(p) >= n, MemProfile copies the profile into p and returns n, true.
153 // If len(p) < n, MemProfile does not change p and returns n, false.
155 // If inuseZero is true, the profile includes allocation records
156 // where r.AllocBytes > 0 but r.AllocBytes == r.FreeBytes.
157 // These are sites where memory was allocated, but it has all
158 // been released back to the runtime.
159 func MemProfile(p []MemProfileRecord, inuseZero bool) (n int, ok bool)