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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 130 |
131 // Clamp hz to something reasonable. | 131 // Clamp hz to something reasonable. |
132 if(hz < 0) | 132 if(hz < 0) |
133 hz = 0; | 133 hz = 0; |
134 if(hz > 1000000) | 134 if(hz > 1000000) |
135 hz = 1000000; | 135 hz = 1000000; |
136 | 136 |
137 runtime·lock(&lk); | 137 runtime·lock(&lk); |
138 if(hz > 0) { | 138 if(hz > 0) { |
139 if(prof == nil) { | 139 if(prof == nil) { |
140 » » » prof = runtime·SysAlloc(sizeof *prof, &mstats.other_sys)
; | 140 » » » prof = runtime·sysAlloc(sizeof *prof, &mstats.other_sys)
; |
141 if(prof == nil) { | 141 if(prof == nil) { |
142 runtime·printf("runtime: cpu profiling cannot al
locate memory\n"); | 142 runtime·printf("runtime: cpu profiling cannot al
locate memory\n"); |
143 runtime·unlock(&lk); | 143 runtime·unlock(&lk); |
144 return; | 144 return; |
145 } | 145 } |
146 } | 146 } |
147 if(prof->on || prof->handoff != 0) { | 147 if(prof->on || prof->handoff != 0) { |
148 runtime·printf("runtime: cannot set cpu profile rate unt
il previous profile has finished.\n"); | 148 runtime·printf("runtime: cannot set cpu profile rate unt
il previous profile has finished.\n"); |
149 runtime·unlock(&lk); | 149 runtime·unlock(&lk); |
150 return; | 150 return; |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 if(!runtime·cas(&p->handoff, p->handoff, 0)) | 424 if(!runtime·cas(&p->handoff, p->handoff, 0)) |
425 runtime·printf("runtime: profile flush racing with something\n")
; | 425 runtime·printf("runtime: profile flush racing with something\n")
; |
426 return ret; // set to nil at top of function | 426 return ret; // set to nil at top of function |
427 } | 427 } |
428 | 428 |
429 // CPUProfile returns the next cpu profile block as a []byte. | 429 // CPUProfile returns the next cpu profile block as a []byte. |
430 // The user documentation is in debug.go. | 430 // The user documentation is in debug.go. |
431 func CPUProfile() (ret Slice) { | 431 func CPUProfile() (ret Slice) { |
432 ret = getprofile(prof); | 432 ret = getprofile(prof); |
433 } | 433 } |
LEFT | RIGHT |