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" |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 entry->AddDeoptInlinedFrames(deopt_id, inlined_frames); | 492 entry->AddDeoptInlinedFrames(deopt_id, inlined_frames); |
493 DCHECK(inlined_frames.empty()); | 493 DCHECK(inlined_frames.empty()); |
494 } | 494 } |
495 } | 495 } |
496 } | 496 } |
497 | 497 |
498 CpuProfiler::CpuProfiler(Isolate* isolate) | 498 CpuProfiler::CpuProfiler(Isolate* isolate) |
499 : isolate_(isolate), | 499 : isolate_(isolate), |
500 sampling_interval_(base::TimeDelta::FromMicroseconds( | 500 sampling_interval_(base::TimeDelta::FromMicroseconds( |
501 FLAG_cpu_profiler_sampling_interval)), | 501 FLAG_cpu_profiler_sampling_interval)), |
502 profiles_(new CpuProfilesCollection(isolate->heap())), | 502 profiles_(new CpuProfilesCollection(isolate)), |
503 generator_(NULL), | |
504 processor_(NULL), | |
505 is_profiling_(false) { | 503 is_profiling_(false) { |
| 504 profiles_->set_cpu_profiler(this); |
506 } | 505 } |
507 | 506 |
508 | 507 CpuProfiler::CpuProfiler(Isolate* isolate, CpuProfilesCollection* test_profiles, |
509 CpuProfiler::CpuProfiler(Isolate* isolate, | |
510 CpuProfilesCollection* test_profiles, | |
511 ProfileGenerator* test_generator, | 508 ProfileGenerator* test_generator, |
512 ProfilerEventsProcessor* test_processor) | 509 ProfilerEventsProcessor* test_processor) |
513 : isolate_(isolate), | 510 : isolate_(isolate), |
514 sampling_interval_(base::TimeDelta::FromMicroseconds( | 511 sampling_interval_(base::TimeDelta::FromMicroseconds( |
515 FLAG_cpu_profiler_sampling_interval)), | 512 FLAG_cpu_profiler_sampling_interval)), |
516 profiles_(test_profiles), | 513 profiles_(test_profiles), |
517 generator_(test_generator), | 514 generator_(test_generator), |
518 processor_(test_processor), | 515 processor_(test_processor), |
519 is_profiling_(false) { | 516 is_profiling_(false) { |
| 517 profiles_->set_cpu_profiler(this); |
520 } | 518 } |
521 | 519 |
522 | |
523 CpuProfiler::~CpuProfiler() { | 520 CpuProfiler::~CpuProfiler() { |
524 DCHECK(!is_profiling_); | 521 DCHECK(!is_profiling_); |
525 delete profiles_; | |
526 } | 522 } |
527 | 523 |
528 | |
529 void CpuProfiler::set_sampling_interval(base::TimeDelta value) { | 524 void CpuProfiler::set_sampling_interval(base::TimeDelta value) { |
530 DCHECK(!is_profiling_); | 525 DCHECK(!is_profiling_); |
531 sampling_interval_ = value; | 526 sampling_interval_ = value; |
532 } | 527 } |
533 | 528 |
534 | |
535 void CpuProfiler::ResetProfiles() { | 529 void CpuProfiler::ResetProfiles() { |
536 delete profiles_; | 530 profiles_.reset(new CpuProfilesCollection(isolate_)); |
537 profiles_ = new CpuProfilesCollection(isolate()->heap()); | 531 profiles_->set_cpu_profiler(this); |
538 } | 532 } |
539 | 533 |
540 void CpuProfiler::CollectSample() { | 534 void CpuProfiler::CollectSample() { |
541 if (processor_ != NULL) { | 535 if (processor_) { |
542 processor_->AddCurrentStack(isolate_); | 536 processor_->AddCurrentStack(isolate_); |
543 } | 537 } |
544 } | 538 } |
545 | 539 |
546 void CpuProfiler::StartProfiling(const char* title, bool record_samples) { | 540 void CpuProfiler::StartProfiling(const char* title, bool record_samples) { |
547 if (profiles_->StartProfiling(title, record_samples)) { | 541 if (profiles_->StartProfiling(title, record_samples)) { |
548 StartProcessorIfNotStarted(); | 542 StartProcessorIfNotStarted(); |
549 } | 543 } |
550 } | 544 } |
551 | 545 |
552 | 546 |
553 void CpuProfiler::StartProfiling(String* title, bool record_samples) { | 547 void CpuProfiler::StartProfiling(String* title, bool record_samples) { |
554 StartProfiling(profiles_->GetName(title), record_samples); | 548 StartProfiling(profiles_->GetName(title), record_samples); |
555 isolate_->debug()->feature_tracker()->Track(DebugFeatureTracker::kProfiler); | 549 isolate_->debug()->feature_tracker()->Track(DebugFeatureTracker::kProfiler); |
556 } | 550 } |
557 | 551 |
558 | 552 |
559 void CpuProfiler::StartProcessorIfNotStarted() { | 553 void CpuProfiler::StartProcessorIfNotStarted() { |
560 if (processor_ != NULL) { | 554 if (processor_) { |
561 processor_->AddCurrentStack(isolate_); | 555 processor_->AddCurrentStack(isolate_); |
562 return; | 556 return; |
563 } | 557 } |
564 Logger* logger = isolate_->logger(); | 558 Logger* logger = isolate_->logger(); |
565 // Disable logging when using the new implementation. | 559 // Disable logging when using the new implementation. |
566 saved_is_logging_ = logger->is_logging_; | 560 saved_is_logging_ = logger->is_logging_; |
567 logger->is_logging_ = false; | 561 logger->is_logging_ = false; |
568 generator_ = new ProfileGenerator(profiles_); | |
569 sampler::Sampler* sampler = logger->sampler(); | 562 sampler::Sampler* sampler = logger->sampler(); |
570 processor_ = new ProfilerEventsProcessor( | 563 generator_.reset(new ProfileGenerator(profiles_.get())); |
571 generator_, sampler, sampling_interval_); | 564 processor_.reset(new ProfilerEventsProcessor(generator_.get(), sampler, |
| 565 sampling_interval_)); |
572 is_profiling_ = true; | 566 is_profiling_ = true; |
573 isolate_->set_is_profiling(true); | 567 isolate_->set_is_profiling(true); |
574 // Enumerate stuff we already have in the heap. | 568 // Enumerate stuff we already have in the heap. |
575 DCHECK(isolate_->heap()->HasBeenSetUp()); | 569 DCHECK(isolate_->heap()->HasBeenSetUp()); |
576 if (!FLAG_prof_browser_mode) { | 570 if (!FLAG_prof_browser_mode) { |
577 logger->LogCodeObjects(); | 571 logger->LogCodeObjects(); |
578 } | 572 } |
579 logger->LogCompiledFunctions(); | 573 logger->LogCompiledFunctions(); |
580 logger->LogAccessorCallbacks(); | 574 logger->LogAccessorCallbacks(); |
581 LogBuiltins(); | 575 LogBuiltins(); |
582 // Enable stack sampling. | 576 // Enable stack sampling. |
583 sampler->SetHasProcessingThread(true); | 577 sampler->SetHasProcessingThread(true); |
584 sampler->IncreaseProfilingDepth(); | 578 sampler->IncreaseProfilingDepth(); |
585 processor_->AddCurrentStack(isolate_); | 579 processor_->AddCurrentStack(isolate_); |
586 processor_->StartSynchronously(); | 580 processor_->StartSynchronously(); |
587 } | 581 } |
588 | 582 |
589 | 583 |
590 CpuProfile* CpuProfiler::StopProfiling(const char* title) { | 584 CpuProfile* CpuProfiler::StopProfiling(const char* title) { |
591 if (!is_profiling_) return NULL; | 585 if (!is_profiling_) return nullptr; |
592 StopProcessorIfLastProfile(title); | 586 StopProcessorIfLastProfile(title); |
593 CpuProfile* result = profiles_->StopProfiling(title); | 587 CpuProfile* result = profiles_->StopProfiling(title); |
594 if (result != NULL) { | 588 if (result) { |
595 result->Print(); | 589 result->Print(); |
596 } | 590 } |
597 return result; | 591 return result; |
598 } | 592 } |
599 | 593 |
600 | 594 |
601 CpuProfile* CpuProfiler::StopProfiling(String* title) { | 595 CpuProfile* CpuProfiler::StopProfiling(String* title) { |
602 if (!is_profiling_) return NULL; | 596 if (!is_profiling_) return nullptr; |
603 const char* profile_title = profiles_->GetName(title); | 597 const char* profile_title = profiles_->GetName(title); |
604 StopProcessorIfLastProfile(profile_title); | 598 StopProcessorIfLastProfile(profile_title); |
605 return profiles_->StopProfiling(profile_title); | 599 return profiles_->StopProfiling(profile_title); |
606 } | 600 } |
607 | 601 |
608 | 602 |
609 void CpuProfiler::StopProcessorIfLastProfile(const char* title) { | 603 void CpuProfiler::StopProcessorIfLastProfile(const char* title) { |
610 if (profiles_->IsLastProfile(title)) StopProcessor(); | 604 if (profiles_->IsLastProfile(title)) { |
| 605 StopProcessor(); |
| 606 } |
611 } | 607 } |
612 | 608 |
613 | 609 |
614 void CpuProfiler::StopProcessor() { | 610 void CpuProfiler::StopProcessor() { |
615 Logger* logger = isolate_->logger(); | 611 Logger* logger = isolate_->logger(); |
616 sampler::Sampler* sampler = | 612 sampler::Sampler* sampler = |
617 reinterpret_cast<sampler::Sampler*>(logger->ticker_); | 613 reinterpret_cast<sampler::Sampler*>(logger->ticker_); |
618 is_profiling_ = false; | 614 is_profiling_ = false; |
619 isolate_->set_is_profiling(false); | 615 isolate_->set_is_profiling(false); |
620 processor_->StopSynchronously(); | 616 processor_->StopSynchronously(); |
621 delete processor_; | 617 processor_.reset(); |
622 delete generator_; | 618 generator_.reset(); |
623 processor_ = NULL; | |
624 generator_ = NULL; | |
625 sampler->SetHasProcessingThread(false); | 619 sampler->SetHasProcessingThread(false); |
626 sampler->DecreaseProfilingDepth(); | 620 sampler->DecreaseProfilingDepth(); |
627 logger->is_logging_ = saved_is_logging_; | 621 logger->is_logging_ = saved_is_logging_; |
628 } | 622 } |
629 | 623 |
630 | 624 |
631 void CpuProfiler::LogBuiltins() { | 625 void CpuProfiler::LogBuiltins() { |
632 Builtins* builtins = isolate_->builtins(); | 626 Builtins* builtins = isolate_->builtins(); |
633 DCHECK(builtins->is_initialized()); | 627 DCHECK(builtins->is_initialized()); |
634 for (int i = 0; i < Builtins::builtin_count; i++) { | 628 for (int i = 0; i < Builtins::builtin_count; i++) { |
635 CodeEventsContainer evt_rec(CodeEventRecord::REPORT_BUILTIN); | 629 CodeEventsContainer evt_rec(CodeEventRecord::REPORT_BUILTIN); |
636 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_; | 630 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_; |
637 Builtins::Name id = static_cast<Builtins::Name>(i); | 631 Builtins::Name id = static_cast<Builtins::Name>(i); |
638 rec->start = builtins->builtin(id)->address(); | 632 rec->start = builtins->builtin(id)->address(); |
639 rec->builtin_id = id; | 633 rec->builtin_id = id; |
640 processor_->Enqueue(evt_rec); | 634 processor_->Enqueue(evt_rec); |
641 } | 635 } |
642 } | 636 } |
643 | 637 |
644 | 638 |
645 } // namespace internal | 639 } // namespace internal |
646 } // namespace v8 | 640 } // namespace v8 |
OLD | NEW |