OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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/sampler.h" | 5 #include "src/sampler.h" |
6 | 6 |
7 #if V8_OS_POSIX && !V8_OS_CYGWIN | 7 #if V8_OS_POSIX && !V8_OS_CYGWIN |
8 | 8 |
9 #define USE_SIGNALS | 9 #define USE_SIGNALS |
10 | 10 |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 static void AddActiveSampler(Sampler* sampler) { | 497 static void AddActiveSampler(Sampler* sampler) { |
498 bool need_to_start = false; | 498 bool need_to_start = false; |
499 base::LockGuard<base::Mutex> lock_guard(mutex_); | 499 base::LockGuard<base::Mutex> lock_guard(mutex_); |
500 if (instance_ == NULL) { | 500 if (instance_ == NULL) { |
501 // Start a thread that will send SIGPROF signal to VM threads, | 501 // Start a thread that will send SIGPROF signal to VM threads, |
502 // when CPU profiling will be enabled. | 502 // when CPU profiling will be enabled. |
503 instance_ = new SamplerThread(sampler->interval()); | 503 instance_ = new SamplerThread(sampler->interval()); |
504 need_to_start = true; | 504 need_to_start = true; |
505 } | 505 } |
506 | 506 |
507 ASSERT(sampler->IsActive()); | 507 DCHECK(sampler->IsActive()); |
508 ASSERT(!instance_->active_samplers_.Contains(sampler)); | 508 DCHECK(!instance_->active_samplers_.Contains(sampler)); |
509 ASSERT(instance_->interval_ == sampler->interval()); | 509 DCHECK(instance_->interval_ == sampler->interval()); |
510 instance_->active_samplers_.Add(sampler); | 510 instance_->active_samplers_.Add(sampler); |
511 | 511 |
512 if (need_to_start) instance_->StartSynchronously(); | 512 if (need_to_start) instance_->StartSynchronously(); |
513 } | 513 } |
514 | 514 |
515 static void RemoveActiveSampler(Sampler* sampler) { | 515 static void RemoveActiveSampler(Sampler* sampler) { |
516 SamplerThread* instance_to_remove = NULL; | 516 SamplerThread* instance_to_remove = NULL; |
517 { | 517 { |
518 base::LockGuard<base::Mutex> lock_guard(mutex_); | 518 base::LockGuard<base::Mutex> lock_guard(mutex_); |
519 | 519 |
520 ASSERT(sampler->IsActive()); | 520 DCHECK(sampler->IsActive()); |
521 bool removed = instance_->active_samplers_.RemoveElement(sampler); | 521 bool removed = instance_->active_samplers_.RemoveElement(sampler); |
522 ASSERT(removed); | 522 DCHECK(removed); |
523 USE(removed); | 523 USE(removed); |
524 | 524 |
525 // We cannot delete the instance immediately as we need to Join() the | 525 // We cannot delete the instance immediately as we need to Join() the |
526 // thread but we are holding mutex_ and the thread may try to acquire it. | 526 // thread but we are holding mutex_ and the thread may try to acquire it. |
527 if (instance_->active_samplers_.is_empty()) { | 527 if (instance_->active_samplers_.is_empty()) { |
528 instance_to_remove = instance_; | 528 instance_to_remove = instance_; |
529 instance_ = NULL; | 529 instance_ = NULL; |
530 } | 530 } |
531 } | 531 } |
532 | 532 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 | 568 |
569 base::Mutex* SamplerThread::mutex_ = NULL; | 569 base::Mutex* SamplerThread::mutex_ = NULL; |
570 SamplerThread* SamplerThread::instance_ = NULL; | 570 SamplerThread* SamplerThread::instance_ = NULL; |
571 | 571 |
572 | 572 |
573 // | 573 // |
574 // StackTracer implementation | 574 // StackTracer implementation |
575 // | 575 // |
576 DISABLE_ASAN void TickSample::Init(Isolate* isolate, | 576 DISABLE_ASAN void TickSample::Init(Isolate* isolate, |
577 const RegisterState& regs) { | 577 const RegisterState& regs) { |
578 ASSERT(isolate->IsInitialized()); | 578 DCHECK(isolate->IsInitialized()); |
579 timestamp = base::TimeTicks::HighResolutionNow(); | 579 timestamp = base::TimeTicks::HighResolutionNow(); |
580 pc = regs.pc; | 580 pc = regs.pc; |
581 state = isolate->current_vm_state(); | 581 state = isolate->current_vm_state(); |
582 | 582 |
583 // Avoid collecting traces while doing GC. | 583 // Avoid collecting traces while doing GC. |
584 if (state == GC) return; | 584 if (state == GC) return; |
585 | 585 |
586 Address js_entry_sp = isolate->js_entry_sp(); | 586 Address js_entry_sp = isolate->js_entry_sp(); |
587 if (js_entry_sp == 0) { | 587 if (js_entry_sp == 0) { |
588 // Not executing JS now. | 588 // Not executing JS now. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 profiling_(false), | 637 profiling_(false), |
638 has_processing_thread_(false), | 638 has_processing_thread_(false), |
639 active_(false), | 639 active_(false), |
640 is_counting_samples_(false), | 640 is_counting_samples_(false), |
641 js_and_external_sample_count_(0) { | 641 js_and_external_sample_count_(0) { |
642 data_ = new PlatformData; | 642 data_ = new PlatformData; |
643 } | 643 } |
644 | 644 |
645 | 645 |
646 Sampler::~Sampler() { | 646 Sampler::~Sampler() { |
647 ASSERT(!IsActive()); | 647 DCHECK(!IsActive()); |
648 delete data_; | 648 delete data_; |
649 } | 649 } |
650 | 650 |
651 | 651 |
652 void Sampler::Start() { | 652 void Sampler::Start() { |
653 ASSERT(!IsActive()); | 653 DCHECK(!IsActive()); |
654 SetActive(true); | 654 SetActive(true); |
655 SamplerThread::AddActiveSampler(this); | 655 SamplerThread::AddActiveSampler(this); |
656 } | 656 } |
657 | 657 |
658 | 658 |
659 void Sampler::Stop() { | 659 void Sampler::Stop() { |
660 ASSERT(IsActive()); | 660 DCHECK(IsActive()); |
661 SamplerThread::RemoveActiveSampler(this); | 661 SamplerThread::RemoveActiveSampler(this); |
662 SetActive(false); | 662 SetActive(false); |
663 } | 663 } |
664 | 664 |
665 | 665 |
666 void Sampler::IncreaseProfilingDepth() { | 666 void Sampler::IncreaseProfilingDepth() { |
667 base::NoBarrier_AtomicIncrement(&profiling_, 1); | 667 base::NoBarrier_AtomicIncrement(&profiling_, 1); |
668 #if defined(USE_SIGNALS) | 668 #if defined(USE_SIGNALS) |
669 SignalHandler::IncreaseSamplerCount(); | 669 SignalHandler::IncreaseSamplerCount(); |
670 #endif | 670 #endif |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 #endif // USE_SIMULATOR | 738 #endif // USE_SIMULATOR |
739 SampleStack(state); | 739 SampleStack(state); |
740 } | 740 } |
741 ResumeThread(profiled_thread); | 741 ResumeThread(profiled_thread); |
742 } | 742 } |
743 | 743 |
744 #endif // USE_SIGNALS | 744 #endif // USE_SIGNALS |
745 | 745 |
746 | 746 |
747 } } // namespace v8::internal | 747 } } // namespace v8::internal |
OLD | NEW |