1 // AUTO-GENERATED by autogen.sh; DO NOT EDIT
8 #line 57 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
9 typedef struct __go_open_array Slice
;
10 #define array __values
12 #define cap __capacity
13 #line 62 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
21 #line 70 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
22 typedef struct Profile Profile
;
23 typedef struct Bucket Bucket
;
24 typedef struct Entry Entry
;
25 #line 74 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
29 uintptr stack
[MaxStack
];
31 #line 80 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
35 #line 84 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
43 #line 93 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
44 Bucket hash
[HashSize
];
45 #line 98 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
46 uintptr log
[2][LogSize
/2];
50 #line 106 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
56 #line 112 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
59 #line 115 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
60 static void tick ( uintptr
* , int32
) ;
61 static void add ( Profile
* , uintptr
* , int32
) ;
62 static bool evict ( Profile
* , Entry
* ) ;
63 static bool flushlog ( Profile
* ) ;
64 #line 120 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
65 static uintptr eod
[3] = { 0 , 1 , 0 } ;
66 #line 125 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
68 LostProfileData ( void )
71 #line 130 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
72 extern void runtime_SetCPUProfileRate ( intgo
)
73 __asm__ ( GOSYM_PREFIX
"runtime.SetCPUProfileRate" ) ;
74 #line 135 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
76 runtime_SetCPUProfileRate ( intgo hz
)
80 #line 142 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
85 #line 147 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
86 runtime_lock ( &lk
) ;
89 prof
= runtime_SysAlloc ( sizeof *prof
, &mstats
.other_sys
) ;
91 runtime_printf ( "runtime: cpu profiling cannot allocate memory\n" ) ;
92 runtime_unlock ( &lk
) ;
96 if ( prof
->on
|| prof
->handoff
!= 0 ) {
97 runtime_printf ( "runtime: cannot set cpu profile rate until previous profile has finished.\n" ) ;
98 runtime_unlock ( &lk
) ;
101 #line 163 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
104 #line 167 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
110 prof
->nlog
= p
- prof
->log
[0];
112 prof
->wholding
= false;
114 prof
->flushing
= false;
115 prof
->eod_sent
= false;
116 runtime_noteclear ( &prof
->wait
) ;
117 #line 180 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
118 runtime_setcpuprofilerate ( tick
, hz
) ;
119 } else if ( prof
!= nil
&& prof
->on
) {
120 runtime_setcpuprofilerate ( nil
, 0 ) ;
122 #line 187 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
126 runtime_printf ( "runtime: setcpuprofile(off) twice" ) ;
127 if ( runtime_cas ( &prof
->handoff
, n
, n
|0x80000000 ) )
131 #line 196 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
132 runtime_notewakeup ( &prof
->wait
) ;
135 runtime_unlock ( &lk
) ;
137 #line 202 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
139 tick ( uintptr
*pc
, int32 n
)
141 add ( prof
, pc
, n
) ;
143 #line 213 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
145 add ( Profile
*p
, uintptr
*pc
, int32 n
)
151 #line 221 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
154 #line 225 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
156 for ( i
=0; i
<n
; i
++ ) {
157 h
= h
<<8 | ( h
>> ( 8* ( sizeof ( h
) -1 ) ) ) ;
159 h
+= x
*31 + x
*7 + x
*3;
162 #line 234 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
163 b
= &p
->hash
[h
%HashSize
];
164 for ( i
=0; i
<Assoc
; i
++ ) {
166 if ( e
->depth
!= ( uintptr
) n
)
168 for ( j
=0; j
<n
; j
++ )
169 if ( e
->stack
[j
] != pc
[j
] )
175 #line 248 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
177 for ( i
=1; i
<Assoc
; i
++ )
178 if ( b
->entry
[i
].count
< e
->count
)
180 if ( e
->count
> 0 ) {
181 if ( !evict ( p
, e
) ) {
182 #line 255 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
189 #line 263 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
192 for ( i
=0; i
<n
; i
++ )
195 #line 275 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
197 evict ( Profile
*p
, Entry
*e
)
201 #line 281 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
204 log
= p
->log
[p
->toggle
];
205 if ( p
->nlog
+nslot
> nelem ( p
->log
[0] ) ) {
206 if ( !flushlog ( p
) )
208 log
= p
->log
[p
->toggle
];
210 #line 290 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
214 for ( i
=0; i
<d
; i
++ )
220 #line 304 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
222 flushlog ( Profile
*p
)
225 #line 309 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
226 if ( !runtime_cas ( &p
->handoff
, 0 , p
->nlog
) )
228 runtime_notewakeup ( &p
->wait
) ;
229 #line 313 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
230 p
->toggle
= 1 - p
->toggle
;
231 log
= p
->log
[p
->toggle
];
236 *q
++ = ( uintptr
) LostProfileData
;
241 #line 327 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
243 getprofile ( Profile
*p
)
249 #line 335 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
253 #line 339 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
256 #line 342 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
258 #line 345 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
262 runtime_printf ( "runtime: phase error during cpu profile handoff\n" ) ;
265 if ( n
& 0x80000000 ) {
266 p
->wtoggle
= 1 - p
->wtoggle
;
271 if ( runtime_cas ( &p
->handoff
, n
, 0 ) )
274 p
->wtoggle
= 1 - p
->wtoggle
;
277 #line 364 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
280 #line 367 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
281 if ( !p
->on
&& p
->handoff
== 0 )
283 #line 371 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
284 runtime_notetsleepg ( &p
->wait
, -1 ) ;
285 runtime_noteclear ( &p
->wait
) ;
286 #line 374 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
289 runtime_printf ( "runtime: phase error during cpu profile wait\n" ) ;
292 if ( n
== 0x80000000 ) {
297 #line 386 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
299 #line 388 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
300 ret
.array
= ( byte
* ) p
->log
[p
->wtoggle
];
301 ret
.len
= n
*sizeof ( uintptr
) ;
304 #line 393 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
306 #line 398 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
307 for ( i
=0; i
<HashSize
; i
++ ) {
309 for ( j
=0; j
<Assoc
; j
++ ) {
311 if ( e
->count
> 0 && !evict ( p
, e
) ) {
312 #line 404 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
318 #line 411 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
320 #line 414 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
321 ret
.array
= ( byte
* ) p
->log
[p
->toggle
];
322 ret
.len
= p
->nlog
*sizeof ( uintptr
) ;
327 #line 422 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
328 if ( !p
->eod_sent
) {
329 #line 425 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
331 ret
.array
= ( byte
* ) eod
;
332 ret
.len
= sizeof eod
;
336 #line 433 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
338 if ( !runtime_cas ( &p
->handoff
, p
->handoff
, 0 ) )
339 runtime_printf ( "runtime: profile flush racing with something\n" ) ;
342 Slice
runtime_CPUProfile() __asm__ (GOSYM_PREFIX
"runtime.CPUProfile");
343 Slice
runtime_CPUProfile()
346 #line 441 "../../../trunk/libgo/runtime/../../../trunk/libgo/runtime/cpuprof.goc"
348 ret
= getprofile(prof
);