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 27 matching lines...) Expand all Loading... | |
38 | 38 |
39 namespace v8 { | 39 namespace v8 { |
40 namespace internal { | 40 namespace internal { |
41 | 41 |
42 static const int kEventsBufferSize = 256 * KB; | 42 static const int kEventsBufferSize = 256 * KB; |
43 static const int kTickSamplesBufferChunkSize = 64 * KB; | 43 static const int kTickSamplesBufferChunkSize = 64 * KB; |
44 static const int kTickSamplesBufferChunksCount = 16; | 44 static const int kTickSamplesBufferChunksCount = 16; |
45 static const int kProfilerStackSize = 64 * KB; | 45 static const int kProfilerStackSize = 64 * KB; |
46 | 46 |
47 | 47 |
48 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator) | 48 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator, Sa mpler* sampler, int interval_in_useconds) |
49 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), | 49 : Thread(Thread::Options("CpuProfiler", kProfilerStackSize)), |
50 generator_(generator), | 50 generator_(generator), |
51 sampler_(sampler), | |
51 running_(true), | 52 running_(true), |
53 interval_in_useconds_(interval_in_useconds), | |
52 ticks_buffer_(sizeof(TickSampleEventRecord), | 54 ticks_buffer_(sizeof(TickSampleEventRecord), |
53 kTickSamplesBufferChunkSize, | 55 kTickSamplesBufferChunkSize, |
54 kTickSamplesBufferChunksCount), | 56 kTickSamplesBufferChunksCount), |
55 enqueue_order_(0) { | 57 enqueue_order_(0) { |
56 } | 58 } |
57 | 59 |
58 | 60 |
59 void ProfilerEventsProcessor::CallbackCreateEvent(Logger::LogEventsAndTags tag, | 61 void ProfilerEventsProcessor::CallbackCreateEvent(Logger::LogEventsAndTags tag, |
60 const char* prefix, | 62 const char* prefix, |
61 String* name, | 63 String* name, |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 #undef PROFILER_TYPE_CASE | 201 #undef PROFILER_TYPE_CASE |
200 default: return true; // Skip record. | 202 default: return true; // Skip record. |
201 } | 203 } |
202 *dequeue_order = record.generic.order; | 204 *dequeue_order = record.generic.order; |
203 return true; | 205 return true; |
204 } | 206 } |
205 return false; | 207 return false; |
206 } | 208 } |
207 | 209 |
208 | 210 |
209 bool ProfilerEventsProcessor::ProcessTicks(unsigned dequeue_order) { | 211 bool ProfilerEventsProcessor::ProcessTicks(int64_t stop_time, unsigned dequeue_o rder) { |
210 while (true) { | 212 while (stop_time == -1 || OS::Ticks() < stop_time) { |
211 if (!ticks_from_vm_buffer_.IsEmpty() | 213 if (!ticks_from_vm_buffer_.IsEmpty() |
212 && ticks_from_vm_buffer_.Peek()->order == dequeue_order) { | 214 && ticks_from_vm_buffer_.Peek()->order == dequeue_order) { |
213 TickSampleEventRecord record; | 215 TickSampleEventRecord record; |
214 ticks_from_vm_buffer_.Dequeue(&record); | 216 ticks_from_vm_buffer_.Dequeue(&record); |
215 generator_->RecordTickSample(record.sample); | 217 generator_->RecordTickSample(record.sample); |
216 } | 218 } |
217 | 219 |
218 const TickSampleEventRecord* rec = | 220 const TickSampleEventRecord* rec = |
219 TickSampleEventRecord::cast(ticks_buffer_.StartDequeue()); | 221 TickSampleEventRecord::cast(ticks_buffer_.StartDequeue()); |
220 if (rec == NULL) return !ticks_from_vm_buffer_.IsEmpty(); | 222 if (rec == NULL) return !ticks_from_vm_buffer_.IsEmpty(); |
221 // Make a local copy of tick sample record to ensure that it won't | 223 // Make a local copy of tick sample record to ensure that it won't |
222 // be modified as we are processing it. This is possible as the | 224 // be modified as we are processing it. This is possible as the |
223 // sampler writes w/o any sync to the queue, so if the processor | 225 // sampler writes w/o any sync to the queue, so if the processor |
224 // will get far behind, a record may be modified right under its | 226 // will get far behind, a record may be modified right under its |
225 // feet. | 227 // feet. |
226 TickSampleEventRecord record = *rec; | 228 TickSampleEventRecord record = *rec; |
227 if (record.order == dequeue_order) { | 229 if (record.order == dequeue_order) { |
228 // A paranoid check to make sure that we don't get a memory overrun | 230 // A paranoid check to make sure that we don't get a memory overrun |
229 // in case of frames_count having a wild value. | 231 // in case of frames_count having a wild value. |
230 if (record.sample.frames_count < 0 | 232 if (record.sample.frames_count < 0 |
231 || record.sample.frames_count > TickSample::kMaxFramesCount) | 233 || record.sample.frames_count > TickSample::kMaxFramesCount) |
232 record.sample.frames_count = 0; | 234 record.sample.frames_count = 0; |
233 generator_->RecordTickSample(record.sample); | 235 generator_->RecordTickSample(record.sample); |
234 ticks_buffer_.FinishDequeue(); | 236 ticks_buffer_.FinishDequeue(); |
235 } else { | 237 } else { |
236 return true; | 238 return true; |
237 } | 239 } |
238 } | 240 } |
241 return false; | |
239 } | 242 } |
240 | 243 |
241 | 244 |
245 void ProfilerEventsProcessor::ProcessEventsQueue(int64_t stop_time, unsigned* de queue_order) { | |
246 while (OS::Ticks() < stop_time) | |
247 // Process ticks until we have any. | |
248 if (ProcessTicks(stop_time, *dequeue_order)) { | |
249 // All ticks of the current dequeue_order are processed, | |
250 // proceed to the next code event. | |
251 ProcessCodeEvent(dequeue_order); | |
252 } | |
253 } | |
254 | |
255 | |
242 void ProfilerEventsProcessor::Run() { | 256 void ProfilerEventsProcessor::Run() { |
243 unsigned dequeue_order = 0; | 257 unsigned dequeue_order = 0; |
244 | 258 |
245 while (running_) { | 259 while (running_) { |
246 // Process ticks until we have any. | 260 if (FLAG_sample_stack_in_postprocessor_thread) { |
caseq
2012/08/17 16:59:28
if (sampler_ != NULL)
| |
247 if (ProcessTicks(dequeue_order)) { | 261 int64_t stop_time = OS::Ticks() + interval_in_useconds_; |
248 // All ticks of the current dequeue_order are processed, | 262 sampler_->DoSample(); |
249 // proceed to the next code event. | 263 ProcessEventsQueue(stop_time, &dequeue_order); |
250 ProcessCodeEvent(&dequeue_order); | 264 } else { |
265 // Process ticks until we have any. | |
266 if (ProcessTicks(-1, dequeue_order)) { | |
267 // All ticks of the current dequeue_order are processed, | |
268 // proceed to the next code event. | |
269 ProcessCodeEvent(&dequeue_order); | |
270 } | |
271 YieldCPU(); | |
251 } | 272 } |
252 YieldCPU(); | |
253 } | 273 } |
254 | 274 |
255 // Process remaining tick events. | 275 // Process remaining tick events. |
256 ticks_buffer_.FlushResidualRecords(); | 276 ticks_buffer_.FlushResidualRecords(); |
257 // Perform processing until we have tick events, skip remaining code events. | 277 // Perform processing until we have tick events, skip remaining code events. |
258 while (ProcessTicks(dequeue_order) && ProcessCodeEvent(&dequeue_order)) { } | 278 while (ProcessTicks(-1, dequeue_order) && ProcessCodeEvent(&dequeue_order)) { } |
259 } | 279 } |
260 | 280 |
261 | 281 |
262 void CpuProfiler::StartProfiling(const char* title) { | 282 void CpuProfiler::StartProfiling(const char* title) { |
263 ASSERT(Isolate::Current()->cpu_profiler() != NULL); | 283 ASSERT(Isolate::Current()->cpu_profiler() != NULL); |
264 Isolate::Current()->cpu_profiler()->StartCollectingProfile(title); | 284 Isolate::Current()->cpu_profiler()->StartCollectingProfile(title); |
265 } | 285 } |
266 | 286 |
267 | 287 |
268 void CpuProfiler::StartProfiling(String* title) { | 288 void CpuProfiler::StartProfiling(String* title) { |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 | 499 |
480 void CpuProfiler::StartCollectingProfile(String* title) { | 500 void CpuProfiler::StartCollectingProfile(String* title) { |
481 StartCollectingProfile(profiles_->GetName(title)); | 501 StartCollectingProfile(profiles_->GetName(title)); |
482 } | 502 } |
483 | 503 |
484 | 504 |
485 void CpuProfiler::StartProcessorIfNotStarted() { | 505 void CpuProfiler::StartProcessorIfNotStarted() { |
486 if (processor_ == NULL) { | 506 if (processor_ == NULL) { |
487 Isolate* isolate = Isolate::Current(); | 507 Isolate* isolate = Isolate::Current(); |
488 | 508 |
509 Sampler* sampler = isolate->logger()->sampler(); | |
489 // Disable logging when using the new implementation. | 510 // Disable logging when using the new implementation. |
490 saved_logging_nesting_ = isolate->logger()->logging_nesting_; | 511 saved_logging_nesting_ = isolate->logger()->logging_nesting_; |
491 isolate->logger()->logging_nesting_ = 0; | 512 isolate->logger()->logging_nesting_ = 0; |
492 generator_ = new ProfileGenerator(profiles_); | 513 generator_ = new ProfileGenerator(profiles_); |
493 processor_ = new ProfilerEventsProcessor(generator_); | 514 if (FLAG_sample_stack_in_postprocessor_thread) |
515 processor_ = new ProfilerEventsProcessor(generator_, sampler, sampler->int erval() * 1000); | |
516 else | |
517 processor_ = new ProfilerEventsProcessor(generator_, NULL, sampler->interv al() * 1000); | |
494 NoBarrier_Store(&is_profiling_, true); | 518 NoBarrier_Store(&is_profiling_, true); |
495 processor_->Start(); | 519 processor_->Start(); |
496 // Enumerate stuff we already have in the heap. | 520 // Enumerate stuff we already have in the heap. |
497 if (isolate->heap()->HasBeenSetUp()) { | 521 if (isolate->heap()->HasBeenSetUp()) { |
498 if (!FLAG_prof_browser_mode) { | 522 if (!FLAG_prof_browser_mode) { |
499 bool saved_log_code_flag = FLAG_log_code; | 523 bool saved_log_code_flag = FLAG_log_code; |
500 FLAG_log_code = true; | 524 FLAG_log_code = true; |
501 isolate->logger()->LogCodeObjects(); | 525 isolate->logger()->LogCodeObjects(); |
502 FLAG_log_code = saved_log_code_flag; | 526 FLAG_log_code = saved_log_code_flag; |
503 } | 527 } |
504 isolate->logger()->LogCompiledFunctions(); | 528 isolate->logger()->LogCompiledFunctions(); |
505 isolate->logger()->LogAccessorCallbacks(); | 529 isolate->logger()->LogAccessorCallbacks(); |
506 } | 530 } |
507 // Enable stack sampling. | 531 // Enable stack sampling. |
508 Sampler* sampler = reinterpret_cast<Sampler*>(isolate->logger()->ticker_); | |
509 if (!sampler->IsActive()) { | 532 if (!sampler->IsActive()) { |
510 sampler->Start(); | 533 sampler->Start(); |
511 need_to_stop_sampler_ = true; | 534 need_to_stop_sampler_ = true; |
512 } | 535 } |
513 sampler->IncreaseProfilingDepth(); | 536 sampler->IncreaseProfilingDepth(); |
514 } | 537 } |
515 } | 538 } |
516 | 539 |
517 | 540 |
518 CpuProfile* CpuProfiler::StopCollectingProfile(const char* title) { | 541 CpuProfile* CpuProfiler::StopCollectingProfile(const char* title) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
573 | 596 |
574 void CpuProfiler::TearDown() { | 597 void CpuProfiler::TearDown() { |
575 Isolate* isolate = Isolate::Current(); | 598 Isolate* isolate = Isolate::Current(); |
576 if (isolate->cpu_profiler() != NULL) { | 599 if (isolate->cpu_profiler() != NULL) { |
577 delete isolate->cpu_profiler(); | 600 delete isolate->cpu_profiler(); |
578 } | 601 } |
579 isolate->set_cpu_profiler(NULL); | 602 isolate->set_cpu_profiler(NULL); |
580 } | 603 } |
581 | 604 |
582 } } // namespace v8::internal | 605 } } // namespace v8::internal |
OLD | NEW |