| 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 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 } | 720 } |
| 721 | 721 |
| 722 static void RestoreSignalHandler() { | 722 static void RestoreSignalHandler() { |
| 723 if (signal_handler_installed_) { | 723 if (signal_handler_installed_) { |
| 724 sigaction(SIGPROF, &old_signal_handler_, 0); | 724 sigaction(SIGPROF, &old_signal_handler_, 0); |
| 725 signal_handler_installed_ = false; | 725 signal_handler_installed_ = false; |
| 726 } | 726 } |
| 727 } | 727 } |
| 728 | 728 |
| 729 static void AddActiveSampler(Sampler* sampler) { | 729 static void AddActiveSampler(Sampler* sampler) { |
| 730 ScopedLock lock(mutex_); | 730 ScopedLock lock(mutex_.Pointer()); |
| 731 SamplerRegistry::AddActiveSampler(sampler); | 731 SamplerRegistry::AddActiveSampler(sampler); |
| 732 if (instance_ == NULL) { | 732 if (instance_ == NULL) { |
| 733 // Start a thread that will send SIGPROF signal to VM threads, | 733 // Start a thread that will send SIGPROF signal to VM threads, |
| 734 // when CPU profiling will be enabled. | 734 // when CPU profiling will be enabled. |
| 735 instance_ = new SignalSender(sampler->interval()); | 735 instance_ = new SignalSender(sampler->interval()); |
| 736 instance_->Start(); | 736 instance_->Start(); |
| 737 } else { | 737 } else { |
| 738 ASSERT(instance_->interval_ == sampler->interval()); | 738 ASSERT(instance_->interval_ == sampler->interval()); |
| 739 } | 739 } |
| 740 } | 740 } |
| 741 | 741 |
| 742 static void RemoveActiveSampler(Sampler* sampler) { | 742 static void RemoveActiveSampler(Sampler* sampler) { |
| 743 ScopedLock lock(mutex_); | 743 ScopedLock lock(mutex_.Pointer()); |
| 744 SamplerRegistry::RemoveActiveSampler(sampler); | 744 SamplerRegistry::RemoveActiveSampler(sampler); |
| 745 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { | 745 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { |
| 746 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); | 746 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); |
| 747 delete instance_; | 747 delete instance_; |
| 748 instance_ = NULL; | 748 instance_ = NULL; |
| 749 RestoreSignalHandler(); | 749 RestoreSignalHandler(); |
| 750 } | 750 } |
| 751 } | 751 } |
| 752 | 752 |
| 753 // Implement Thread::Run(). | 753 // Implement Thread::Run(). |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 ASSERT(result == 0 || errno == EINTR); | 827 ASSERT(result == 0 || errno == EINTR); |
| 828 } | 828 } |
| 829 #endif | 829 #endif |
| 830 USE(result); | 830 USE(result); |
| 831 } | 831 } |
| 832 | 832 |
| 833 const int interval_; | 833 const int interval_; |
| 834 RuntimeProfilerRateLimiter rate_limiter_; | 834 RuntimeProfilerRateLimiter rate_limiter_; |
| 835 | 835 |
| 836 // Protects the process wide state below. | 836 // Protects the process wide state below. |
| 837 static Mutex* mutex_; | 837 static LazyMutex mutex_; |
| 838 static SignalSender* instance_; | 838 static SignalSender* instance_; |
| 839 static bool signal_handler_installed_; | 839 static bool signal_handler_installed_; |
| 840 static struct sigaction old_signal_handler_; | 840 static struct sigaction old_signal_handler_; |
| 841 | 841 |
| 842 private: | 842 private: |
| 843 DISALLOW_COPY_AND_ASSIGN(SignalSender); | 843 DISALLOW_COPY_AND_ASSIGN(SignalSender); |
| 844 }; | 844 }; |
| 845 | 845 |
| 846 Mutex* SignalSender::mutex_ = OS::CreateMutex(); | 846 LazyMutex SignalSender::mutex_ = LAZY_MUTEX_INITIALIZER; |
| 847 SignalSender* SignalSender::instance_ = NULL; | 847 SignalSender* SignalSender::instance_ = NULL; |
| 848 struct sigaction SignalSender::old_signal_handler_; | 848 struct sigaction SignalSender::old_signal_handler_; |
| 849 bool SignalSender::signal_handler_installed_ = false; | 849 bool SignalSender::signal_handler_installed_ = false; |
| 850 | 850 |
| 851 | 851 |
| 852 Sampler::Sampler(Isolate* isolate, int interval) | 852 Sampler::Sampler(Isolate* isolate, int interval) |
| 853 : isolate_(isolate), | 853 : isolate_(isolate), |
| 854 interval_(interval), | 854 interval_(interval), |
| 855 profiling_(false), | 855 profiling_(false), |
| 856 active_(false), | 856 active_(false), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 872 } | 872 } |
| 873 | 873 |
| 874 | 874 |
| 875 void Sampler::Stop() { | 875 void Sampler::Stop() { |
| 876 ASSERT(IsActive()); | 876 ASSERT(IsActive()); |
| 877 SignalSender::RemoveActiveSampler(this); | 877 SignalSender::RemoveActiveSampler(this); |
| 878 SetActive(false); | 878 SetActive(false); |
| 879 } | 879 } |
| 880 | 880 |
| 881 } } // namespace v8::internal | 881 } } // namespace v8::internal |
| OLD | NEW |