Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: src/profiler/sampler.cc

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

Powered by Google App Engine
This is Rietveld 408576698