| 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 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 | 733 |
| 734 class SamplerThread : public Thread { | 734 class SamplerThread : public Thread { |
| 735 public: | 735 public: |
| 736 static const int kSamplerThreadStackSize = 64 * KB; | 736 static const int kSamplerThreadStackSize = 64 * KB; |
| 737 | 737 |
| 738 explicit SamplerThread(int interval) | 738 explicit SamplerThread(int interval) |
| 739 : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)), | 739 : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)), |
| 740 interval_(interval) {} | 740 interval_(interval) {} |
| 741 | 741 |
| 742 static void AddActiveSampler(Sampler* sampler) { | 742 static void AddActiveSampler(Sampler* sampler) { |
| 743 ScopedLock lock(mutex_); | 743 ScopedLock lock(mutex_.Pointer()); |
| 744 SamplerRegistry::AddActiveSampler(sampler); | 744 SamplerRegistry::AddActiveSampler(sampler); |
| 745 if (instance_ == NULL) { | 745 if (instance_ == NULL) { |
| 746 instance_ = new SamplerThread(sampler->interval()); | 746 instance_ = new SamplerThread(sampler->interval()); |
| 747 instance_->Start(); | 747 instance_->Start(); |
| 748 } else { | 748 } else { |
| 749 ASSERT(instance_->interval_ == sampler->interval()); | 749 ASSERT(instance_->interval_ == sampler->interval()); |
| 750 } | 750 } |
| 751 } | 751 } |
| 752 | 752 |
| 753 static void RemoveActiveSampler(Sampler* sampler) { | 753 static void RemoveActiveSampler(Sampler* sampler) { |
| 754 ScopedLock lock(mutex_); | 754 ScopedLock lock(mutex_.Pointer()); |
| 755 SamplerRegistry::RemoveActiveSampler(sampler); | 755 SamplerRegistry::RemoveActiveSampler(sampler); |
| 756 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { | 756 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { |
| 757 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); | 757 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); |
| 758 delete instance_; | 758 delete instance_; |
| 759 instance_ = NULL; | 759 instance_ = NULL; |
| 760 } | 760 } |
| 761 } | 761 } |
| 762 | 762 |
| 763 // Implement Thread::Run(). | 763 // Implement Thread::Run(). |
| 764 virtual void Run() { | 764 virtual void Run() { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 sampler->SampleStack(sample); | 841 sampler->SampleStack(sample); |
| 842 sampler->Tick(sample); | 842 sampler->Tick(sample); |
| 843 } | 843 } |
| 844 thread_resume(profiled_thread); | 844 thread_resume(profiled_thread); |
| 845 } | 845 } |
| 846 | 846 |
| 847 const int interval_; | 847 const int interval_; |
| 848 RuntimeProfilerRateLimiter rate_limiter_; | 848 RuntimeProfilerRateLimiter rate_limiter_; |
| 849 | 849 |
| 850 // Protects the process wide state below. | 850 // Protects the process wide state below. |
| 851 static Mutex* mutex_; | 851 static LazyMutex mutex_; |
| 852 static SamplerThread* instance_; | 852 static SamplerThread* instance_; |
| 853 | 853 |
| 854 private: | 854 private: |
| 855 DISALLOW_COPY_AND_ASSIGN(SamplerThread); | 855 DISALLOW_COPY_AND_ASSIGN(SamplerThread); |
| 856 }; | 856 }; |
| 857 | 857 |
| 858 #undef REGISTER_FIELD | 858 #undef REGISTER_FIELD |
| 859 | 859 |
| 860 | 860 |
| 861 Mutex* SamplerThread::mutex_ = OS::CreateMutex(); | 861 LazyMutex SamplerThread::mutex_ = LAZY_MUTEX_INITIALIZER; |
| 862 SamplerThread* SamplerThread::instance_ = NULL; | 862 SamplerThread* SamplerThread::instance_ = NULL; |
| 863 | 863 |
| 864 | 864 |
| 865 Sampler::Sampler(Isolate* isolate, int interval) | 865 Sampler::Sampler(Isolate* isolate, int interval) |
| 866 : isolate_(isolate), | 866 : isolate_(isolate), |
| 867 interval_(interval), | 867 interval_(interval), |
| 868 profiling_(false), | 868 profiling_(false), |
| 869 active_(false), | 869 active_(false), |
| 870 samples_taken_(0) { | 870 samples_taken_(0) { |
| 871 data_ = new PlatformData; | 871 data_ = new PlatformData; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 886 | 886 |
| 887 | 887 |
| 888 void Sampler::Stop() { | 888 void Sampler::Stop() { |
| 889 ASSERT(IsActive()); | 889 ASSERT(IsActive()); |
| 890 SamplerThread::RemoveActiveSampler(this); | 890 SamplerThread::RemoveActiveSampler(this); |
| 891 SetActive(false); | 891 SetActive(false); |
| 892 } | 892 } |
| 893 | 893 |
| 894 | 894 |
| 895 } } // namespace v8::internal | 895 } } // namespace v8::internal |
| OLD | NEW |