Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package runtime | 5 package runtime |
6 | 6 |
7 // Breakpoint() executes a breakpoint trap. | 7 // Breakpoint() executes a breakpoint trap. |
8 func Breakpoint() | 8 func Breakpoint() |
9 | 9 |
10 // LockOSThread wires the calling goroutine to its current operating system thre ad. | 10 // LockOSThread wires the calling goroutine to its current operating system thre ad. |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 func CPUProfile() []byte | 131 func CPUProfile() []byte |
132 | 132 |
133 // SetCPUProfileRate sets the CPU profiling rate to hz samples per second. | 133 // SetCPUProfileRate sets the CPU profiling rate to hz samples per second. |
134 // If hz <= 0, SetCPUProfileRate turns off profiling. | 134 // If hz <= 0, SetCPUProfileRate turns off profiling. |
135 // If the profiler is on, the rate cannot be changed without first turning it of f. | 135 // If the profiler is on, the rate cannot be changed without first turning it of f. |
136 // Most clients should use the runtime/pprof package or | 136 // Most clients should use the runtime/pprof package or |
137 // the testing package's -test.cpuprofile flag instead of calling | 137 // the testing package's -test.cpuprofile flag instead of calling |
138 // SetCPUProfileRate directly. | 138 // SetCPUProfileRate directly. |
139 func SetCPUProfileRate(hz int) | 139 func SetCPUProfileRate(hz int) |
140 | 140 |
141 // ContentionProfileRate controls the fraction of contention events | 141 // SetBlockProfileRate controls the fraction of goroutine blocking events |
142 // that are recorded and reported in the contention profile. | 142 // that are reported in the blocking profile. The profiler aims to sample |
143 // The profiler aims to sample an average of | 143 // an average of one blocking event per rate nanoseconds spent blocked. |
144 // one contention event per ContentionProfileRate contended cycles. | |
145 // | 144 // |
146 // To include every contention event in the profile, set ContentionProfileRate t o 1. | 145 // To include every blocking event in the profile, pass rate = 1. |
147 // To turn off profiling entirely, set ContentionProfileRate to 0. | 146 // To turn off profiling entirely, pass rate <= 0. |
148 var ContentionProfileRate int = 0 | 147 func SetBlockProfileRate(rate int) |
149 | 148 |
150 // ContentionProfileRecord describes contention events originated | 149 // BlockProfileRecord describes blocking events originated |
151 // at a particular call sequence (stack trace). | 150 // at a particular call sequence (stack trace). |
152 type ContentionProfileRecord struct { | 151 type BlockProfileRecord struct { |
153 Count int64 | 152 Count int64 |
154 Cycles int64 | 153 Cycles int64 |
155 » Stack0 [32]uintptr | 154 » StackRecord |
dfc
2012/08/15 07:15:53
-Stack0 [32]uintptr
+StackRecord
dvyukov
2012/08/15 09:55:45
Done.
| |
156 } | 155 } |
157 | 156 |
158 // Stack returns the stack trace associated with the record, | 157 // BlockProfile returns n, the number of records in the current blocking profile . |
159 // a prefix of r.Stack0. | 158 // If len(p) >= n, BlockProfile copies the profile into p and returns n, true. |
dfc
2012/08/15 07:15:53
Then you can remove this
dvyukov
2012/08/15 09:55:45
Done.
dfc
2012/08/15 10:17:28
I'm both surprised and pleased that this worked.
| |
160 func (r *ContentionProfileRecord) Stack() []uintptr { | 159 // If len(p) < n, BlockProfile does not change p and returns n, false. |
161 » for i, v := range r.Stack0 { | |
162 » » if v == 0 { | |
163 » » » return r.Stack0[:i] | |
164 » » } | |
165 » } | |
166 » return r.Stack0[:] | |
167 } | |
168 | |
169 // ContentionProfile returns n, the number of records in the current contention profile. | |
170 // If len(p) >= n, ContentionProfile copies the profile into p and returns n, tr ue. | |
171 // If len(p) < n, ContentionProfile does not change p and returns n, false. | |
172 // | 160 // |
173 // Most clients should use the runtime/pprof package or | 161 // Most clients should use the runtime/pprof package or |
174 // the testing package's -test.contentionprofile flag instead | 162 // the testing package's -test.blockprofile flag instead |
175 // of calling ContentionProfile directly. | 163 // of calling BlockProfile directly. |
176 func ContentionProfile(p []ContentionProfileRecord) (n int, ok bool) | 164 func BlockProfile(p []BlockProfileRecord) (n int, ok bool) |
177 | 165 |
178 // Stack formats a stack trace of the calling goroutine into buf | 166 // Stack formats a stack trace of the calling goroutine into buf |
179 // and returns the number of bytes written to buf. | 167 // and returns the number of bytes written to buf. |
180 // If all is true, Stack formats stack traces of all other goroutines | 168 // If all is true, Stack formats stack traces of all other goroutines |
181 // into buf after the trace for the current goroutine. | 169 // into buf after the trace for the current goroutine. |
182 func Stack(buf []byte, all bool) int | 170 func Stack(buf []byte, all bool) int |
LEFT | RIGHT |