| 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 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 | 610 |
| 611 class SamplerThread : public Thread { | 611 class SamplerThread : public Thread { |
| 612 public: | 612 public: |
| 613 static const int kSamplerThreadStackSize = 64 * KB; | 613 static const int kSamplerThreadStackSize = 64 * KB; |
| 614 | 614 |
| 615 explicit SamplerThread(int interval) | 615 explicit SamplerThread(int interval) |
| 616 : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)), | 616 : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)), |
| 617 interval_(interval) {} | 617 interval_(interval) {} |
| 618 | 618 |
| 619 static void AddActiveSampler(Sampler* sampler) { | 619 static void AddActiveSampler(Sampler* sampler) { |
| 620 ScopedLock lock(mutex_); | 620 ScopedLock lock(mutex_.Pointer()); |
| 621 SamplerRegistry::AddActiveSampler(sampler); | 621 SamplerRegistry::AddActiveSampler(sampler); |
| 622 if (instance_ == NULL) { | 622 if (instance_ == NULL) { |
| 623 instance_ = new SamplerThread(sampler->interval()); | 623 instance_ = new SamplerThread(sampler->interval()); |
| 624 instance_->Start(); | 624 instance_->Start(); |
| 625 } else { | 625 } else { |
| 626 ASSERT(instance_->interval_ == sampler->interval()); | 626 ASSERT(instance_->interval_ == sampler->interval()); |
| 627 } | 627 } |
| 628 } | 628 } |
| 629 | 629 |
| 630 static void RemoveActiveSampler(Sampler* sampler) { | 630 static void RemoveActiveSampler(Sampler* sampler) { |
| 631 ScopedLock lock(mutex_); | 631 ScopedLock lock(mutex_.Pointer()); |
| 632 SamplerRegistry::RemoveActiveSampler(sampler); | 632 SamplerRegistry::RemoveActiveSampler(sampler); |
| 633 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { | 633 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { |
| 634 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); | 634 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); |
| 635 delete instance_; | 635 delete instance_; |
| 636 instance_ = NULL; | 636 instance_ = NULL; |
| 637 } | 637 } |
| 638 } | 638 } |
| 639 | 639 |
| 640 // Implement Thread::Run(). | 640 // Implement Thread::Run(). |
| 641 virtual void Run() { | 641 virtual void Run() { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 sampler->SampleStack(sample); | 707 sampler->SampleStack(sample); |
| 708 sampler->Tick(sample); | 708 sampler->Tick(sample); |
| 709 } | 709 } |
| 710 ResumeThread(profiled_thread); | 710 ResumeThread(profiled_thread); |
| 711 } | 711 } |
| 712 | 712 |
| 713 const int interval_; | 713 const int interval_; |
| 714 RuntimeProfilerRateLimiter rate_limiter_; | 714 RuntimeProfilerRateLimiter rate_limiter_; |
| 715 | 715 |
| 716 // Protects the process wide state below. | 716 // Protects the process wide state below. |
| 717 static Mutex* mutex_; | 717 static LazyMutex mutex_; |
| 718 static SamplerThread* instance_; | 718 static SamplerThread* instance_; |
| 719 | 719 |
| 720 private: | 720 private: |
| 721 DISALLOW_COPY_AND_ASSIGN(SamplerThread); | 721 DISALLOW_COPY_AND_ASSIGN(SamplerThread); |
| 722 }; | 722 }; |
| 723 | 723 |
| 724 | 724 |
| 725 Mutex* SamplerThread::mutex_ = OS::CreateMutex(); | 725 LazyMutex SamplerThread::mutex_ = LAZY_MUTEX_INITIALIZER; |
| 726 SamplerThread* SamplerThread::instance_ = NULL; | 726 SamplerThread* SamplerThread::instance_ = NULL; |
| 727 | 727 |
| 728 | 728 |
| 729 Sampler::Sampler(Isolate* isolate, int interval) | 729 Sampler::Sampler(Isolate* isolate, int interval) |
| 730 : isolate_(isolate), | 730 : isolate_(isolate), |
| 731 interval_(interval), | 731 interval_(interval), |
| 732 profiling_(false), | 732 profiling_(false), |
| 733 active_(false), | 733 active_(false), |
| 734 samples_taken_(0) { | 734 samples_taken_(0) { |
| 735 data_ = new PlatformData; | 735 data_ = new PlatformData; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 750 | 750 |
| 751 | 751 |
| 752 void Sampler::Stop() { | 752 void Sampler::Stop() { |
| 753 ASSERT(IsActive()); | 753 ASSERT(IsActive()); |
| 754 SamplerThread::RemoveActiveSampler(this); | 754 SamplerThread::RemoveActiveSampler(this); |
| 755 SetActive(false); | 755 SetActive(false); |
| 756 } | 756 } |
| 757 | 757 |
| 758 | 758 |
| 759 } } // namespace v8::internal | 759 } } // namespace v8::internal |
| OLD | NEW |