OSDN Git Service

Update to current version of Go library (revision 94d654be2064).
[pf3gnuchains/gcc-fork.git] / libgo / go / runtime / debug.go
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.
4
5 package runtime
6
7 import "unsafe"
8
9 // Breakpoint() executes a breakpoint trap.
10 func Breakpoint()
11
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.
16 func LockOSThread()
17
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.
20 func UnlockOSThread()
21
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
27
28 // Cgocalls returns the number of cgo calls made by the current process.
29 func Cgocalls() int64
30
31 // Goroutines returns the number of goroutines that currently exist.
32 func Goroutines() int32
33
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
43
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
50
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
55         StackSys    uint64
56         MSpanInuse  uint64 // mspan structures
57         MSpanSys    uint64
58         MCacheInuse uint64 // mcache structures
59         MCacheSys   uint64
60         BuckHashSys uint64 // profiling bucket hash table
61
62         // Garbage collector statistics.
63         NextGC       uint64
64         PauseTotalNs uint64
65         PauseNs      [256]uint64 // most recent GC pause times
66         NumGC        uint32
67         EnableGC     bool
68         DebugGC      bool
69
70         // Per-size allocation statistics.
71         // Not locked during update; approximate.
72         // 61 is NumSizeClasses in the C code.
73         BySize [61]struct {
74                 Size    uint32
75                 Mallocs uint64
76                 Frees   uint64
77         }
78 }
79
80 var Sizeof_C_MStats int // filled in by malloc.goc
81
82 func init() {
83         if Sizeof_C_MStats != unsafe.Sizeof(MemStats) {
84                 println(Sizeof_C_MStats, unsafe.Sizeof(MemStats))
85                 panic("MStats vs MemStatsType size mismatch")
86         }
87 }
88
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
92
93 // Alloc allocates a block of the given size.
94 // FOR TESTING AND DEBUGGING ONLY.
95 func Alloc(uintptr) *byte
96
97 // Free frees the block starting at the given pointer.
98 // FOR TESTING AND DEBUGGING ONLY.
99 func Free(*byte)
100
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)
104
105 // GC runs a garbage collection.
106 func GC()
107
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.
112 //
113 // To include every allocated block in the profile, set MemProfileRate to 1.
114 // To turn off profiling entirely, set MemProfileRate to 0.
115 //
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
123
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
130 }
131
132 // InUseBytes returns the number of bytes in use (AllocBytes - FreeBytes).
133 func (r *MemProfileRecord) InUseBytes() int64 { return r.AllocBytes - r.FreeBytes }
134
135 // InUseObjects returns the number of objects in use (AllocObjects - FreeObjects).
136 func (r *MemProfileRecord) InUseObjects() int64 {
137         return r.AllocObjects - r.FreeObjects
138 }
139
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 {
144                 if v == 0 {
145                         return r.Stack0[0:i]
146                 }
147         }
148         return r.Stack0[0:]
149 }
150
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.
154 //
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)