| 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 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 | 621 |
| 622 class SamplerThread : public Thread { | 622 class SamplerThread : public Thread { |
| 623 public: | 623 public: |
| 624 static const int kSamplerThreadStackSize = 64 * KB; | 624 static const int kSamplerThreadStackSize = 64 * KB; |
| 625 | 625 |
| 626 explicit SamplerThread(int interval) | 626 explicit SamplerThread(int interval) |
| 627 : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)), | 627 : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)), |
| 628 interval_(interval) {} | 628 interval_(interval) {} |
| 629 | 629 |
| 630 static void AddActiveSampler(Sampler* sampler) { | 630 static void AddActiveSampler(Sampler* sampler) { |
| 631 ScopedLock lock(mutex_); | 631 ScopedLock lock(mutex_.Pointer()); |
| 632 SamplerRegistry::AddActiveSampler(sampler); | 632 SamplerRegistry::AddActiveSampler(sampler); |
| 633 if (instance_ == NULL) { | 633 if (instance_ == NULL) { |
| 634 instance_ = new SamplerThread(sampler->interval()); | 634 instance_ = new SamplerThread(sampler->interval()); |
| 635 instance_->Start(); | 635 instance_->Start(); |
| 636 } else { | 636 } else { |
| 637 ASSERT(instance_->interval_ == sampler->interval()); | 637 ASSERT(instance_->interval_ == sampler->interval()); |
| 638 } | 638 } |
| 639 } | 639 } |
| 640 | 640 |
| 641 static void RemoveActiveSampler(Sampler* sampler) { | 641 static void RemoveActiveSampler(Sampler* sampler) { |
| 642 ScopedLock lock(mutex_); | 642 ScopedLock lock(mutex_.Pointer()); |
| 643 SamplerRegistry::RemoveActiveSampler(sampler); | 643 SamplerRegistry::RemoveActiveSampler(sampler); |
| 644 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { | 644 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { |
| 645 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); | 645 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); |
| 646 delete instance_; | 646 delete instance_; |
| 647 instance_ = NULL; | 647 instance_ = NULL; |
| 648 } | 648 } |
| 649 } | 649 } |
| 650 | 650 |
| 651 // Implement Thread::Run(). | 651 // Implement Thread::Run(). |
| 652 virtual void Run() { | 652 virtual void Run() { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 sampler->SampleStack(sample); | 718 sampler->SampleStack(sample); |
| 719 sampler->Tick(sample); | 719 sampler->Tick(sample); |
| 720 } | 720 } |
| 721 ResumeThread(profiled_thread); | 721 ResumeThread(profiled_thread); |
| 722 } | 722 } |
| 723 | 723 |
| 724 const int interval_; | 724 const int interval_; |
| 725 RuntimeProfilerRateLimiter rate_limiter_; | 725 RuntimeProfilerRateLimiter rate_limiter_; |
| 726 | 726 |
| 727 // Protects the process wide state below. | 727 // Protects the process wide state below. |
| 728 static Mutex* mutex_; | 728 static LazyMutex mutex_; |
| 729 static SamplerThread* instance_; | 729 static SamplerThread* instance_; |
| 730 | 730 |
| 731 private: | 731 private: |
| 732 DISALLOW_COPY_AND_ASSIGN(SamplerThread); | 732 DISALLOW_COPY_AND_ASSIGN(SamplerThread); |
| 733 }; | 733 }; |
| 734 | 734 |
| 735 | 735 |
| 736 Mutex* SamplerThread::mutex_ = OS::CreateMutex(); | 736 LazyMutex SamplerThread::mutex_ = LAZY_MUTEX_INITIALIZER; |
| 737 SamplerThread* SamplerThread::instance_ = NULL; | 737 SamplerThread* SamplerThread::instance_ = NULL; |
| 738 | 738 |
| 739 | 739 |
| 740 Sampler::Sampler(Isolate* isolate, int interval) | 740 Sampler::Sampler(Isolate* isolate, int interval) |
| 741 : isolate_(isolate), | 741 : isolate_(isolate), |
| 742 interval_(interval), | 742 interval_(interval), |
| 743 profiling_(false), | 743 profiling_(false), |
| 744 active_(false), | 744 active_(false), |
| 745 samples_taken_(0) { | 745 samples_taken_(0) { |
| 746 data_ = new PlatformData; | 746 data_ = new PlatformData; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 761 | 761 |
| 762 | 762 |
| 763 void Sampler::Stop() { | 763 void Sampler::Stop() { |
| 764 ASSERT(IsActive()); | 764 ASSERT(IsActive()); |
| 765 SamplerThread::RemoveActiveSampler(this); | 765 SamplerThread::RemoveActiveSampler(this); |
| 766 SetActive(false); | 766 SetActive(false); |
| 767 } | 767 } |
| 768 | 768 |
| 769 | 769 |
| 770 } } // namespace v8::internal | 770 } } // namespace v8::internal |
| OLD | NEW |