| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/profiler/cpu-profiler.h" | 5 #include "src/profiler/cpu-profiler.h" |
| 6 | 6 |
| 7 #include "src/debug/debug.h" | 7 #include "src/debug/debug.h" |
| 8 #include "src/deoptimizer.h" | 8 #include "src/deoptimizer.h" |
| 9 #include "src/frames-inl.h" | 9 #include "src/frames-inl.h" |
| 10 #include "src/locked-queue-inl.h" | 10 #include "src/locked-queue-inl.h" |
| 11 #include "src/log-inl.h" | 11 #include "src/log-inl.h" |
| 12 #include "src/profiler/cpu-profiler-inl.h" | 12 #include "src/profiler/cpu-profiler-inl.h" |
| 13 #include "src/vm-state-inl.h" | 13 #include "src/vm-state-inl.h" |
| 14 | 14 |
| 15 #include "include/v8-profiler.h" | 15 #include "include/v8-profiler.h" |
| 16 | 16 |
| 17 namespace v8 { | 17 namespace v8 { |
| 18 namespace internal { | 18 namespace internal { |
| 19 | 19 |
| 20 static const int kProfilerStackSize = 64 * KB; | 20 static const int kProfilerStackSize = 64 * KB; |
| 21 | 21 |
| 22 | 22 |
| 23 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator, | 23 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator, |
| 24 Sampler* sampler, | 24 sampler::Sampler* sampler, |
| 25 base::TimeDelta period) | 25 base::TimeDelta period) |
| 26 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), | 26 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), |
| 27 generator_(generator), | 27 generator_(generator), |
| 28 sampler_(sampler), | 28 sampler_(sampler), |
| 29 running_(1), | 29 running_(1), |
| 30 period_(period), | 30 period_(period), |
| 31 last_code_event_id_(0), | 31 last_code_event_id_(0), |
| 32 last_processed_code_event_id_(0) {} | 32 last_processed_code_event_id_(0) {} |
| 33 | 33 |
| 34 | 34 |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 void CpuProfiler::StartProcessorIfNotStarted() { | 559 void CpuProfiler::StartProcessorIfNotStarted() { |
| 560 if (processor_ != NULL) { | 560 if (processor_ != NULL) { |
| 561 processor_->AddCurrentStack(isolate_); | 561 processor_->AddCurrentStack(isolate_); |
| 562 return; | 562 return; |
| 563 } | 563 } |
| 564 Logger* logger = isolate_->logger(); | 564 Logger* logger = isolate_->logger(); |
| 565 // Disable logging when using the new implementation. | 565 // Disable logging when using the new implementation. |
| 566 saved_is_logging_ = logger->is_logging_; | 566 saved_is_logging_ = logger->is_logging_; |
| 567 logger->is_logging_ = false; | 567 logger->is_logging_ = false; |
| 568 generator_ = new ProfileGenerator(profiles_); | 568 generator_ = new ProfileGenerator(profiles_); |
| 569 Sampler* sampler = logger->sampler(); | 569 sampler::Sampler* sampler = logger->sampler(); |
| 570 processor_ = new ProfilerEventsProcessor( | 570 processor_ = new ProfilerEventsProcessor( |
| 571 generator_, sampler, sampling_interval_); | 571 generator_, sampler, sampling_interval_); |
| 572 is_profiling_ = true; | 572 is_profiling_ = true; |
| 573 // Enumerate stuff we already have in the heap. | 573 // Enumerate stuff we already have in the heap. |
| 574 DCHECK(isolate_->heap()->HasBeenSetUp()); | 574 DCHECK(isolate_->heap()->HasBeenSetUp()); |
| 575 if (!FLAG_prof_browser_mode) { | 575 if (!FLAG_prof_browser_mode) { |
| 576 logger->LogCodeObjects(); | 576 logger->LogCodeObjects(); |
| 577 } | 577 } |
| 578 logger->LogCompiledFunctions(); | 578 logger->LogCompiledFunctions(); |
| 579 logger->LogAccessorCallbacks(); | 579 logger->LogAccessorCallbacks(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 605 } | 605 } |
| 606 | 606 |
| 607 | 607 |
| 608 void CpuProfiler::StopProcessorIfLastProfile(const char* title) { | 608 void CpuProfiler::StopProcessorIfLastProfile(const char* title) { |
| 609 if (profiles_->IsLastProfile(title)) StopProcessor(); | 609 if (profiles_->IsLastProfile(title)) StopProcessor(); |
| 610 } | 610 } |
| 611 | 611 |
| 612 | 612 |
| 613 void CpuProfiler::StopProcessor() { | 613 void CpuProfiler::StopProcessor() { |
| 614 Logger* logger = isolate_->logger(); | 614 Logger* logger = isolate_->logger(); |
| 615 Sampler* sampler = reinterpret_cast<Sampler*>(logger->ticker_); | 615 sampler::Sampler* sampler = |
| 616 reinterpret_cast<sampler::Sampler*>(logger->ticker_); |
| 616 is_profiling_ = false; | 617 is_profiling_ = false; |
| 617 processor_->StopSynchronously(); | 618 processor_->StopSynchronously(); |
| 618 delete processor_; | 619 delete processor_; |
| 619 delete generator_; | 620 delete generator_; |
| 620 processor_ = NULL; | 621 processor_ = NULL; |
| 621 generator_ = NULL; | 622 generator_ = NULL; |
| 622 sampler->SetHasProcessingThread(false); | 623 sampler->SetHasProcessingThread(false); |
| 623 sampler->DecreaseProfilingDepth(); | 624 sampler->DecreaseProfilingDepth(); |
| 624 logger->is_logging_ = saved_is_logging_; | 625 logger->is_logging_ = saved_is_logging_; |
| 625 } | 626 } |
| 626 | 627 |
| 627 | 628 |
| 628 void CpuProfiler::LogBuiltins() { | 629 void CpuProfiler::LogBuiltins() { |
| 629 Builtins* builtins = isolate_->builtins(); | 630 Builtins* builtins = isolate_->builtins(); |
| 630 DCHECK(builtins->is_initialized()); | 631 DCHECK(builtins->is_initialized()); |
| 631 for (int i = 0; i < Builtins::builtin_count; i++) { | 632 for (int i = 0; i < Builtins::builtin_count; i++) { |
| 632 CodeEventsContainer evt_rec(CodeEventRecord::REPORT_BUILTIN); | 633 CodeEventsContainer evt_rec(CodeEventRecord::REPORT_BUILTIN); |
| 633 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_; | 634 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_; |
| 634 Builtins::Name id = static_cast<Builtins::Name>(i); | 635 Builtins::Name id = static_cast<Builtins::Name>(i); |
| 635 rec->start = builtins->builtin(id)->address(); | 636 rec->start = builtins->builtin(id)->address(); |
| 636 rec->builtin_id = id; | 637 rec->builtin_id = id; |
| 637 processor_->Enqueue(evt_rec); | 638 processor_->Enqueue(evt_rec); |
| 638 } | 639 } |
| 639 } | 640 } |
| 640 | 641 |
| 641 | 642 |
| 642 } // namespace internal | 643 } // namespace internal |
| 643 } // namespace v8 | 644 } // namespace v8 |
| OLD | NEW |