LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 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 // CPU profiling. | 5 // CPU profiling. |
6 // Based on algorithms and data structures used in | 6 // Based on algorithms and data structures used in |
7 // http://code.google.com/p/google-perftools/. | 7 // http://code.google.com/p/google-perftools/. |
8 // | 8 // |
9 // The main difference between this code and the google-perftools | 9 // The main difference between this code and the google-perftools |
10 // code is that this code is written to allow copying the profile data | 10 // code is that this code is written to allow copying the profile data |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 func (p *cpuProfile) flushlog() bool { | 282 func (p *cpuProfile) flushlog() bool { |
283 if !cas(&p.handoff, 0, uint32(p.nlog)) { | 283 if !cas(&p.handoff, 0, uint32(p.nlog)) { |
284 return false | 284 return false |
285 } | 285 } |
286 notewakeup(&p.wait) | 286 notewakeup(&p.wait) |
287 | 287 |
288 p.toggle = 1 - p.toggle | 288 p.toggle = 1 - p.toggle |
289 log := &p.log[p.toggle] | 289 log := &p.log[p.toggle] |
290 q := uintptr(0) | 290 q := uintptr(0) |
291 if p.lost > 0 { | 291 if p.lost > 0 { |
292 » » f := lostProfileData | 292 » » lostPC := funcPC(lostProfileData) |
293 » » lostPC := **(**uintptr)(unsafe.Pointer(&f)) | |
294 log[0] = p.lost | 293 log[0] = p.lost |
295 log[1] = 1 | 294 log[1] = 1 |
296 log[2] = lostPC | 295 log[2] = lostPC |
297 q = 3 | 296 q = 3 |
298 p.lost = 0 | 297 p.lost = 0 |
299 } | 298 } |
300 p.nlog = q | 299 p.nlog = q |
301 return true | 300 return true |
302 } | 301 } |
303 | 302 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 // blocking until data is available. If profiling is turned off and all the pro
file | 414 // blocking until data is available. If profiling is turned off and all the pro
file |
416 // data accumulated while it was on has been returned, CPUProfile returns nil. | 415 // data accumulated while it was on has been returned, CPUProfile returns nil. |
417 // The caller must save the returned data before calling CPUProfile again. | 416 // The caller must save the returned data before calling CPUProfile again. |
418 // | 417 // |
419 // Most clients should use the runtime/pprof package or | 418 // Most clients should use the runtime/pprof package or |
420 // the testing package's -test.cpuprofile flag instead of calling | 419 // the testing package's -test.cpuprofile flag instead of calling |
421 // CPUProfile directly. | 420 // CPUProfile directly. |
422 func CPUProfile() []byte { | 421 func CPUProfile() []byte { |
423 return cpuprof.getprofile() | 422 return cpuprof.getprofile() |
424 } | 423 } |
LEFT | RIGHT |