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

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

Issue 1858143003: 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
« src/profiler/sampler.h ('K') | « 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 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
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
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() && !sampler->IsRegistered()))
Yang 2016/04/15 05:35:53 please use {} brackets on line break.
lpy 2016/04/15 05:57:53 Done.
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; 472 return;
429 } 473 Isolate* isolate = sampler->isolate();
474
475 // We require a fully initialized and entered isolate.
476 if (isolate == NULL || !isolate->IsInUse()) return;
477
430 if (v8::Locker::IsActive() && 478 if (v8::Locker::IsActive() &&
431 !isolate->thread_manager()->IsLockedByCurrentThread()) { 479 !isolate->thread_manager()->IsLockedByCurrentThread()) {
432 return; 480 return;
433 } 481 }
434 482
435 Sampler* sampler = isolate->logger()->sampler();
436 if (sampler == NULL) return;
437
438 v8::RegisterState state; 483 v8::RegisterState state;
439 484
440 #if defined(USE_SIMULATOR) 485 #if defined(USE_SIMULATOR)
441 SimulatorHelper helper; 486 SimulatorHelper helper;
442 if (!helper.Init(isolate)) return; 487 if (!helper.Init(isolate)) return;
443 helper.FillRegisters(&state); 488 helper.FillRegisters(&state);
444 // It possible that the simulator is interrupted while it is updating 489 // It possible that the simulator is interrupted while it is updating
445 // the sp or fp register. ARM64 simulator does this in two steps: 490 // 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. 491 // first setting it to zero and then setting it to the new value.
447 // Bailout if sp/fp doesn't contain the new value. 492 // 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 620 #elif V8_OS_AIX
576 state.pc = reinterpret_cast<Address>(mcontext.jmp_context.iar); 621 state.pc = reinterpret_cast<Address>(mcontext.jmp_context.iar);
577 state.sp = reinterpret_cast<Address>(mcontext.jmp_context.gpr[1]); 622 state.sp = reinterpret_cast<Address>(mcontext.jmp_context.gpr[1]);
578 state.fp = reinterpret_cast<Address>(mcontext.jmp_context.gpr[31]); 623 state.fp = reinterpret_cast<Address>(mcontext.jmp_context.gpr[31]);
579 #endif // V8_OS_AIX 624 #endif // V8_OS_AIX
580 #endif // USE_SIMULATOR 625 #endif // USE_SIMULATOR
581 sampler->SampleStack(state); 626 sampler->SampleStack(state);
582 } 627 }
583 #endif // V8_OS_NACL 628 #endif // V8_OS_NACL
584 629
585 #endif 630 #endif // USE_SIGNALS
586 631
587 632
588 class SamplerThread : public base::Thread { 633 class SamplerThread : public base::Thread {
589 public: 634 public:
590 static const int kSamplerThreadStackSize = 64 * KB; 635 static const int kSamplerThreadStackSize = 64 * KB;
591 636
592 explicit SamplerThread(int interval) 637 explicit SamplerThread(int interval)
593 : Thread(base::Thread::Options("SamplerThread", kSamplerThreadStackSize)), 638 : Thread(base::Thread::Options("SamplerThread", kSamplerThreadStackSize)),
594 interval_(interval) {} 639 interval_(interval) {}
595 640
596 static void SetUp() { if (!mutex_) mutex_ = new base::Mutex(); } 641 static void SetUp() { if (!mutex_) mutex_ = new base::Mutex(); }
597 static void TearDown() { delete mutex_; mutex_ = NULL; } 642 static void TearDown() { delete mutex_; mutex_ = NULL; }
598 643
599 static void AddActiveSampler(Sampler* sampler) { 644 static void AddActiveSampler(Sampler* sampler) {
600 bool need_to_start = false; 645 bool need_to_start = false;
601 base::LockGuard<base::Mutex> lock_guard(mutex_); 646 base::LockGuard<base::Mutex> lock_guard(mutex_);
602 if (instance_ == NULL) { 647 if (instance_ == NULL) {
603 // Start a thread that will send SIGPROF signal to VM threads, 648 // Start a thread that will send SIGPROF signal to VM threads,
604 // when CPU profiling will be enabled. 649 // when CPU profiling will be enabled.
605 instance_ = new SamplerThread(sampler->interval()); 650 instance_ = new SamplerThread(sampler->interval());
606 need_to_start = true; 651 need_to_start = true;
607 } 652 }
608 653
609 DCHECK(sampler->IsActive()); 654 DCHECK(sampler->IsActive());
655 DCHECK(instance_->interval_ == sampler->interval());
656
657 #if defined(USE_SIGNALS)
658 AddSampler(sampler);
659 #else
610 DCHECK(!instance_->active_samplers_.Contains(sampler)); 660 DCHECK(!instance_->active_samplers_.Contains(sampler));
611 DCHECK(instance_->interval_ == sampler->interval());
612 instance_->active_samplers_.Add(sampler); 661 instance_->active_samplers_.Add(sampler);
662 #endif // USE_SIGNALS
613 663
614 if (need_to_start) instance_->StartSynchronously(); 664 if (need_to_start) instance_->StartSynchronously();
615 } 665 }
616 666
617 static void RemoveActiveSampler(Sampler* sampler) { 667 static void RemoveSampler(Sampler* sampler) {
618 SamplerThread* instance_to_remove = NULL; 668 SamplerThread* instance_to_remove = NULL;
619 { 669 {
620 base::LockGuard<base::Mutex> lock_guard(mutex_); 670 base::LockGuard<base::Mutex> lock_guard(mutex_);
621 671
622 DCHECK(sampler->IsActive()); 672 DCHECK(sampler->IsActive() || sampler->IsRegistered());
673 #if defined(USE_SIGNALS)
674 {
675 AtomicGuard atomic_guard(&sampler_list_access_counter_);
676 // Remove sampler from map.
677 pthread_t thread_id = sampler->platform_data()->vm_tid();
678 void* thread_key = ThreadKey(thread_id);
679 uint32_t thread_hash = ThreadHash(thread_id);
680 HashMap::Entry* entry =
681 thread_id_to_samplers_.Get().Lookup(thread_key, thread_hash);
682 DCHECK(entry != NULL);
683 SamplerList* samplers = reinterpret_cast<SamplerList*>(entry->value);
684 samplers->RemoveElement(sampler);
685 if (samplers->is_empty()) {
686 thread_id_to_samplers_.Pointer()->Remove(thread_key, thread_hash);
687 delete samplers;
688 }
689 if (thread_id_to_samplers_.Get().occupancy() == 0) {
690 instance_to_remove = instance_;
691 instance_ = NULL;
692 }
693 }
694 #else
623 bool removed = instance_->active_samplers_.RemoveElement(sampler); 695 bool removed = instance_->active_samplers_.RemoveElement(sampler);
624 DCHECK(removed); 696 DCHECK(removed);
625 USE(removed); 697 USE(removed);
626 698
627 // We cannot delete the instance immediately as we need to Join() the 699 // 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. 700 // thread but we are holding mutex_ and the thread may try to acquire it.
629 if (instance_->active_samplers_.is_empty()) { 701 if (instance_->active_samplers_.is_empty()) {
630 instance_to_remove = instance_; 702 instance_to_remove = instance_;
631 instance_ = NULL; 703 instance_ = NULL;
632 } 704 }
705 #endif // USE_SIGNALS
633 } 706 }
634 707
635 if (!instance_to_remove) return; 708 if (!instance_to_remove) return;
636 instance_to_remove->Join(); 709 instance_to_remove->Join();
637 delete instance_to_remove; 710 delete instance_to_remove;
638 } 711 }
639 712
713 // Unlike AddActiveSampler, this method only adds a sampler,
714 // but won't start the sampler thread.
715 static void RegisterSampler(Sampler* sampler) {
716 base::LockGuard<base::Mutex> lock_guard(mutex_);
717 #if defined(USE_SIGNALS)
718 AddSampler(sampler);
719 #endif // USE_SIGNALS
720 }
721
640 // Implement Thread::Run(). 722 // Implement Thread::Run().
641 virtual void Run() { 723 virtual void Run() {
642 while (true) { 724 while (true) {
643 { 725 {
644 base::LockGuard<base::Mutex> lock_guard(mutex_); 726 base::LockGuard<base::Mutex> lock_guard(mutex_);
727 #if defined(USE_SIGNALS)
728 if (thread_id_to_samplers_.Get().occupancy() == 0) break;
729 if (SignalHandler::Installed()) {
730 for (HashMap::Entry *p = thread_id_to_samplers_.Get().Start();
731 p != NULL; p = thread_id_to_samplers_.Get().Next(p)) {
732 pthread_t thread_id = reinterpret_cast<pthread_t>(p->key);
733 pthread_kill(thread_id, SIGPROF);
734 }
735 }
736 #else
645 if (active_samplers_.is_empty()) break; 737 if (active_samplers_.is_empty()) break;
646 // When CPU profiling is enabled both JavaScript and C++ code is 738 // When CPU profiling is enabled both JavaScript and C++ code is
647 // profiled. We must not suspend. 739 // profiled. We must not suspend.
648 for (int i = 0; i < active_samplers_.length(); ++i) { 740 for (int i = 0; i < active_samplers_.length(); ++i) {
649 Sampler* sampler = active_samplers_.at(i); 741 Sampler* sampler = active_samplers_.at(i);
650 if (!sampler->IsProfiling()) continue; 742 if (!sampler->IsProfiling()) continue;
651 sampler->DoSample(); 743 sampler->DoSample();
652 } 744 }
745 #endif // USE_SIGNALS
653 } 746 }
654 base::OS::Sleep(base::TimeDelta::FromMilliseconds(interval_)); 747 base::OS::Sleep(base::TimeDelta::FromMilliseconds(interval_));
655 } 748 }
656 } 749 }
657 750
658 private: 751 private:
659 // Protects the process wide state below. 752 // Protects the process wide state below.
660 static base::Mutex* mutex_; 753 static base::Mutex* mutex_;
661 static SamplerThread* instance_; 754 static SamplerThread* instance_;
662 755
663 const int interval_; 756 const int interval_;
664 List<Sampler*> active_samplers_; 757
758 #if defined(USE_SIGNALS)
759 struct HashMapCreateTrait {
760 static void Construct(HashMap* allocated_ptr) {
761 new (allocated_ptr) HashMap(HashMap::PointersMatch);
762 }
763 };
764 friend class SignalHandler;
765 static base::LazyInstance<HashMap, HashMapCreateTrait>::type
766 thread_id_to_samplers_;
767 static AtomicValue<int> sampler_list_access_counter_;
768 static void AddSampler(Sampler* sampler) {
769 AtomicGuard atomic_guard(&sampler_list_access_counter_);
770 // Add sampler into map if needed.
771 pthread_t thread_id = sampler->platform_data()->vm_tid();
772 HashMap::Entry *entry =
773 thread_id_to_samplers_.Pointer()->LookupOrInsert(ThreadKey(thread_id),
774 ThreadHash(thread_id));
775 if (entry->value == NULL) {
776 SamplerList* samplers = new SamplerList();
777 samplers->Add(sampler);
778 entry->value = samplers;
779 } else {
780 SamplerList* samplers = reinterpret_cast<SamplerList*>(entry->value);
781 if (!samplers->Contains(sampler)) {
782 samplers->Add(sampler);
783 }
784 }
785 }
786 #else
787 SamplerList active_samplers_;
788 #endif // USE_SIGNALS
665 789
666 DISALLOW_COPY_AND_ASSIGN(SamplerThread); 790 DISALLOW_COPY_AND_ASSIGN(SamplerThread);
667 }; 791 };
668 792
669 793
670 base::Mutex* SamplerThread::mutex_ = NULL; 794 base::Mutex* SamplerThread::mutex_ = NULL;
671 SamplerThread* SamplerThread::instance_ = NULL; 795 SamplerThread* SamplerThread::instance_ = NULL;
796 #if defined(USE_SIGNALS)
797 base::LazyInstance<HashMap, SamplerThread::HashMapCreateTrait>::type
798 SamplerThread::thread_id_to_samplers_ = LAZY_INSTANCE_INITIALIZER;
799 AtomicValue<int> SamplerThread::sampler_list_access_counter_(0);
800
801 // As Native Client does not support signal handling, profiling is disabled.
802 #if !V8_OS_NACL
803 void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info,
804 void* context) {
805 USE(info);
806 if (signal != SIGPROF) return;
807 AtomicGuard atomic_guard(&SamplerThread::sampler_list_access_counter_, false);
808 if (!atomic_guard.is_success()) return;
809 pthread_t thread_id = pthread_self();
810 HashMap::Entry* entry =
811 SamplerThread::thread_id_to_samplers_.Pointer()->Lookup(
812 ThreadKey(thread_id), ThreadHash(thread_id));
813 if (entry == NULL)
814 return;
815 SamplerList* samplers = reinterpret_cast<SamplerList*>(entry->value);
816 for (int i = 0; i < samplers->length(); ++i) {
817 Sampler* sampler = samplers->at(i);
818 CollectSample(context, sampler);
819 }
820 }
821 #endif // !V8_OS_NACL
822 #endif // USE_SIGNALs
672 823
673 824
674 // 825 //
675 // StackTracer implementation 826 // StackTracer implementation
676 // 827 //
677 DISABLE_ASAN void TickSample::Init(Isolate* isolate, 828 DISABLE_ASAN void TickSample::Init(Isolate* isolate,
678 const v8::RegisterState& regs, 829 const v8::RegisterState& regs,
679 RecordCEntryFrame record_c_entry_frame, 830 RecordCEntryFrame record_c_entry_frame,
680 bool update_stats) { 831 bool update_stats) {
681 timestamp = base::TimeTicks::HighResolutionNow(); 832 timestamp = base::TimeTicks::HighResolutionNow();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 SignalHandler::TearDown(); 933 SignalHandler::TearDown();
783 #endif 934 #endif
784 } 935 }
785 936
786 Sampler::Sampler(Isolate* isolate, int interval) 937 Sampler::Sampler(Isolate* isolate, int interval)
787 : isolate_(isolate), 938 : isolate_(isolate),
788 interval_(interval), 939 interval_(interval),
789 profiling_(false), 940 profiling_(false),
790 has_processing_thread_(false), 941 has_processing_thread_(false),
791 active_(false), 942 active_(false),
943 registered_(false),
792 is_counting_samples_(false), 944 is_counting_samples_(false),
793 js_sample_count_(0), 945 js_sample_count_(0),
794 external_sample_count_(0) { 946 external_sample_count_(0) {
795 data_ = new PlatformData; 947 data_ = new PlatformData;
796 } 948 }
797 949
798 Sampler::~Sampler() { 950 Sampler::~Sampler() {
799 DCHECK(!IsActive()); 951 DCHECK(!IsActive());
952 if (IsRegistered()) {
953 SamplerThread::RemoveSampler(this);
954 }
800 delete data_; 955 delete data_;
801 } 956 }
802 957
803 void Sampler::Start() { 958 void Sampler::Start() {
804 DCHECK(!IsActive()); 959 DCHECK(!IsActive());
805 SetActive(true); 960 SetActive(true);
806 SamplerThread::AddActiveSampler(this); 961 SamplerThread::AddActiveSampler(this);
807 } 962 }
808 963
809 964
810 void Sampler::Stop() { 965 void Sampler::Stop() {
811 DCHECK(IsActive()); 966 DCHECK(IsActive());
812 SamplerThread::RemoveActiveSampler(this); 967 SamplerThread::RemoveSampler(this);
813 SetActive(false); 968 SetActive(false);
969 SetRegistered(false);
814 } 970 }
815 971
816 972
817 void Sampler::IncreaseProfilingDepth() { 973 void Sampler::IncreaseProfilingDepth() {
818 base::NoBarrier_AtomicIncrement(&profiling_, 1); 974 base::NoBarrier_AtomicIncrement(&profiling_, 1);
819 #if defined(USE_SIGNALS) 975 #if defined(USE_SIGNALS)
820 SignalHandler::IncreaseSamplerCount(); 976 SignalHandler::IncreaseSamplerCount();
821 #endif 977 #endif
822 } 978 }
823 979
(...skipping 19 matching lines...) Expand all
843 if (sample != &sample_obj) { 999 if (sample != &sample_obj) {
844 isolate_->cpu_profiler()->FinishTickSample(); 1000 isolate_->cpu_profiler()->FinishTickSample();
845 } 1001 }
846 } 1002 }
847 1003
848 1004
849 #if defined(USE_SIGNALS) 1005 #if defined(USE_SIGNALS)
850 1006
851 void Sampler::DoSample() { 1007 void Sampler::DoSample() {
852 if (!SignalHandler::Installed()) return; 1008 if (!SignalHandler::Installed()) return;
1009 if (!IsActive() && !IsRegistered()) {
1010 SamplerThread::RegisterSampler(this);
1011 SetRegistered(true);
1012 }
853 pthread_kill(platform_data()->vm_tid(), SIGPROF); 1013 pthread_kill(platform_data()->vm_tid(), SIGPROF);
854 } 1014 }
855 1015
856 #elif V8_OS_WIN || V8_OS_CYGWIN 1016 #elif V8_OS_WIN || V8_OS_CYGWIN
857 1017
858 void Sampler::DoSample() { 1018 void Sampler::DoSample() {
859 HANDLE profiled_thread = platform_data()->profiled_thread(); 1019 HANDLE profiled_thread = platform_data()->profiled_thread();
860 if (profiled_thread == NULL) return; 1020 if (profiled_thread == NULL) return;
861 1021
862 #if defined(USE_SIMULATOR) 1022 #if defined(USE_SIMULATOR)
(...skipping 26 matching lines...) Expand all
889 SampleStack(state); 1049 SampleStack(state);
890 } 1050 }
891 ResumeThread(profiled_thread); 1051 ResumeThread(profiled_thread);
892 } 1052 }
893 1053
894 #endif // USE_SIGNALS 1054 #endif // USE_SIGNALS
895 1055
896 1056
897 } // namespace internal 1057 } // namespace internal
898 } // namespace v8 1058 } // namespace v8
OLDNEW
« src/profiler/sampler.h ('K') | « src/profiler/sampler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698