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...) Expand all 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...) Expand 10 before | Expand all | Expand 10 after 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 AtomicGuard { |
| 244 public: |
| 245 explicit AtomicGuard(AtomicValue<int>* atomic, bool is_block = true) |
| 246 : atomic_(atomic), |
| 247 is_success_(false) { |
| 248 do { |
| 249 is_success_ = atomic_->TrySetValue(0, 1); |
| 250 } while (is_block && !is_success_); |
| 251 } |
| 252 |
| 253 bool is_success() { return is_success_; } |
| 254 |
| 255 ~AtomicGuard() { |
| 256 if (is_success_) { |
| 257 atomic_->SetValue(0); |
| 258 } |
| 259 atomic_ = NULL; |
| 260 } |
| 261 |
| 262 private: |
| 263 AtomicValue<int>* atomic_; |
| 264 bool is_success_; |
| 265 }; |
| 266 |
| 267 |
| 268 // Returns key for hash map. |
| 269 void* ThreadKey(pthread_t thread_id) { |
| 270 return reinterpret_cast<void*>(thread_id); |
| 271 } |
| 272 |
| 273 |
| 274 // Returns hash value for hash map. |
| 275 uint32_t ThreadHash(pthread_t thread_id) { |
| 276 #if V8_OS_MACOSX |
| 277 return static_cast<uint32_t>(reinterpret_cast<intptr_t>(thread_id)); |
| 278 #else |
| 279 return static_cast<uint32_t>(thread_id); |
| 280 #endif |
| 281 } |
| 282 #endif // USE_SIGNALS |
| 283 |
239 } // namespace | 284 } // namespace |
240 | 285 |
241 #if defined(USE_SIGNALS) | 286 #if defined(USE_SIGNALS) |
242 | 287 |
243 class Sampler::PlatformData : public PlatformDataCommon { | 288 class Sampler::PlatformData : public PlatformDataCommon { |
244 public: | 289 public: |
245 PlatformData() : vm_tid_(pthread_self()) {} | 290 PlatformData() : vm_tid_(pthread_self()) {} |
246 pthread_t vm_tid() const { return vm_tid_; } | 291 pthread_t vm_tid() const { return vm_tid_; } |
247 | 292 |
248 private: | 293 private: |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 | 412 |
368 static void DecreaseSamplerCount() { | 413 static void DecreaseSamplerCount() { |
369 base::LockGuard<base::Mutex> lock_guard(mutex_); | 414 base::LockGuard<base::Mutex> lock_guard(mutex_); |
370 if (--client_count_ == 0) Restore(); | 415 if (--client_count_ == 0) Restore(); |
371 } | 416 } |
372 | 417 |
373 static bool Installed() { | 418 static bool Installed() { |
374 return signal_handler_installed_; | 419 return signal_handler_installed_; |
375 } | 420 } |
376 | 421 |
| 422 #if !V8_OS_NACL |
| 423 static void CollectSample(void* context, Sampler* sampler); |
| 424 #endif |
| 425 |
377 private: | 426 private: |
378 static void Install() { | 427 static void Install() { |
379 #if !V8_OS_NACL | 428 #if !V8_OS_NACL |
380 struct sigaction sa; | 429 struct sigaction sa; |
381 sa.sa_sigaction = &HandleProfilerSignal; | 430 sa.sa_sigaction = &HandleProfilerSignal; |
382 sigemptyset(&sa.sa_mask); | 431 sigemptyset(&sa.sa_mask); |
383 #if V8_OS_QNX | 432 #if V8_OS_QNX |
384 sa.sa_flags = SA_SIGINFO; | 433 sa.sa_flags = SA_SIGINFO; |
385 #else | 434 #else |
386 sa.sa_flags = SA_RESTART | SA_SIGINFO; | 435 sa.sa_flags = SA_RESTART | SA_SIGINFO; |
(...skipping 24 matching lines...) Expand all Loading... |
411 | 460 |
412 | 461 |
413 base::Mutex* SignalHandler::mutex_ = NULL; | 462 base::Mutex* SignalHandler::mutex_ = NULL; |
414 int SignalHandler::client_count_ = 0; | 463 int SignalHandler::client_count_ = 0; |
415 struct sigaction SignalHandler::old_signal_handler_; | 464 struct sigaction SignalHandler::old_signal_handler_; |
416 bool SignalHandler::signal_handler_installed_ = false; | 465 bool SignalHandler::signal_handler_installed_ = false; |
417 | 466 |
418 | 467 |
419 // As Native Client does not support signal handling, profiling is disabled. | 468 // As Native Client does not support signal handling, profiling is disabled. |
420 #if !V8_OS_NACL | 469 #if !V8_OS_NACL |
421 void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info, | 470 void SignalHandler::CollectSample(void* context, Sampler* sampler) { |
422 void* context) { | 471 if (sampler == NULL || (!sampler->IsProfiling() && |
423 USE(info); | 472 !sampler->IsRegistered())) { |
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; | 473 return; |
429 } | 474 } |
| 475 Isolate* isolate = sampler->isolate(); |
| 476 |
| 477 // We require a fully initialized and entered isolate. |
| 478 if (isolate == NULL || !isolate->IsInUse()) return; |
| 479 |
430 if (v8::Locker::IsActive() && | 480 if (v8::Locker::IsActive() && |
431 !isolate->thread_manager()->IsLockedByCurrentThread()) { | 481 !isolate->thread_manager()->IsLockedByCurrentThread()) { |
432 return; | 482 return; |
433 } | 483 } |
434 | 484 |
435 Sampler* sampler = isolate->logger()->sampler(); | |
436 if (sampler == NULL) return; | |
437 | |
438 v8::RegisterState state; | 485 v8::RegisterState state; |
439 | 486 |
440 #if defined(USE_SIMULATOR) | 487 #if defined(USE_SIMULATOR) |
441 SimulatorHelper helper; | 488 SimulatorHelper helper; |
442 if (!helper.Init(isolate)) return; | 489 if (!helper.Init(isolate)) return; |
443 helper.FillRegisters(&state); | 490 helper.FillRegisters(&state); |
444 // It possible that the simulator is interrupted while it is updating | 491 // It possible that the simulator is interrupted while it is updating |
445 // the sp or fp register. ARM64 simulator does this in two steps: | 492 // 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. | 493 // first setting it to zero and then setting it to the new value. |
447 // Bailout if sp/fp doesn't contain the new value. | 494 // Bailout if sp/fp doesn't contain the new value. |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 #elif V8_OS_AIX | 622 #elif V8_OS_AIX |
576 state.pc = reinterpret_cast<Address>(mcontext.jmp_context.iar); | 623 state.pc = reinterpret_cast<Address>(mcontext.jmp_context.iar); |
577 state.sp = reinterpret_cast<Address>(mcontext.jmp_context.gpr[1]); | 624 state.sp = reinterpret_cast<Address>(mcontext.jmp_context.gpr[1]); |
578 state.fp = reinterpret_cast<Address>(mcontext.jmp_context.gpr[31]); | 625 state.fp = reinterpret_cast<Address>(mcontext.jmp_context.gpr[31]); |
579 #endif // V8_OS_AIX | 626 #endif // V8_OS_AIX |
580 #endif // USE_SIMULATOR | 627 #endif // USE_SIMULATOR |
581 sampler->SampleStack(state); | 628 sampler->SampleStack(state); |
582 } | 629 } |
583 #endif // V8_OS_NACL | 630 #endif // V8_OS_NACL |
584 | 631 |
585 #endif | 632 #endif // USE_SIGNALS |
586 | 633 |
587 | 634 |
588 class SamplerThread : public base::Thread { | 635 class SamplerThread : public base::Thread { |
589 public: | 636 public: |
590 static const int kSamplerThreadStackSize = 64 * KB; | 637 static const int kSamplerThreadStackSize = 64 * KB; |
591 | 638 |
592 explicit SamplerThread(int interval) | 639 explicit SamplerThread(int interval) |
593 : Thread(base::Thread::Options("SamplerThread", kSamplerThreadStackSize)), | 640 : Thread(base::Thread::Options("SamplerThread", kSamplerThreadStackSize)), |
594 interval_(interval) {} | 641 interval_(interval) {} |
595 | 642 |
596 static void SetUp() { if (!mutex_) mutex_ = new base::Mutex(); } | 643 static void SetUp() { if (!mutex_) mutex_ = new base::Mutex(); } |
597 static void TearDown() { delete mutex_; mutex_ = NULL; } | 644 static void TearDown() { delete mutex_; mutex_ = NULL; } |
598 | 645 |
599 static void AddActiveSampler(Sampler* sampler) { | 646 static void AddActiveSampler(Sampler* sampler) { |
600 bool need_to_start = false; | 647 bool need_to_start = false; |
601 base::LockGuard<base::Mutex> lock_guard(mutex_); | 648 base::LockGuard<base::Mutex> lock_guard(mutex_); |
602 if (instance_ == NULL) { | 649 if (instance_ == NULL) { |
603 // Start a thread that will send SIGPROF signal to VM threads, | 650 // Start a thread that will send SIGPROF signal to VM threads, |
604 // when CPU profiling will be enabled. | 651 // when CPU profiling will be enabled. |
605 instance_ = new SamplerThread(sampler->interval()); | 652 instance_ = new SamplerThread(sampler->interval()); |
606 need_to_start = true; | 653 need_to_start = true; |
607 } | 654 } |
608 | 655 |
609 DCHECK(sampler->IsActive()); | 656 DCHECK(sampler->IsActive()); |
| 657 DCHECK(instance_->interval_ == sampler->interval()); |
| 658 |
| 659 #if defined(USE_SIGNALS) |
| 660 AddSampler(sampler); |
| 661 #else |
610 DCHECK(!instance_->active_samplers_.Contains(sampler)); | 662 DCHECK(!instance_->active_samplers_.Contains(sampler)); |
611 DCHECK(instance_->interval_ == sampler->interval()); | |
612 instance_->active_samplers_.Add(sampler); | 663 instance_->active_samplers_.Add(sampler); |
| 664 #endif // USE_SIGNALS |
613 | 665 |
614 if (need_to_start) instance_->StartSynchronously(); | 666 if (need_to_start) instance_->StartSynchronously(); |
615 } | 667 } |
616 | 668 |
617 static void RemoveActiveSampler(Sampler* sampler) { | 669 static void RemoveSampler(Sampler* sampler) { |
618 SamplerThread* instance_to_remove = NULL; | 670 SamplerThread* instance_to_remove = NULL; |
619 { | 671 { |
620 base::LockGuard<base::Mutex> lock_guard(mutex_); | 672 base::LockGuard<base::Mutex> lock_guard(mutex_); |
621 | 673 |
622 DCHECK(sampler->IsActive()); | 674 DCHECK(sampler->IsActive() || sampler->IsRegistered()); |
| 675 #if defined(USE_SIGNALS) |
| 676 { |
| 677 AtomicGuard atomic_guard(&sampler_list_access_counter_); |
| 678 // Remove sampler from map. |
| 679 pthread_t thread_id = sampler->platform_data()->vm_tid(); |
| 680 void* thread_key = ThreadKey(thread_id); |
| 681 uint32_t thread_hash = ThreadHash(thread_id); |
| 682 HashMap::Entry* entry = |
| 683 thread_id_to_samplers_.Get().Lookup(thread_key, thread_hash); |
| 684 DCHECK(entry != NULL); |
| 685 SamplerList* samplers = reinterpret_cast<SamplerList*>(entry->value); |
| 686 samplers->RemoveElement(sampler); |
| 687 if (samplers->is_empty()) { |
| 688 thread_id_to_samplers_.Pointer()->Remove(thread_key, thread_hash); |
| 689 delete samplers; |
| 690 } |
| 691 if (thread_id_to_samplers_.Get().occupancy() == 0) { |
| 692 instance_to_remove = instance_; |
| 693 instance_ = NULL; |
| 694 } |
| 695 } |
| 696 #else |
623 bool removed = instance_->active_samplers_.RemoveElement(sampler); | 697 bool removed = instance_->active_samplers_.RemoveElement(sampler); |
624 DCHECK(removed); | 698 DCHECK(removed); |
625 USE(removed); | 699 USE(removed); |
626 | 700 |
627 // We cannot delete the instance immediately as we need to Join() the | 701 // 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. | 702 // thread but we are holding mutex_ and the thread may try to acquire it. |
629 if (instance_->active_samplers_.is_empty()) { | 703 if (instance_->active_samplers_.is_empty()) { |
630 instance_to_remove = instance_; | 704 instance_to_remove = instance_; |
631 instance_ = NULL; | 705 instance_ = NULL; |
632 } | 706 } |
| 707 #endif // USE_SIGNALS |
633 } | 708 } |
634 | 709 |
635 if (!instance_to_remove) return; | 710 if (!instance_to_remove) return; |
636 instance_to_remove->Join(); | 711 instance_to_remove->Join(); |
637 delete instance_to_remove; | 712 delete instance_to_remove; |
638 } | 713 } |
639 | 714 |
| 715 // Unlike AddActiveSampler, this method only adds a sampler, |
| 716 // but won't start the sampler thread. |
| 717 static void RegisterSampler(Sampler* sampler) { |
| 718 base::LockGuard<base::Mutex> lock_guard(mutex_); |
| 719 #if defined(USE_SIGNALS) |
| 720 AddSampler(sampler); |
| 721 #endif // USE_SIGNALS |
| 722 } |
| 723 |
640 // Implement Thread::Run(). | 724 // Implement Thread::Run(). |
641 virtual void Run() { | 725 virtual void Run() { |
642 while (true) { | 726 while (true) { |
643 { | 727 { |
644 base::LockGuard<base::Mutex> lock_guard(mutex_); | 728 base::LockGuard<base::Mutex> lock_guard(mutex_); |
| 729 #if defined(USE_SIGNALS) |
| 730 if (thread_id_to_samplers_.Get().occupancy() == 0) break; |
| 731 if (SignalHandler::Installed()) { |
| 732 for (HashMap::Entry *p = thread_id_to_samplers_.Get().Start(); |
| 733 p != NULL; p = thread_id_to_samplers_.Get().Next(p)) { |
| 734 pthread_t thread_id = reinterpret_cast<pthread_t>(p->key); |
| 735 pthread_kill(thread_id, SIGPROF); |
| 736 } |
| 737 } |
| 738 #else |
645 if (active_samplers_.is_empty()) break; | 739 if (active_samplers_.is_empty()) break; |
646 // When CPU profiling is enabled both JavaScript and C++ code is | 740 // When CPU profiling is enabled both JavaScript and C++ code is |
647 // profiled. We must not suspend. | 741 // profiled. We must not suspend. |
648 for (int i = 0; i < active_samplers_.length(); ++i) { | 742 for (int i = 0; i < active_samplers_.length(); ++i) { |
649 Sampler* sampler = active_samplers_.at(i); | 743 Sampler* sampler = active_samplers_.at(i); |
650 if (!sampler->IsProfiling()) continue; | 744 if (!sampler->IsProfiling()) continue; |
651 sampler->DoSample(); | 745 sampler->DoSample(); |
652 } | 746 } |
| 747 #endif // USE_SIGNALS |
653 } | 748 } |
654 base::OS::Sleep(base::TimeDelta::FromMilliseconds(interval_)); | 749 base::OS::Sleep(base::TimeDelta::FromMilliseconds(interval_)); |
655 } | 750 } |
656 } | 751 } |
657 | 752 |
658 private: | 753 private: |
659 // Protects the process wide state below. | 754 // Protects the process wide state below. |
660 static base::Mutex* mutex_; | 755 static base::Mutex* mutex_; |
661 static SamplerThread* instance_; | 756 static SamplerThread* instance_; |
662 | 757 |
663 const int interval_; | 758 const int interval_; |
664 List<Sampler*> active_samplers_; | 759 |
| 760 #if defined(USE_SIGNALS) |
| 761 struct HashMapCreateTrait { |
| 762 static void Construct(HashMap* allocated_ptr) { |
| 763 new (allocated_ptr) HashMap(HashMap::PointersMatch); |
| 764 } |
| 765 }; |
| 766 friend class SignalHandler; |
| 767 static base::LazyInstance<HashMap, HashMapCreateTrait>::type |
| 768 thread_id_to_samplers_; |
| 769 static AtomicValue<int> sampler_list_access_counter_; |
| 770 static void AddSampler(Sampler* sampler) { |
| 771 AtomicGuard atomic_guard(&sampler_list_access_counter_); |
| 772 // Add sampler into map if needed. |
| 773 pthread_t thread_id = sampler->platform_data()->vm_tid(); |
| 774 HashMap::Entry *entry = |
| 775 thread_id_to_samplers_.Pointer()->LookupOrInsert(ThreadKey(thread_id), |
| 776 ThreadHash(thread_id)); |
| 777 if (entry->value == NULL) { |
| 778 SamplerList* samplers = new SamplerList(); |
| 779 samplers->Add(sampler); |
| 780 entry->value = samplers; |
| 781 } else { |
| 782 SamplerList* samplers = reinterpret_cast<SamplerList*>(entry->value); |
| 783 if (!samplers->Contains(sampler)) { |
| 784 samplers->Add(sampler); |
| 785 } |
| 786 } |
| 787 } |
| 788 #else |
| 789 SamplerList active_samplers_; |
| 790 #endif // USE_SIGNALS |
665 | 791 |
666 DISALLOW_COPY_AND_ASSIGN(SamplerThread); | 792 DISALLOW_COPY_AND_ASSIGN(SamplerThread); |
667 }; | 793 }; |
668 | 794 |
669 | 795 |
670 base::Mutex* SamplerThread::mutex_ = NULL; | 796 base::Mutex* SamplerThread::mutex_ = NULL; |
671 SamplerThread* SamplerThread::instance_ = NULL; | 797 SamplerThread* SamplerThread::instance_ = NULL; |
| 798 #if defined(USE_SIGNALS) |
| 799 base::LazyInstance<HashMap, SamplerThread::HashMapCreateTrait>::type |
| 800 SamplerThread::thread_id_to_samplers_ = LAZY_INSTANCE_INITIALIZER; |
| 801 AtomicValue<int> SamplerThread::sampler_list_access_counter_(0); |
| 802 |
| 803 // As Native Client does not support signal handling, profiling is disabled. |
| 804 #if !V8_OS_NACL |
| 805 void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info, |
| 806 void* context) { |
| 807 USE(info); |
| 808 if (signal != SIGPROF) return; |
| 809 AtomicGuard atomic_guard(&SamplerThread::sampler_list_access_counter_, false); |
| 810 if (!atomic_guard.is_success()) return; |
| 811 pthread_t thread_id = pthread_self(); |
| 812 HashMap::Entry* entry = |
| 813 SamplerThread::thread_id_to_samplers_.Pointer()->Lookup( |
| 814 ThreadKey(thread_id), ThreadHash(thread_id)); |
| 815 if (entry == NULL) |
| 816 return; |
| 817 SamplerList* samplers = reinterpret_cast<SamplerList*>(entry->value); |
| 818 for (int i = 0; i < samplers->length(); ++i) { |
| 819 Sampler* sampler = samplers->at(i); |
| 820 CollectSample(context, sampler); |
| 821 } |
| 822 } |
| 823 #endif // !V8_OS_NACL |
| 824 #endif // USE_SIGNALs |
672 | 825 |
673 | 826 |
674 // | 827 // |
675 // StackTracer implementation | 828 // StackTracer implementation |
676 // | 829 // |
677 DISABLE_ASAN void TickSample::Init(Isolate* isolate, | 830 DISABLE_ASAN void TickSample::Init(Isolate* isolate, |
678 const v8::RegisterState& regs, | 831 const v8::RegisterState& regs, |
679 RecordCEntryFrame record_c_entry_frame, | 832 RecordCEntryFrame record_c_entry_frame, |
680 bool update_stats) { | 833 bool update_stats) { |
681 timestamp = base::TimeTicks::HighResolutionNow(); | 834 timestamp = base::TimeTicks::HighResolutionNow(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 SignalHandler::TearDown(); | 935 SignalHandler::TearDown(); |
783 #endif | 936 #endif |
784 } | 937 } |
785 | 938 |
786 Sampler::Sampler(Isolate* isolate, int interval) | 939 Sampler::Sampler(Isolate* isolate, int interval) |
787 : isolate_(isolate), | 940 : isolate_(isolate), |
788 interval_(interval), | 941 interval_(interval), |
789 profiling_(false), | 942 profiling_(false), |
790 has_processing_thread_(false), | 943 has_processing_thread_(false), |
791 active_(false), | 944 active_(false), |
| 945 registered_(false), |
792 is_counting_samples_(false), | 946 is_counting_samples_(false), |
793 js_sample_count_(0), | 947 js_sample_count_(0), |
794 external_sample_count_(0) { | 948 external_sample_count_(0) { |
795 data_ = new PlatformData; | 949 data_ = new PlatformData; |
796 } | 950 } |
797 | 951 |
798 Sampler::~Sampler() { | 952 Sampler::~Sampler() { |
799 DCHECK(!IsActive()); | 953 DCHECK(!IsActive()); |
| 954 if (IsRegistered()) { |
| 955 SamplerThread::RemoveSampler(this); |
| 956 } |
800 delete data_; | 957 delete data_; |
801 } | 958 } |
802 | 959 |
803 void Sampler::Start() { | 960 void Sampler::Start() { |
804 DCHECK(!IsActive()); | 961 DCHECK(!IsActive()); |
805 SetActive(true); | 962 SetActive(true); |
806 SamplerThread::AddActiveSampler(this); | 963 SamplerThread::AddActiveSampler(this); |
807 } | 964 } |
808 | 965 |
809 | 966 |
810 void Sampler::Stop() { | 967 void Sampler::Stop() { |
811 DCHECK(IsActive()); | 968 DCHECK(IsActive()); |
812 SamplerThread::RemoveActiveSampler(this); | 969 SamplerThread::RemoveSampler(this); |
813 SetActive(false); | 970 SetActive(false); |
| 971 SetRegistered(false); |
814 } | 972 } |
815 | 973 |
816 | 974 |
817 void Sampler::IncreaseProfilingDepth() { | 975 void Sampler::IncreaseProfilingDepth() { |
818 base::NoBarrier_AtomicIncrement(&profiling_, 1); | 976 base::NoBarrier_AtomicIncrement(&profiling_, 1); |
819 #if defined(USE_SIGNALS) | 977 #if defined(USE_SIGNALS) |
820 SignalHandler::IncreaseSamplerCount(); | 978 SignalHandler::IncreaseSamplerCount(); |
821 #endif | 979 #endif |
822 } | 980 } |
823 | 981 |
(...skipping 19 matching lines...) Expand all Loading... |
843 if (sample != &sample_obj) { | 1001 if (sample != &sample_obj) { |
844 isolate_->cpu_profiler()->FinishTickSample(); | 1002 isolate_->cpu_profiler()->FinishTickSample(); |
845 } | 1003 } |
846 } | 1004 } |
847 | 1005 |
848 | 1006 |
849 #if defined(USE_SIGNALS) | 1007 #if defined(USE_SIGNALS) |
850 | 1008 |
851 void Sampler::DoSample() { | 1009 void Sampler::DoSample() { |
852 if (!SignalHandler::Installed()) return; | 1010 if (!SignalHandler::Installed()) return; |
| 1011 if (!IsActive() && !IsRegistered()) { |
| 1012 SamplerThread::RegisterSampler(this); |
| 1013 SetRegistered(true); |
| 1014 } |
853 pthread_kill(platform_data()->vm_tid(), SIGPROF); | 1015 pthread_kill(platform_data()->vm_tid(), SIGPROF); |
854 } | 1016 } |
855 | 1017 |
856 #elif V8_OS_WIN || V8_OS_CYGWIN | 1018 #elif V8_OS_WIN || V8_OS_CYGWIN |
857 | 1019 |
858 void Sampler::DoSample() { | 1020 void Sampler::DoSample() { |
859 HANDLE profiled_thread = platform_data()->profiled_thread(); | 1021 HANDLE profiled_thread = platform_data()->profiled_thread(); |
860 if (profiled_thread == NULL) return; | 1022 if (profiled_thread == NULL) return; |
861 | 1023 |
862 #if defined(USE_SIMULATOR) | 1024 #if defined(USE_SIMULATOR) |
(...skipping 26 matching lines...) Expand all Loading... |
889 SampleStack(state); | 1051 SampleStack(state); |
890 } | 1052 } |
891 ResumeThread(profiled_thread); | 1053 ResumeThread(profiled_thread); |
892 } | 1054 } |
893 | 1055 |
894 #endif // USE_SIGNALS | 1056 #endif // USE_SIGNALS |
895 | 1057 |
896 | 1058 |
897 } // namespace internal | 1059 } // namespace internal |
898 } // namespace v8 | 1060 } // namespace v8 |
OLD | NEW |