| 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 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 sample->sp = reinterpret_cast<Address>(mcontext.mc_r13); | 705 sample->sp = reinterpret_cast<Address>(mcontext.mc_r13); |
| 706 sample->fp = reinterpret_cast<Address>(mcontext.mc_r11); | 706 sample->fp = reinterpret_cast<Address>(mcontext.mc_r11); |
| 707 #endif | 707 #endif |
| 708 sampler->SampleStack(sample); | 708 sampler->SampleStack(sample); |
| 709 sampler->Tick(sample); | 709 sampler->Tick(sample); |
| 710 } | 710 } |
| 711 | 711 |
| 712 | 712 |
| 713 class SignalSender : public Thread { | 713 class SignalSender : public Thread { |
| 714 public: | 714 public: |
| 715 enum SleepInterval { | |
| 716 HALF_INTERVAL, | |
| 717 FULL_INTERVAL | |
| 718 }; | |
| 719 | |
| 720 static const int kSignalSenderStackSize = 64 * KB; | 715 static const int kSignalSenderStackSize = 64 * KB; |
| 721 | 716 |
| 722 explicit SignalSender(int interval) | 717 explicit SignalSender(int interval) |
| 723 : Thread(Thread::Options("SignalSender", kSignalSenderStackSize)), | 718 : Thread(Thread::Options("SignalSender", kSignalSenderStackSize)), |
| 724 interval_(interval) {} | 719 interval_(interval) {} |
| 725 | 720 |
| 726 static void SetUp() { if (!mutex_) mutex_ = OS::CreateMutex(); } | 721 static void SetUp() { if (!mutex_) mutex_ = OS::CreateMutex(); } |
| 727 static void TearDown() { delete mutex_; } | 722 static void TearDown() { delete mutex_; } |
| 728 | 723 |
| 729 static void AddActiveSampler(Sampler* sampler) { | 724 static void AddActiveSampler(Sampler* sampler) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 760 signal_handler_installed_ = false; | 755 signal_handler_installed_ = false; |
| 761 } | 756 } |
| 762 } | 757 } |
| 763 } | 758 } |
| 764 | 759 |
| 765 // Implement Thread::Run(). | 760 // Implement Thread::Run(). |
| 766 virtual void Run() { | 761 virtual void Run() { |
| 767 SamplerRegistry::State state; | 762 SamplerRegistry::State state; |
| 768 while ((state = SamplerRegistry::GetState()) != | 763 while ((state = SamplerRegistry::GetState()) != |
| 769 SamplerRegistry::HAS_NO_SAMPLERS) { | 764 SamplerRegistry::HAS_NO_SAMPLERS) { |
| 770 bool cpu_profiling_enabled = | |
| 771 (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS); | |
| 772 bool runtime_profiler_enabled = RuntimeProfiler::IsEnabled(); | |
| 773 // When CPU profiling is enabled both JavaScript and C++ code is | 765 // When CPU profiling is enabled both JavaScript and C++ code is |
| 774 // profiled. We must not suspend. | 766 // profiled. We must not suspend. |
| 775 if (!cpu_profiling_enabled) { | 767 if (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS) { |
| 768 SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this); |
| 769 } else { |
| 776 if (rate_limiter_.SuspendIfNecessary()) continue; | 770 if (rate_limiter_.SuspendIfNecessary()) continue; |
| 777 } | 771 } |
| 778 if (cpu_profiling_enabled && runtime_profiler_enabled) { | 772 Sleep(); // TODO(svenpanne) Figure out if OS:Sleep(interval_) is enough. |
| 779 if (!SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this)) { | |
| 780 return; | |
| 781 } | |
| 782 Sleep(HALF_INTERVAL); | |
| 783 if (!SamplerRegistry::IterateActiveSamplers(&DoRuntimeProfile, NULL)) { | |
| 784 return; | |
| 785 } | |
| 786 Sleep(HALF_INTERVAL); | |
| 787 } else { | |
| 788 if (cpu_profiling_enabled) { | |
| 789 if (!SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, | |
| 790 this)) { | |
| 791 return; | |
| 792 } | |
| 793 } | |
| 794 if (runtime_profiler_enabled) { | |
| 795 if (!SamplerRegistry::IterateActiveSamplers(&DoRuntimeProfile, | |
| 796 NULL)) { | |
| 797 return; | |
| 798 } | |
| 799 } | |
| 800 Sleep(FULL_INTERVAL); | |
| 801 } | |
| 802 } | 773 } |
| 803 } | 774 } |
| 804 | 775 |
| 805 static void DoCpuProfile(Sampler* sampler, void* raw_sender) { | 776 static void DoCpuProfile(Sampler* sampler, void* raw_sender) { |
| 806 if (!sampler->IsProfiling()) return; | 777 if (!sampler->IsProfiling()) return; |
| 807 SignalSender* sender = reinterpret_cast<SignalSender*>(raw_sender); | 778 SignalSender* sender = reinterpret_cast<SignalSender*>(raw_sender); |
| 808 sender->SendProfilingSignal(sampler->platform_data()->vm_tid()); | 779 sender->SendProfilingSignal(sampler->platform_data()->vm_tid()); |
| 809 } | 780 } |
| 810 | 781 |
| 811 static void DoRuntimeProfile(Sampler* sampler, void* ignored) { | |
| 812 if (!sampler->isolate()->IsInitialized()) return; | |
| 813 sampler->isolate()->runtime_profiler()->NotifyTick(); | |
| 814 } | |
| 815 | |
| 816 void SendProfilingSignal(pthread_t tid) { | 782 void SendProfilingSignal(pthread_t tid) { |
| 817 if (!signal_handler_installed_) return; | 783 if (!signal_handler_installed_) return; |
| 818 pthread_kill(tid, SIGPROF); | 784 pthread_kill(tid, SIGPROF); |
| 819 } | 785 } |
| 820 | 786 |
| 821 void Sleep(SleepInterval full_or_half) { | 787 void Sleep() { |
| 822 // Convert ms to us and subtract 100 us to compensate delays | 788 // Convert ms to us and subtract 100 us to compensate delays |
| 823 // occuring during signal delivery. | 789 // occuring during signal delivery. |
| 824 useconds_t interval = interval_ * 1000 - 100; | 790 useconds_t interval = interval_ * 1000 - 100; |
| 825 if (full_or_half == HALF_INTERVAL) interval /= 2; | |
| 826 int result = usleep(interval); | 791 int result = usleep(interval); |
| 827 #ifdef DEBUG | 792 #ifdef DEBUG |
| 828 if (result != 0 && errno != EINTR) { | 793 if (result != 0 && errno != EINTR) { |
| 829 fprintf(stderr, | 794 fprintf(stderr, |
| 830 "SignalSender usleep error; interval = %u, errno = %d\n", | 795 "SignalSender usleep error; interval = %u, errno = %d\n", |
| 831 interval, | 796 interval, |
| 832 errno); | 797 errno); |
| 833 ASSERT(result == 0 || errno == EINTR); | 798 ASSERT(result == 0 || errno == EINTR); |
| 834 } | 799 } |
| 835 #endif | 800 #endif |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 | 863 |
| 899 | 864 |
| 900 void Sampler::Stop() { | 865 void Sampler::Stop() { |
| 901 ASSERT(IsActive()); | 866 ASSERT(IsActive()); |
| 902 SignalSender::RemoveActiveSampler(this); | 867 SignalSender::RemoveActiveSampler(this); |
| 903 SetActive(false); | 868 SetActive(false); |
| 904 } | 869 } |
| 905 | 870 |
| 906 | 871 |
| 907 } } // namespace v8::internal | 872 } } // namespace v8::internal |
| OLD | NEW |