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, |
| 49 Sampler* sampler, |
| 50 int period_in_useconds) |
49 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), | 51 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), |
50 generator_(generator), | 52 generator_(generator), |
| 53 sampler_(sampler), |
51 running_(true), | 54 running_(true), |
| 55 period_in_useconds_(period_in_useconds), |
52 ticks_buffer_(sizeof(TickSampleEventRecord), | 56 ticks_buffer_(sizeof(TickSampleEventRecord), |
53 kTickSamplesBufferChunkSize, | 57 kTickSamplesBufferChunkSize, |
54 kTickSamplesBufferChunksCount), | 58 kTickSamplesBufferChunksCount, |
| 59 !Sampler::CanSampleOnProfilerEventsProcessorThread()), |
55 enqueue_order_(0) { | 60 enqueue_order_(0) { |
56 } | 61 } |
57 | 62 |
58 | 63 |
59 void ProfilerEventsProcessor::CallbackCreateEvent(Logger::LogEventsAndTags tag, | 64 void ProfilerEventsProcessor::CallbackCreateEvent(Logger::LogEventsAndTags tag, |
60 const char* prefix, | 65 const char* prefix, |
61 String* name, | 66 String* name, |
62 Address start) { | 67 Address start) { |
63 if (FilterOutCodeCreateEvent(tag)) return; | 68 if (FilterOutCodeCreateEvent(tag)) return; |
64 CodeEventsContainer evt_rec; | 69 CodeEventsContainer evt_rec; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 record.sample.frames_count = 0; | 237 record.sample.frames_count = 0; |
233 generator_->RecordTickSample(record.sample); | 238 generator_->RecordTickSample(record.sample); |
234 ticks_buffer_.FinishDequeue(); | 239 ticks_buffer_.FinishDequeue(); |
235 } else { | 240 } else { |
236 return true; | 241 return true; |
237 } | 242 } |
238 } | 243 } |
239 } | 244 } |
240 | 245 |
241 | 246 |
| 247 void ProfilerEventsProcessor::ProcessEventsAndDoSample( |
| 248 unsigned* dequeue_order) { |
| 249 int64_t stop_time = OS::Ticks() + period_in_useconds_; |
| 250 // Keep processing existing events until we need to do next sample. |
| 251 while (OS::Ticks() < stop_time) { |
| 252 if (ProcessTicks(*dequeue_order)) { |
| 253 // All ticks of the current dequeue_order are processed, |
| 254 // proceed to the next code event. |
| 255 ProcessCodeEvent(dequeue_order); |
| 256 } |
| 257 } |
| 258 // Schedule next sample. sampler_ is NULL in tests. |
| 259 if (sampler_) |
| 260 sampler_->DoSample(); |
| 261 } |
| 262 |
| 263 |
| 264 void ProfilerEventsProcessor::ProcessEventsAndYield(unsigned* dequeue_order) { |
| 265 if (ProcessTicks(*dequeue_order)) { |
| 266 // All ticks of the current dequeue_order are processed, |
| 267 // proceed to the next code event. |
| 268 ProcessCodeEvent(dequeue_order); |
| 269 } |
| 270 YieldCPU(); |
| 271 } |
| 272 |
| 273 |
242 void ProfilerEventsProcessor::Run() { | 274 void ProfilerEventsProcessor::Run() { |
243 unsigned dequeue_order = 0; | 275 unsigned dequeue_order = 0; |
244 | 276 |
245 while (running_) { | 277 while (running_) { |
246 // Process ticks until we have any. | 278 if (Sampler::CanSampleOnProfilerEventsProcessorThread()) { |
247 if (ProcessTicks(dequeue_order)) { | 279 ProcessEventsAndDoSample(&dequeue_order); |
248 // All ticks of the current dequeue_order are processed, | 280 } else { |
249 // proceed to the next code event. | 281 ProcessEventsAndYield(&dequeue_order); |
250 ProcessCodeEvent(&dequeue_order); | |
251 } | 282 } |
252 YieldCPU(); | |
253 } | 283 } |
254 | 284 |
255 // Process remaining tick events. | 285 // Process remaining tick events. |
256 ticks_buffer_.FlushResidualRecords(); | 286 ticks_buffer_.FlushResidualRecords(); |
257 // Perform processing until we have tick events, skip remaining code events. | 287 // Perform processing until we have tick events, skip remaining code events. |
258 while (ProcessTicks(dequeue_order) && ProcessCodeEvent(&dequeue_order)) { } | 288 while (ProcessTicks(dequeue_order) && ProcessCodeEvent(&dequeue_order)) { } |
259 } | 289 } |
260 | 290 |
261 | 291 |
262 void CpuProfiler::StartProfiling(const char* title) { | 292 void CpuProfiler::StartProfiling(const char* title) { |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 | 509 |
480 void CpuProfiler::StartCollectingProfile(String* title) { | 510 void CpuProfiler::StartCollectingProfile(String* title) { |
481 StartCollectingProfile(profiles_->GetName(title)); | 511 StartCollectingProfile(profiles_->GetName(title)); |
482 } | 512 } |
483 | 513 |
484 | 514 |
485 void CpuProfiler::StartProcessorIfNotStarted() { | 515 void CpuProfiler::StartProcessorIfNotStarted() { |
486 if (processor_ == NULL) { | 516 if (processor_ == NULL) { |
487 Isolate* isolate = Isolate::Current(); | 517 Isolate* isolate = Isolate::Current(); |
488 | 518 |
| 519 Sampler* sampler = reinterpret_cast<Sampler*>(isolate->logger()->ticker_); |
489 // Disable logging when using the new implementation. | 520 // Disable logging when using the new implementation. |
490 saved_logging_nesting_ = isolate->logger()->logging_nesting_; | 521 saved_logging_nesting_ = isolate->logger()->logging_nesting_; |
491 isolate->logger()->logging_nesting_ = 0; | 522 isolate->logger()->logging_nesting_ = 0; |
492 generator_ = new ProfileGenerator(profiles_); | 523 generator_ = new ProfileGenerator(profiles_); |
493 processor_ = new ProfilerEventsProcessor(generator_); | 524 processor_ = new ProfilerEventsProcessor(generator_, |
| 525 sampler, |
| 526 FLAG_cpu_profiler_sampling_period); |
494 NoBarrier_Store(&is_profiling_, true); | 527 NoBarrier_Store(&is_profiling_, true); |
495 processor_->Start(); | |
496 // Enumerate stuff we already have in the heap. | 528 // Enumerate stuff we already have in the heap. |
497 if (isolate->heap()->HasBeenSetUp()) { | 529 if (isolate->heap()->HasBeenSetUp()) { |
498 if (!FLAG_prof_browser_mode) { | 530 if (!FLAG_prof_browser_mode) { |
499 bool saved_log_code_flag = FLAG_log_code; | 531 bool saved_log_code_flag = FLAG_log_code; |
500 FLAG_log_code = true; | 532 FLAG_log_code = true; |
501 isolate->logger()->LogCodeObjects(); | 533 isolate->logger()->LogCodeObjects(); |
502 FLAG_log_code = saved_log_code_flag; | 534 FLAG_log_code = saved_log_code_flag; |
503 } | 535 } |
504 isolate->logger()->LogCompiledFunctions(); | 536 isolate->logger()->LogCompiledFunctions(); |
505 isolate->logger()->LogAccessorCallbacks(); | 537 isolate->logger()->LogAccessorCallbacks(); |
506 } | 538 } |
507 // Enable stack sampling. | 539 // Enable stack sampling. |
508 Sampler* sampler = reinterpret_cast<Sampler*>(isolate->logger()->ticker_); | |
509 if (!sampler->IsActive()) { | 540 if (!sampler->IsActive()) { |
510 sampler->Start(); | 541 sampler->Start(); |
511 need_to_stop_sampler_ = true; | 542 need_to_stop_sampler_ = true; |
512 } | 543 } |
| 544 sampler->SetHasProcessingThread(true); |
513 sampler->IncreaseProfilingDepth(); | 545 sampler->IncreaseProfilingDepth(); |
| 546 processor_->Start(); |
514 } | 547 } |
515 } | 548 } |
516 | 549 |
517 | 550 |
518 CpuProfile* CpuProfiler::StopCollectingProfile(const char* title) { | 551 CpuProfile* CpuProfiler::StopCollectingProfile(const char* title) { |
519 const double actual_sampling_rate = generator_->actual_sampling_rate(); | 552 const double actual_sampling_rate = generator_->actual_sampling_rate(); |
520 StopProcessorIfLastProfile(title); | 553 StopProcessorIfLastProfile(title); |
521 CpuProfile* result = | 554 CpuProfile* result = |
522 profiles_->StopProfiling(TokenEnumerator::kNoSecurityToken, | 555 profiles_->StopProfiling(TokenEnumerator::kNoSecurityToken, |
523 title, | 556 title, |
(...skipping 17 matching lines...) Expand all Loading... |
541 | 574 |
542 void CpuProfiler::StopProcessorIfLastProfile(const char* title) { | 575 void CpuProfiler::StopProcessorIfLastProfile(const char* title) { |
543 if (profiles_->IsLastProfile(title)) StopProcessor(); | 576 if (profiles_->IsLastProfile(title)) StopProcessor(); |
544 } | 577 } |
545 | 578 |
546 | 579 |
547 void CpuProfiler::StopProcessor() { | 580 void CpuProfiler::StopProcessor() { |
548 Logger* logger = Isolate::Current()->logger(); | 581 Logger* logger = Isolate::Current()->logger(); |
549 Sampler* sampler = reinterpret_cast<Sampler*>(logger->ticker_); | 582 Sampler* sampler = reinterpret_cast<Sampler*>(logger->ticker_); |
550 sampler->DecreaseProfilingDepth(); | 583 sampler->DecreaseProfilingDepth(); |
| 584 sampler->SetHasProcessingThread(false); |
551 if (need_to_stop_sampler_) { | 585 if (need_to_stop_sampler_) { |
552 sampler->Stop(); | 586 sampler->Stop(); |
553 need_to_stop_sampler_ = false; | 587 need_to_stop_sampler_ = false; |
554 } | 588 } |
555 NoBarrier_Store(&is_profiling_, false); | 589 NoBarrier_Store(&is_profiling_, false); |
556 processor_->Stop(); | 590 processor_->Stop(); |
557 processor_->Join(); | 591 processor_->Join(); |
558 delete processor_; | 592 delete processor_; |
559 delete generator_; | 593 delete generator_; |
560 processor_ = NULL; | 594 processor_ = NULL; |
(...skipping 12 matching lines...) Expand all Loading... |
573 | 607 |
574 void CpuProfiler::TearDown() { | 608 void CpuProfiler::TearDown() { |
575 Isolate* isolate = Isolate::Current(); | 609 Isolate* isolate = Isolate::Current(); |
576 if (isolate->cpu_profiler() != NULL) { | 610 if (isolate->cpu_profiler() != NULL) { |
577 delete isolate->cpu_profiler(); | 611 delete isolate->cpu_profiler(); |
578 } | 612 } |
579 isolate->set_cpu_profiler(NULL); | 613 isolate->set_cpu_profiler(NULL); |
580 } | 614 } |
581 | 615 |
582 } } // namespace v8::internal | 616 } } // namespace v8::internal |
OLD | NEW |