OLD | NEW |
---|---|
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/profiler/sampler.h" | 5 #include "src/profiler/sampler.h" |
6 | 6 |
7 #if V8_OS_POSIX && !V8_OS_CYGWIN | 7 #if V8_OS_POSIX && !V8_OS_CYGWIN |
8 | 8 |
9 #define USE_SIGNALS | 9 #define USE_SIGNALS |
10 | 10 |
(...skipping 24 matching lines...) Loading... | |
35 !defined(__BIONIC_HAVE_STRUCT_SIGCONTEXT) | 35 !defined(__BIONIC_HAVE_STRUCT_SIGCONTEXT) |
36 #include <asm/sigcontext.h> // NOLINT | 36 #include <asm/sigcontext.h> // NOLINT |
37 #endif | 37 #endif |
38 | 38 |
39 #elif V8_OS_WIN || V8_OS_CYGWIN | 39 #elif V8_OS_WIN || V8_OS_CYGWIN |
40 | 40 |
41 #include "src/base/win32-headers.h" | 41 #include "src/base/win32-headers.h" |
42 | 42 |
43 #endif | 43 #endif |
44 | 44 |
45 #include "src/atomic-utils.h" | |
45 #include "src/base/platform/platform.h" | 46 #include "src/base/platform/platform.h" |
46 #include "src/flags.h" | 47 #include "src/flags.h" |
47 #include "src/frames-inl.h" | 48 #include "src/frames-inl.h" |
48 #include "src/log.h" | 49 #include "src/log.h" |
49 #include "src/profiler/cpu-profiler-inl.h" | 50 #include "src/profiler/cpu-profiler-inl.h" |
50 #include "src/simulator.h" | 51 #include "src/simulator.h" |
51 #include "src/v8threads.h" | 52 #include "src/v8threads.h" |
52 #include "src/vm-state-inl.h" | 53 #include "src/vm-state-inl.h" |
53 | 54 |
54 | 55 |
(...skipping 174 matching lines...) Loading... | |
229 // pessimistically assume it could be the entire pattern match. | 230 // pessimistically assume it could be the entire pattern match. |
230 MSAN_MEMORY_IS_INITIALIZED(pc, pattern->bytes_count - offset); | 231 MSAN_MEMORY_IS_INITIALIZED(pc, pattern->bytes_count - offset); |
231 if (!memcmp(pc, pattern->bytes + offset, pattern->bytes_count - offset)) | 232 if (!memcmp(pc, pattern->bytes + offset, pattern->bytes_count - offset)) |
232 return true; | 233 return true; |
233 } | 234 } |
234 } | 235 } |
235 } | 236 } |
236 return false; | 237 return false; |
237 } | 238 } |
238 | 239 |
240 typedef List<Sampler*> SamplerList; | |
241 | |
242 #if defined(USE_SIGNALS) | |
243 class ThreadSamplersPair { | |
alph
2016/04/06 22:21:26
Is it possible to use std::pair?
lpy
2016/04/06 23:51:37
Done.
| |
244 public: | |
245 ThreadSamplersPair(pthread_t thread_id, SamplerList* samplers) | |
246 : thread_id_(thread_id), samplers_(samplers) {} | |
247 ~ThreadSamplersPair() { | |
248 delete samplers_; | |
249 } | |
250 pthread_t thread_id() const { return thread_id_; } | |
251 SamplerList* samplers() const { return samplers_; } | |
252 bool operator==(const ThreadSamplersPair& rhs) { | |
253 return thread_id_ == rhs.thread_id(); | |
254 } | |
255 private: | |
256 pthread_t thread_id_; | |
257 SamplerList* samplers_; | |
258 ThreadSamplersPair() {} | |
259 }; | |
260 | |
261 typedef List<ThreadSamplersPair*> ThreadSamplersList; | |
262 | |
263 template <typename T> | |
alph
2016/04/06 22:21:26
Why a template? Do you plan to use it elsewhere wi
lpy
2016/04/06 23:51:37
Done.
| |
264 class AtomicGuard { | |
265 public: | |
266 explicit AtomicGuard(AtomicValue<T>* atomic, T expected, T desired, | |
alph
2016/04/06 22:21:26
Drop explicit
Also, can you just hardcode expected
lpy
2016/04/06 23:51:37
I don't understand, what's the benefit to hard cod
alph
2016/04/07 00:40:10
It is always 0,1 at the call sites. So you use it
| |
267 bool is_block) | |
268 : atomic_(atomic), | |
269 expected_(expected), | |
270 desired_(desired), | |
271 is_success_(false) { | |
272 do { | |
273 is_success_ = atomic_->TrySetValue(expected, desired); | |
274 if (is_success_) break; | |
275 } while (is_block); | |
alph
2016/04/06 22:21:26
while (is_block && !is_success_)
lpy
2016/04/06 23:51:37
if is_block is set to false, then we only want to
alph
2016/04/07 00:40:10
the code I suggest is semantically equivalent to y
| |
276 } | |
277 | |
278 bool is_success() { return is_success_; } | |
279 | |
280 ~AtomicGuard() { | |
281 if (is_success_) | |
282 atomic_->SetValue(expected_); | |
alph
2016/04/06 22:21:25
v8 style requires block statement here
lpy
2016/04/06 23:51:37
Done.
| |
283 atomic_ = NULL; | |
284 } | |
285 | |
286 private: | |
287 AtomicValue<T>* atomic_; | |
288 T expected_; | |
289 T desired_; | |
alph
2016/04/06 22:21:25
not used
lpy
2016/04/06 23:51:37
Done.
| |
290 bool is_success_; | |
291 }; | |
292 #endif // USE_SIGNALS | |
293 | |
239 } // namespace | 294 } // namespace |
240 | 295 |
241 #if defined(USE_SIGNALS) | 296 #if defined(USE_SIGNALS) |
242 | 297 |
243 class Sampler::PlatformData : public PlatformDataCommon { | 298 class Sampler::PlatformData : public PlatformDataCommon { |
244 public: | 299 public: |
245 PlatformData() : vm_tid_(pthread_self()) {} | 300 PlatformData() : vm_tid_(pthread_self()) {} |
246 pthread_t vm_tid() const { return vm_tid_; } | 301 pthread_t vm_tid() const { return vm_tid_; } |
247 | 302 |
248 private: | 303 private: |
(...skipping 118 matching lines...) Loading... | |
367 | 422 |
368 static void DecreaseSamplerCount() { | 423 static void DecreaseSamplerCount() { |
369 base::LockGuard<base::Mutex> lock_guard(mutex_); | 424 base::LockGuard<base::Mutex> lock_guard(mutex_); |
370 if (--client_count_ == 0) Restore(); | 425 if (--client_count_ == 0) Restore(); |
371 } | 426 } |
372 | 427 |
373 static bool Installed() { | 428 static bool Installed() { |
374 return signal_handler_installed_; | 429 return signal_handler_installed_; |
375 } | 430 } |
376 | 431 |
432 #if !V8_OS_NACL | |
433 static void CollectSample(void* context, Sampler* sampler); | |
434 #endif | |
435 | |
377 private: | 436 private: |
378 static void Install() { | 437 static void Install() { |
379 #if !V8_OS_NACL | 438 #if !V8_OS_NACL |
380 struct sigaction sa; | 439 struct sigaction sa; |
381 sa.sa_sigaction = &HandleProfilerSignal; | 440 sa.sa_sigaction = &HandleProfilerSignal; |
382 sigemptyset(&sa.sa_mask); | 441 sigemptyset(&sa.sa_mask); |
383 #if V8_OS_QNX | 442 #if V8_OS_QNX |
384 sa.sa_flags = SA_SIGINFO; | 443 sa.sa_flags = SA_SIGINFO; |
385 #else | 444 #else |
386 sa.sa_flags = SA_RESTART | SA_SIGINFO; | 445 sa.sa_flags = SA_RESTART | SA_SIGINFO; |
(...skipping 24 matching lines...) Loading... | |
411 | 470 |
412 | 471 |
413 base::Mutex* SignalHandler::mutex_ = NULL; | 472 base::Mutex* SignalHandler::mutex_ = NULL; |
414 int SignalHandler::client_count_ = 0; | 473 int SignalHandler::client_count_ = 0; |
415 struct sigaction SignalHandler::old_signal_handler_; | 474 struct sigaction SignalHandler::old_signal_handler_; |
416 bool SignalHandler::signal_handler_installed_ = false; | 475 bool SignalHandler::signal_handler_installed_ = false; |
417 | 476 |
418 | 477 |
419 // As Native Client does not support signal handling, profiling is disabled. | 478 // As Native Client does not support signal handling, profiling is disabled. |
420 #if !V8_OS_NACL | 479 #if !V8_OS_NACL |
421 void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info, | 480 void SignalHandler::CollectSample(void* context, Sampler* sampler) { |
422 void* context) { | 481 if (sampler == NULL || (!sampler->IsProfiling() && !sampler->IsRegistered())) |
423 USE(info); | |
424 if (signal != SIGPROF) return; | |
425 Isolate* isolate = Isolate::UnsafeCurrent(); | |
426 if (isolate == NULL || !isolate->IsInUse()) { | |
427 // We require a fully initialized and entered isolate. | |
428 return; | 482 return; |
429 } | 483 Isolate* isolate = sampler->isolate(); |
484 | |
485 // We require a fully initialized and entered isolate. | |
486 if (isolate == NULL || !isolate->IsInUse()) return; | |
487 | |
430 if (v8::Locker::IsActive() && | 488 if (v8::Locker::IsActive() && |
431 !isolate->thread_manager()->IsLockedByCurrentThread()) { | 489 !isolate->thread_manager()->IsLockedByCurrentThread()) { |
432 return; | 490 return; |
433 } | 491 } |
434 | 492 |
435 Sampler* sampler = isolate->logger()->sampler(); | |
436 if (sampler == NULL) return; | |
437 | |
438 v8::RegisterState state; | 493 v8::RegisterState state; |
439 | 494 |
440 #if defined(USE_SIMULATOR) | 495 #if defined(USE_SIMULATOR) |
441 SimulatorHelper helper; | 496 SimulatorHelper helper; |
442 if (!helper.Init(isolate)) return; | 497 if (!helper.Init(isolate)) return; |
443 helper.FillRegisters(&state); | 498 helper.FillRegisters(&state); |
444 // It possible that the simulator is interrupted while it is updating | 499 // It possible that the simulator is interrupted while it is updating |
445 // the sp or fp register. ARM64 simulator does this in two steps: | 500 // the sp or fp register. ARM64 simulator does this in two steps: |
446 // first setting it to zero and then setting it to the new value. | 501 // first setting it to zero and then setting it to the new value. |
447 // Bailout if sp/fp doesn't contain the new value. | 502 // Bailout if sp/fp doesn't contain the new value. |
(...skipping 152 matching lines...) Loading... | |
600 bool need_to_start = false; | 655 bool need_to_start = false; |
601 base::LockGuard<base::Mutex> lock_guard(mutex_); | 656 base::LockGuard<base::Mutex> lock_guard(mutex_); |
602 if (instance_ == NULL) { | 657 if (instance_ == NULL) { |
603 // Start a thread that will send SIGPROF signal to VM threads, | 658 // Start a thread that will send SIGPROF signal to VM threads, |
604 // when CPU profiling will be enabled. | 659 // when CPU profiling will be enabled. |
605 instance_ = new SamplerThread(sampler->interval()); | 660 instance_ = new SamplerThread(sampler->interval()); |
606 need_to_start = true; | 661 need_to_start = true; |
607 } | 662 } |
608 | 663 |
609 DCHECK(sampler->IsActive()); | 664 DCHECK(sampler->IsActive()); |
665 DCHECK(instance_->interval_ == sampler->interval()); | |
666 | |
667 #if defined(USE_SIGNALS) | |
668 AddSampler(sampler); | |
669 #else | |
610 DCHECK(!instance_->active_samplers_.Contains(sampler)); | 670 DCHECK(!instance_->active_samplers_.Contains(sampler)); |
611 DCHECK(instance_->interval_ == sampler->interval()); | |
612 instance_->active_samplers_.Add(sampler); | 671 instance_->active_samplers_.Add(sampler); |
672 #endif // USE_SIGNALS | |
613 | 673 |
614 if (need_to_start) instance_->StartSynchronously(); | 674 if (need_to_start) instance_->StartSynchronously(); |
615 } | 675 } |
616 | 676 |
617 static void RemoveActiveSampler(Sampler* sampler) { | 677 static void RemoveSampler(Sampler* sampler) { |
618 SamplerThread* instance_to_remove = NULL; | 678 SamplerThread* instance_to_remove = NULL; |
619 { | 679 { |
620 base::LockGuard<base::Mutex> lock_guard(mutex_); | 680 base::LockGuard<base::Mutex> lock_guard(mutex_); |
621 | 681 |
622 DCHECK(sampler->IsActive()); | 682 DCHECK(sampler->IsActive() || sampler->IsRegistered()); |
683 #if defined(USE_SIGNALS) | |
684 { | |
685 AtomicGuard<int> atomic_guard(&sampler_list_access_counter_, | |
686 0, 1, true); | |
687 // Remove sampler from map. | |
688 pthread_t thread_id = sampler->platform_data()->vm_tid(); | |
689 SamplerList* samplers = NULL; | |
690 int i = 0; | |
691 for (; i < thread_id_to_samplers_.length(); ++i) { | |
692 ThreadSamplersPair* tsp = thread_id_to_samplers_.at(i); | |
693 if (pthread_equal(tsp->thread_id(), thread_id) != 0) { | |
694 samplers = tsp->samplers(); | |
695 break; | |
696 } | |
697 } | |
698 if (samplers != NULL) { | |
699 samplers->RemoveElement(sampler); | |
700 if (samplers->is_empty()) { | |
701 ThreadSamplersPair* tsp = thread_id_to_samplers_.Remove(i); | |
702 delete tsp; | |
703 } | |
704 } | |
705 if (thread_id_to_samplers_.is_empty()) { | |
706 instance_to_remove = instance_; | |
707 instance_ = NULL; | |
708 } | |
709 } | |
710 #else | |
623 bool removed = instance_->active_samplers_.RemoveElement(sampler); | 711 bool removed = instance_->active_samplers_.RemoveElement(sampler); |
624 DCHECK(removed); | 712 DCHECK(removed); |
625 USE(removed); | 713 USE(removed); |
626 | 714 |
627 // We cannot delete the instance immediately as we need to Join() the | 715 // We cannot delete the instance immediately as we need to Join() the |
628 // thread but we are holding mutex_ and the thread may try to acquire it. | 716 // thread but we are holding mutex_ and the thread may try to acquire it. |
629 if (instance_->active_samplers_.is_empty()) { | 717 if (instance_->active_samplers_.is_empty()) { |
630 instance_to_remove = instance_; | 718 instance_to_remove = instance_; |
631 instance_ = NULL; | 719 instance_ = NULL; |
632 } | 720 } |
721 #endif // USE_SIGNALS | |
633 } | 722 } |
634 | 723 |
635 if (!instance_to_remove) return; | 724 if (!instance_to_remove) return; |
636 instance_to_remove->Join(); | 725 instance_to_remove->Join(); |
637 delete instance_to_remove; | 726 delete instance_to_remove; |
638 } | 727 } |
639 | 728 |
729 // Unlike AddActiveSampler, this method only adds a sampler, | |
730 // but won't start the sampler thread. | |
731 static void RegisterSampler(Sampler* sampler) { | |
732 base::LockGuard<base::Mutex> lock_guard(mutex_); | |
733 #if defined(USE_SIGNALS) | |
734 AddSampler(sampler); | |
735 #endif // USE_SIGNALS | |
736 } | |
737 | |
640 // Implement Thread::Run(). | 738 // Implement Thread::Run(). |
641 virtual void Run() { | 739 virtual void Run() { |
642 while (true) { | 740 while (true) { |
643 { | 741 { |
644 base::LockGuard<base::Mutex> lock_guard(mutex_); | 742 base::LockGuard<base::Mutex> lock_guard(mutex_); |
743 #if defined(USE_SIGNALS) | |
744 if (thread_id_to_samplers_.is_empty()) break; | |
745 if (SignalHandler::Installed()) { | |
746 for (int i = 0; i < thread_id_to_samplers_.length(); ++i) { | |
747 pthread_t thread_id = thread_id_to_samplers_.at(i)->thread_id(); | |
748 pthread_kill(thread_id, SIGPROF); | |
749 } | |
750 } | |
751 #else | |
645 if (active_samplers_.is_empty()) break; | 752 if (active_samplers_.is_empty()) break; |
646 // When CPU profiling is enabled both JavaScript and C++ code is | 753 // When CPU profiling is enabled both JavaScript and C++ code is |
647 // profiled. We must not suspend. | 754 // profiled. We must not suspend. |
648 for (int i = 0; i < active_samplers_.length(); ++i) { | 755 for (int i = 0; i < active_samplers_.length(); ++i) { |
649 Sampler* sampler = active_samplers_.at(i); | 756 Sampler* sampler = active_samplers_.at(i); |
650 if (!sampler->IsProfiling()) continue; | 757 if (!sampler->IsProfiling()) continue; |
651 sampler->DoSample(); | 758 sampler->DoSample(); |
652 } | 759 } |
760 #endif // USE_SIGNALS | |
653 } | 761 } |
654 base::OS::Sleep(base::TimeDelta::FromMilliseconds(interval_)); | 762 base::OS::Sleep(base::TimeDelta::FromMilliseconds(interval_)); |
655 } | 763 } |
656 } | 764 } |
657 | 765 |
658 private: | 766 private: |
659 // Protects the process wide state below. | 767 // Protects the process wide state below. |
660 static base::Mutex* mutex_; | 768 static base::Mutex* mutex_; |
661 static SamplerThread* instance_; | 769 static SamplerThread* instance_; |
662 | 770 |
663 const int interval_; | 771 const int interval_; |
664 List<Sampler*> active_samplers_; | 772 |
773 #if defined(USE_SIGNALS) | |
774 friend class SignalHandler; | |
775 static ThreadSamplersList thread_id_to_samplers_; | |
776 static AtomicValue<int> sampler_list_access_counter_; | |
777 static void AddSampler(Sampler* sampler) { | |
778 AtomicGuard<int> atomic_guard(&SamplerThread::sampler_list_access_counter_, | |
779 0, 1, true); | |
780 // Add sampler into map if needed. | |
781 pthread_t thread_id = sampler->platform_data()->vm_tid(); | |
782 SamplerList* samplers = NULL; | |
783 for (int i = 0; i < thread_id_to_samplers_.length(); ++i) { | |
784 ThreadSamplersPair* tsp = thread_id_to_samplers_.at(i); | |
785 if (pthread_equal(tsp->thread_id(), thread_id) != 0) { | |
786 samplers = tsp->samplers(); | |
787 break; | |
788 } | |
789 } | |
790 if (samplers != NULL) { | |
791 if (!samplers->Contains(sampler)) | |
792 samplers->Add(sampler); | |
alph
2016/04/06 22:21:26
use {}
lpy
2016/04/06 23:51:37
Done.
| |
793 } else { | |
794 samplers = new SamplerList(); | |
795 samplers->Add(sampler); | |
796 thread_id_to_samplers_.Add(new ThreadSamplersPair(thread_id, samplers)); | |
797 } | |
798 } | |
799 #else | |
800 SamplerList active_samplers_; | |
801 #endif // USE_SIGNALS | |
665 | 802 |
666 DISALLOW_COPY_AND_ASSIGN(SamplerThread); | 803 DISALLOW_COPY_AND_ASSIGN(SamplerThread); |
667 }; | 804 }; |
668 | 805 |
669 | 806 |
670 base::Mutex* SamplerThread::mutex_ = NULL; | 807 base::Mutex* SamplerThread::mutex_ = NULL; |
671 SamplerThread* SamplerThread::instance_ = NULL; | 808 SamplerThread* SamplerThread::instance_ = NULL; |
809 #if defined(USE_SIGNALS) | |
810 ThreadSamplersList SamplerThread::thread_id_to_samplers_; | |
811 AtomicValue<int> SamplerThread::sampler_list_access_counter_(0); | |
812 #endif // USE_SIGNALS | |
813 | |
814 // As Native Client does not support signal handling, profiling is disabled. | |
815 #if defined(USE_SIGNALS) | |
alph
2016/04/06 22:21:25
you can have a single #if - #endif block for USE_S
lpy
2016/04/06 23:51:37
Done.
| |
816 #if !V8_OS_NACL | |
817 void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info, | |
818 void* context) { | |
819 USE(info); | |
820 if (signal != SIGPROF) return; | |
821 AtomicGuard<int> atomic_guard(&SamplerThread::sampler_list_access_counter_, | |
822 0, 1, false); | |
823 if (!atomic_guard.is_success()) return; | |
824 pthread_t thread_id = pthread_self(); | |
825 SamplerList* samplers = NULL; | |
826 for (int i = 0; i < SamplerThread::thread_id_to_samplers_.length(); ++i) { | |
alph
2016/04/06 22:21:26
Looks like thread_id_to_samplers_ should be a map,
lpy
2016/04/06 23:51:38
Done.
| |
827 ThreadSamplersPair* tsp = SamplerThread::thread_id_to_samplers_.at(i); | |
828 if (pthread_equal(tsp->thread_id(), thread_id) != 0) { | |
829 samplers = tsp->samplers(); | |
830 break; | |
831 } | |
832 } | |
833 DCHECK(samplers != NULL); | |
alph
2016/04/06 22:21:26
This is not true. The samplers could get deleted w
lpy
2016/04/06 23:51:37
Done.
| |
834 for (int i = 0; i < samplers->length(); ++i) { | |
835 Sampler* sampler = samplers->at(i); | |
836 SignalHandler::CollectSample(context, sampler); | |
alph
2016/04/06 22:21:26
drop SignalHandler::
lpy
2016/04/06 23:51:37
Done.
| |
837 } | |
838 } | |
839 #endif // !V8_OS_NACL | |
840 #endif // USE_SIGNALs | |
672 | 841 |
673 | 842 |
674 // | 843 // |
675 // StackTracer implementation | 844 // StackTracer implementation |
676 // | 845 // |
677 DISABLE_ASAN void TickSample::Init(Isolate* isolate, | 846 DISABLE_ASAN void TickSample::Init(Isolate* isolate, |
678 const v8::RegisterState& regs, | 847 const v8::RegisterState& regs, |
679 RecordCEntryFrame record_c_entry_frame, | 848 RecordCEntryFrame record_c_entry_frame, |
680 bool update_stats) { | 849 bool update_stats) { |
681 timestamp = base::TimeTicks::HighResolutionNow(); | 850 timestamp = base::TimeTicks::HighResolutionNow(); |
(...skipping 100 matching lines...) Loading... | |
782 SignalHandler::TearDown(); | 951 SignalHandler::TearDown(); |
783 #endif | 952 #endif |
784 } | 953 } |
785 | 954 |
786 Sampler::Sampler(Isolate* isolate, int interval) | 955 Sampler::Sampler(Isolate* isolate, int interval) |
787 : isolate_(isolate), | 956 : isolate_(isolate), |
788 interval_(interval), | 957 interval_(interval), |
789 profiling_(false), | 958 profiling_(false), |
790 has_processing_thread_(false), | 959 has_processing_thread_(false), |
791 active_(false), | 960 active_(false), |
961 registered_(false), | |
792 is_counting_samples_(false), | 962 is_counting_samples_(false), |
793 js_sample_count_(0), | 963 js_sample_count_(0), |
794 external_sample_count_(0) { | 964 external_sample_count_(0) { |
795 data_ = new PlatformData; | 965 data_ = new PlatformData; |
796 } | 966 } |
797 | 967 |
798 Sampler::~Sampler() { | 968 Sampler::~Sampler() { |
799 DCHECK(!IsActive()); | 969 DCHECK(!IsActive()); |
970 if (IsRegistered()) | |
971 SamplerThread::RemoveSampler(this); | |
alph
2016/04/06 22:21:26
{}
lpy
2016/04/06 23:51:37
Done.
| |
800 delete data_; | 972 delete data_; |
801 } | 973 } |
802 | 974 |
803 void Sampler::Start() { | 975 void Sampler::Start() { |
804 DCHECK(!IsActive()); | 976 DCHECK(!IsActive()); |
805 SetActive(true); | 977 SetActive(true); |
806 SamplerThread::AddActiveSampler(this); | 978 SamplerThread::AddActiveSampler(this); |
807 } | 979 } |
808 | 980 |
809 | 981 |
810 void Sampler::Stop() { | 982 void Sampler::Stop() { |
811 DCHECK(IsActive()); | 983 DCHECK(IsActive()); |
812 SamplerThread::RemoveActiveSampler(this); | 984 SamplerThread::RemoveSampler(this); |
813 SetActive(false); | 985 SetActive(false); |
986 SetRegistered(false); | |
814 } | 987 } |
815 | 988 |
816 | 989 |
817 void Sampler::IncreaseProfilingDepth() { | 990 void Sampler::IncreaseProfilingDepth() { |
818 base::NoBarrier_AtomicIncrement(&profiling_, 1); | 991 base::NoBarrier_AtomicIncrement(&profiling_, 1); |
819 #if defined(USE_SIGNALS) | 992 #if defined(USE_SIGNALS) |
820 SignalHandler::IncreaseSamplerCount(); | 993 SignalHandler::IncreaseSamplerCount(); |
821 #endif | 994 #endif |
822 } | 995 } |
823 | 996 |
(...skipping 19 matching lines...) Loading... | |
843 if (sample != &sample_obj) { | 1016 if (sample != &sample_obj) { |
844 isolate_->cpu_profiler()->FinishTickSample(); | 1017 isolate_->cpu_profiler()->FinishTickSample(); |
845 } | 1018 } |
846 } | 1019 } |
847 | 1020 |
848 | 1021 |
849 #if defined(USE_SIGNALS) | 1022 #if defined(USE_SIGNALS) |
850 | 1023 |
851 void Sampler::DoSample() { | 1024 void Sampler::DoSample() { |
852 if (!SignalHandler::Installed()) return; | 1025 if (!SignalHandler::Installed()) return; |
1026 if (!IsActive() && !IsRegistered()) { | |
1027 SamplerThread::RegisterSampler(this); | |
1028 SetRegistered(true); | |
1029 } | |
853 pthread_kill(platform_data()->vm_tid(), SIGPROF); | 1030 pthread_kill(platform_data()->vm_tid(), SIGPROF); |
854 } | 1031 } |
855 | 1032 |
856 #elif V8_OS_WIN || V8_OS_CYGWIN | 1033 #elif V8_OS_WIN || V8_OS_CYGWIN |
857 | 1034 |
858 void Sampler::DoSample() { | 1035 void Sampler::DoSample() { |
859 HANDLE profiled_thread = platform_data()->profiled_thread(); | 1036 HANDLE profiled_thread = platform_data()->profiled_thread(); |
860 if (profiled_thread == NULL) return; | 1037 if (profiled_thread == NULL) return; |
861 | 1038 |
862 #if defined(USE_SIMULATOR) | 1039 #if defined(USE_SIMULATOR) |
(...skipping 26 matching lines...) Loading... | |
889 SampleStack(state); | 1066 SampleStack(state); |
890 } | 1067 } |
891 ResumeThread(profiled_thread); | 1068 ResumeThread(profiled_thread); |
892 } | 1069 } |
893 | 1070 |
894 #endif // USE_SIGNALS | 1071 #endif // USE_SIGNALS |
895 | 1072 |
896 | 1073 |
897 } // namespace internal | 1074 } // namespace internal |
898 } // namespace v8 | 1075 } // namespace v8 |
OLD | NEW |