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 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 delete instance_; | 780 delete instance_; |
781 instance_ = NULL; | 781 instance_ = NULL; |
782 } | 782 } |
783 } | 783 } |
784 | 784 |
785 // Implement Thread::Run(). | 785 // Implement Thread::Run(). |
786 virtual void Run() { | 786 virtual void Run() { |
787 SamplerRegistry::State state; | 787 SamplerRegistry::State state; |
788 while ((state = SamplerRegistry::GetState()) != | 788 while ((state = SamplerRegistry::GetState()) != |
789 SamplerRegistry::HAS_NO_SAMPLERS) { | 789 SamplerRegistry::HAS_NO_SAMPLERS) { |
790 bool cpu_profiling_enabled = | |
791 (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS); | |
792 bool runtime_profiler_enabled = RuntimeProfiler::IsEnabled(); | |
793 // When CPU profiling is enabled both JavaScript and C++ code is | 790 // When CPU profiling is enabled both JavaScript and C++ code is |
794 // profiled. We must not suspend. | 791 // profiled. We must not suspend. |
795 if (!cpu_profiling_enabled) { | 792 if (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS) { |
| 793 SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this); |
| 794 } else { |
796 if (rate_limiter_.SuspendIfNecessary()) continue; | 795 if (rate_limiter_.SuspendIfNecessary()) continue; |
797 } | 796 } |
798 if (cpu_profiling_enabled) { | |
799 if (!SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this)) { | |
800 return; | |
801 } | |
802 } | |
803 if (runtime_profiler_enabled) { | |
804 if (!SamplerRegistry::IterateActiveSamplers(&DoRuntimeProfile, NULL)) { | |
805 return; | |
806 } | |
807 } | |
808 OS::Sleep(interval_); | 797 OS::Sleep(interval_); |
809 } | 798 } |
810 } | 799 } |
811 | 800 |
812 static void DoCpuProfile(Sampler* sampler, void* raw_sampler_thread) { | 801 static void DoCpuProfile(Sampler* sampler, void* raw_sampler_thread) { |
813 if (!sampler->isolate()->IsInitialized()) return; | 802 if (!sampler->isolate()->IsInitialized()) return; |
814 if (!sampler->IsProfiling()) return; | 803 if (!sampler->IsProfiling()) return; |
815 SamplerThread* sampler_thread = | 804 SamplerThread* sampler_thread = |
816 reinterpret_cast<SamplerThread*>(raw_sampler_thread); | 805 reinterpret_cast<SamplerThread*>(raw_sampler_thread); |
817 sampler_thread->SampleContext(sampler); | 806 sampler_thread->SampleContext(sampler); |
818 } | 807 } |
819 | 808 |
820 static void DoRuntimeProfile(Sampler* sampler, void* ignored) { | |
821 if (!sampler->isolate()->IsInitialized()) return; | |
822 sampler->isolate()->runtime_profiler()->NotifyTick(); | |
823 } | |
824 | |
825 void SampleContext(Sampler* sampler) { | 809 void SampleContext(Sampler* sampler) { |
826 thread_act_t profiled_thread = sampler->platform_data()->profiled_thread(); | 810 thread_act_t profiled_thread = sampler->platform_data()->profiled_thread(); |
827 TickSample sample_obj; | 811 TickSample sample_obj; |
828 TickSample* sample = CpuProfiler::TickSampleEvent(sampler->isolate()); | 812 TickSample* sample = CpuProfiler::TickSampleEvent(sampler->isolate()); |
829 if (sample == NULL) sample = &sample_obj; | 813 if (sample == NULL) sample = &sample_obj; |
830 | 814 |
831 if (KERN_SUCCESS != thread_suspend(profiled_thread)) return; | 815 if (KERN_SUCCESS != thread_suspend(profiled_thread)) return; |
832 | 816 |
833 #if V8_HOST_ARCH_X64 | 817 #if V8_HOST_ARCH_X64 |
834 thread_state_flavor_t flavor = x86_THREAD_STATE64; | 818 thread_state_flavor_t flavor = x86_THREAD_STATE64; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 | 907 |
924 | 908 |
925 void Sampler::Stop() { | 909 void Sampler::Stop() { |
926 ASSERT(IsActive()); | 910 ASSERT(IsActive()); |
927 SamplerThread::RemoveActiveSampler(this); | 911 SamplerThread::RemoveActiveSampler(this); |
928 SetActive(false); | 912 SetActive(false); |
929 } | 913 } |
930 | 914 |
931 | 915 |
932 } } // namespace v8::internal | 916 } } // namespace v8::internal |
OLD | NEW |