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 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 delete instance_; | 648 delete instance_; |
649 instance_ = NULL; | 649 instance_ = NULL; |
650 } | 650 } |
651 } | 651 } |
652 | 652 |
653 // Implement Thread::Run(). | 653 // Implement Thread::Run(). |
654 virtual void Run() { | 654 virtual void Run() { |
655 SamplerRegistry::State state; | 655 SamplerRegistry::State state; |
656 while ((state = SamplerRegistry::GetState()) != | 656 while ((state = SamplerRegistry::GetState()) != |
657 SamplerRegistry::HAS_NO_SAMPLERS) { | 657 SamplerRegistry::HAS_NO_SAMPLERS) { |
658 bool cpu_profiling_enabled = | |
659 (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS); | |
660 bool runtime_profiler_enabled = RuntimeProfiler::IsEnabled(); | |
661 // When CPU profiling is enabled both JavaScript and C++ code is | 658 // When CPU profiling is enabled both JavaScript and C++ code is |
662 // profiled. We must not suspend. | 659 // profiled. We must not suspend. |
663 if (!cpu_profiling_enabled) { | 660 if (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS) { |
| 661 SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this); |
| 662 } else { |
664 if (rate_limiter_.SuspendIfNecessary()) continue; | 663 if (rate_limiter_.SuspendIfNecessary()) continue; |
665 } | 664 } |
666 if (cpu_profiling_enabled) { | |
667 if (!SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this)) { | |
668 return; | |
669 } | |
670 } | |
671 if (runtime_profiler_enabled) { | |
672 if (!SamplerRegistry::IterateActiveSamplers(&DoRuntimeProfile, NULL)) { | |
673 return; | |
674 } | |
675 } | |
676 OS::Sleep(interval_); | 665 OS::Sleep(interval_); |
677 } | 666 } |
678 } | 667 } |
679 | 668 |
680 static void DoCpuProfile(Sampler* sampler, void* raw_sampler_thread) { | 669 static void DoCpuProfile(Sampler* sampler, void* raw_sampler_thread) { |
681 if (!sampler->isolate()->IsInitialized()) return; | 670 if (!sampler->isolate()->IsInitialized()) return; |
682 if (!sampler->IsProfiling()) return; | 671 if (!sampler->IsProfiling()) return; |
683 SamplerThread* sampler_thread = | 672 SamplerThread* sampler_thread = |
684 reinterpret_cast<SamplerThread*>(raw_sampler_thread); | 673 reinterpret_cast<SamplerThread*>(raw_sampler_thread); |
685 sampler_thread->SampleContext(sampler); | 674 sampler_thread->SampleContext(sampler); |
686 } | 675 } |
687 | 676 |
688 static void DoRuntimeProfile(Sampler* sampler, void* ignored) { | |
689 if (!sampler->isolate()->IsInitialized()) return; | |
690 sampler->isolate()->runtime_profiler()->NotifyTick(); | |
691 } | |
692 | |
693 void SampleContext(Sampler* sampler) { | 677 void SampleContext(Sampler* sampler) { |
694 HANDLE profiled_thread = sampler->platform_data()->profiled_thread(); | 678 HANDLE profiled_thread = sampler->platform_data()->profiled_thread(); |
695 if (profiled_thread == NULL) return; | 679 if (profiled_thread == NULL) return; |
696 | 680 |
697 // Context used for sampling the register state of the profiled thread. | 681 // Context used for sampling the register state of the profiled thread. |
698 CONTEXT context; | 682 CONTEXT context; |
699 memset(&context, 0, sizeof(context)); | 683 memset(&context, 0, sizeof(context)); |
700 | 684 |
701 TickSample sample_obj; | 685 TickSample sample_obj; |
702 TickSample* sample = CpuProfiler::TickSampleEvent(sampler->isolate()); | 686 TickSample* sample = CpuProfiler::TickSampleEvent(sampler->isolate()); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 | 766 |
783 | 767 |
784 void Sampler::Stop() { | 768 void Sampler::Stop() { |
785 ASSERT(IsActive()); | 769 ASSERT(IsActive()); |
786 SamplerThread::RemoveActiveSampler(this); | 770 SamplerThread::RemoveActiveSampler(this); |
787 SetActive(false); | 771 SetActive(false); |
788 } | 772 } |
789 | 773 |
790 | 774 |
791 } } // namespace v8::internal | 775 } } // namespace v8::internal |
OLD | NEW |