OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 21 matching lines...) Expand all Loading... | |
32 #include "frames-inl.h" | 32 #include "frames-inl.h" |
33 #include "hashmap.h" | 33 #include "hashmap.h" |
34 #include "log-inl.h" | 34 #include "log-inl.h" |
35 #include "vm-state-inl.h" | 35 #include "vm-state-inl.h" |
36 | 36 |
37 #include "../include/v8-profiler.h" | 37 #include "../include/v8-profiler.h" |
38 | 38 |
39 namespace v8 { | 39 namespace v8 { |
40 namespace internal { | 40 namespace internal { |
41 | 41 |
42 static const int kEventsBufferSize = 256 * KB; | |
43 static const int kTickSamplesBufferChunkSize = 64 * KB; | |
44 static const int kTickSamplesBufferChunksCount = 16; | |
45 static const int kProfilerStackSize = 64 * KB; | 42 static const int kProfilerStackSize = 64 * KB; |
46 | 43 |
47 | 44 |
48 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator, | 45 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator, |
49 Sampler* sampler, | 46 Sampler* sampler, |
50 int period_in_useconds) | 47 int period_in_useconds) |
51 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), | 48 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), |
52 generator_(generator), | 49 generator_(generator), |
53 sampler_(sampler), | 50 sampler_(sampler), |
54 running_(true), | 51 running_(true), |
55 period_in_useconds_(period_in_useconds), | 52 period_in_useconds_(period_in_useconds), |
56 ticks_buffer_(sizeof(TickSampleEventRecord), | 53 ticks_buffer_is_empty_(true), |
57 kTickSamplesBufferChunkSize, | 54 ticks_buffer_is_initialized_(false), |
58 kTickSamplesBufferChunksCount), | |
59 enqueue_order_(0) { | 55 enqueue_order_(0) { |
60 } | 56 } |
61 | 57 |
62 | 58 |
63 void ProfilerEventsProcessor::CallbackCreateEvent(Logger::LogEventsAndTags tag, | 59 void ProfilerEventsProcessor::CallbackCreateEvent(Logger::LogEventsAndTags tag, |
64 const char* prefix, | 60 const char* prefix, |
65 String* name, | 61 String* name, |
66 Address start) { | 62 Address start) { |
67 if (FilterOutCodeCreateEvent(tag)) return; | 63 if (FilterOutCodeCreateEvent(tag)) return; |
68 CodeEventsContainer evt_rec; | 64 CodeEventsContainer evt_rec; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 #undef PROFILER_TYPE_CASE | 199 #undef PROFILER_TYPE_CASE |
204 default: return true; // Skip record. | 200 default: return true; // Skip record. |
205 } | 201 } |
206 *dequeue_order = record.generic.order; | 202 *dequeue_order = record.generic.order; |
207 return true; | 203 return true; |
208 } | 204 } |
209 return false; | 205 return false; |
210 } | 206 } |
211 | 207 |
212 | 208 |
213 bool ProfilerEventsProcessor::ProcessTicks(int64_t stop_time, | 209 bool ProfilerEventsProcessor::ProcessTicks(unsigned dequeue_order) { |
214 unsigned dequeue_order) { | 210 while (true) { |
215 while (stop_time == -1 || OS::Ticks() < stop_time) { | |
216 if (!ticks_from_vm_buffer_.IsEmpty() | 211 if (!ticks_from_vm_buffer_.IsEmpty() |
217 && ticks_from_vm_buffer_.Peek()->order == dequeue_order) { | 212 && ticks_from_vm_buffer_.Peek()->order == dequeue_order) { |
218 TickSampleEventRecord record; | 213 TickSampleEventRecord record; |
219 ticks_from_vm_buffer_.Dequeue(&record); | 214 ticks_from_vm_buffer_.Dequeue(&record); |
220 generator_->RecordTickSample(record.sample); | 215 generator_->RecordTickSample(record.sample); |
221 } | 216 } |
222 | 217 |
223 const TickSampleEventRecord* rec = | 218 if (ticks_buffer_is_empty_) return !ticks_from_vm_buffer_.IsEmpty(); |
224 TickSampleEventRecord::cast(ticks_buffer_.StartDequeue()); | 219 if (ticks_buffer_.order == dequeue_order) { |
225 if (rec == NULL) return !ticks_from_vm_buffer_.IsEmpty(); | |
226 // Make a local copy of tick sample record to ensure that it won't | |
227 // be modified as we are processing it. This is possible as the | |
228 // sampler writes w/o any sync to the queue, so if the processor | |
229 // will get far behind, a record may be modified right under its | |
230 // feet. | |
231 TickSampleEventRecord record = *rec; | |
232 if (record.order == dequeue_order) { | |
233 // A paranoid check to make sure that we don't get a memory overrun | 220 // A paranoid check to make sure that we don't get a memory overrun |
234 // in case of frames_count having a wild value. | 221 // in case of frames_count having a wild value. |
235 if (record.sample.frames_count < 0 | 222 if (ticks_buffer_.sample.frames_count < 0 |
236 || record.sample.frames_count > TickSample::kMaxFramesCount) | 223 || ticks_buffer_.sample.frames_count > TickSample::kMaxFramesCount) { |
237 record.sample.frames_count = 0; | 224 ticks_buffer_.sample.frames_count = 0; |
238 generator_->RecordTickSample(record.sample); | 225 } |
239 ticks_buffer_.FinishDequeue(); | 226 generator_->RecordTickSample(ticks_buffer_.sample); |
227 ticks_buffer_is_empty_ = true; | |
228 ticks_buffer_is_initialized_ = false; | |
240 } else { | 229 } else { |
241 return true; | 230 return true; |
242 } | 231 } |
243 } | 232 } |
244 return false; | |
245 } | 233 } |
246 | 234 |
247 | 235 |
248 void ProfilerEventsProcessor::ProcessEventsQueue(int64_t stop_time, | 236 void ProfilerEventsProcessor::ProcessEventsQueue(int64_t stop_time, |
249 unsigned* dequeue_order) { | 237 unsigned* dequeue_order) { |
250 while (OS::Ticks() < stop_time) { | 238 while (OS::Ticks() < stop_time) { |
251 if (ProcessTicks(stop_time, *dequeue_order)) { | 239 if (ProcessTicks(*dequeue_order)) { |
252 // All ticks of the current dequeue_order are processed, | 240 // All ticks of the current dequeue_order are processed, |
253 // proceed to the next code event. | 241 // proceed to the next code event. |
254 ProcessCodeEvent(dequeue_order); | 242 ProcessCodeEvent(dequeue_order); |
255 } | 243 } |
256 } | 244 } |
257 } | 245 } |
258 | 246 |
259 | 247 |
260 void ProfilerEventsProcessor::Run() { | 248 void ProfilerEventsProcessor::Run() { |
261 unsigned dequeue_order = 0; | 249 unsigned dequeue_order = 0; |
262 | 250 |
263 while (running_) { | 251 while (running_) { |
264 int64_t stop_time = OS::Ticks() + period_in_useconds_; | 252 int64_t stop_time = OS::Ticks() + period_in_useconds_; |
265 if (sampler_ != NULL) | 253 if (sampler_ != NULL) |
266 sampler_->DoSample(); | 254 sampler_->DoSample(); |
Jakob Kummerow
2012/09/04 17:44:46
{} please
| |
267 ProcessEventsQueue(stop_time, &dequeue_order); | 255 ProcessEventsQueue(stop_time, &dequeue_order); |
268 } | 256 } |
269 | 257 |
270 // Process remaining tick events. | 258 while (ProcessTicks(dequeue_order) && ProcessCodeEvent(&dequeue_order)) { } |
271 ticks_buffer_.FlushResidualRecords(); | |
272 // Perform processing until we have tick events, skip remaining code events. | |
273 while (ProcessTicks(-1, dequeue_order) && ProcessCodeEvent(&dequeue_order)) { | |
274 } | |
275 } | 259 } |
276 | 260 |
277 | 261 |
278 void CpuProfiler::StartProfiling(const char* title) { | 262 void CpuProfiler::StartProfiling(const char* title) { |
279 ASSERT(Isolate::Current()->cpu_profiler() != NULL); | 263 ASSERT(Isolate::Current()->cpu_profiler() != NULL); |
280 Isolate::Current()->cpu_profiler()->StartCollectingProfile(title); | 264 Isolate::Current()->cpu_profiler()->StartCollectingProfile(title); |
281 } | 265 } |
282 | 266 |
283 | 267 |
284 void CpuProfiler::StartProfiling(String* title) { | 268 void CpuProfiler::StartProfiling(String* title) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 | 303 |
320 | 304 |
321 CpuProfile* CpuProfiler::FindProfile(Object* security_token, unsigned uid) { | 305 CpuProfile* CpuProfiler::FindProfile(Object* security_token, unsigned uid) { |
322 ASSERT(Isolate::Current()->cpu_profiler() != NULL); | 306 ASSERT(Isolate::Current()->cpu_profiler() != NULL); |
323 CpuProfiler* profiler = Isolate::Current()->cpu_profiler(); | 307 CpuProfiler* profiler = Isolate::Current()->cpu_profiler(); |
324 const int token = profiler->token_enumerator_->GetTokenId(security_token); | 308 const int token = profiler->token_enumerator_->GetTokenId(security_token); |
325 return profiler->profiles_->GetProfile(token, uid); | 309 return profiler->profiles_->GetProfile(token, uid); |
326 } | 310 } |
327 | 311 |
328 | 312 |
329 TickSample* CpuProfiler::TickSampleEvent(Isolate* isolate) { | 313 TickSample* CpuProfiler::StartTickSampleEvent(Isolate* isolate) { |
330 if (CpuProfiler::is_profiling(isolate)) { | 314 if (CpuProfiler::is_profiling(isolate)) { |
331 return isolate->cpu_profiler()->processor_->TickSampleEvent(); | 315 return isolate->cpu_profiler()->processor_->StartTickSampleEvent(); |
332 } else { | 316 } else { |
333 return NULL; | 317 return NULL; |
334 } | 318 } |
335 } | 319 } |
336 | 320 |
337 | 321 |
322 void CpuProfiler::FinishTickSampleEvent(Isolate* isolate) { | |
323 if (CpuProfiler::is_profiling(isolate)) { | |
324 isolate->cpu_profiler()->processor_->FinishTickSampleEvent(); | |
325 } | |
326 } | |
327 | |
328 | |
338 void CpuProfiler::DeleteAllProfiles() { | 329 void CpuProfiler::DeleteAllProfiles() { |
339 Isolate* isolate = Isolate::Current(); | 330 Isolate* isolate = Isolate::Current(); |
340 ASSERT(isolate->cpu_profiler() != NULL); | 331 ASSERT(isolate->cpu_profiler() != NULL); |
341 if (is_profiling(isolate)) { | 332 if (is_profiling(isolate)) { |
342 isolate->cpu_profiler()->StopProcessor(); | 333 isolate->cpu_profiler()->StopProcessor(); |
343 } | 334 } |
344 isolate->cpu_profiler()->ResetProfiles(); | 335 isolate->cpu_profiler()->ResetProfiles(); |
345 } | 336 } |
346 | 337 |
347 | 338 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
591 | 582 |
592 void CpuProfiler::TearDown() { | 583 void CpuProfiler::TearDown() { |
593 Isolate* isolate = Isolate::Current(); | 584 Isolate* isolate = Isolate::Current(); |
594 if (isolate->cpu_profiler() != NULL) { | 585 if (isolate->cpu_profiler() != NULL) { |
595 delete isolate->cpu_profiler(); | 586 delete isolate->cpu_profiler(); |
596 } | 587 } |
597 isolate->set_cpu_profiler(NULL); | 588 isolate->set_cpu_profiler(NULL); |
598 } | 589 } |
599 | 590 |
600 } } // namespace v8::internal | 591 } } // namespace v8::internal |
OLD | NEW |