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

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
« no previous file with comments | « src/profiler/sampler.h ('k') | tools/check-static-initializers.sh » ('j') | 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 AtomicGuard(bool is_block, AtomicValue<int>* atomic,
alph 2016/04/07 22:38:16 nit: why did you swap the arguments? is_blocking s
lpy 2016/04/07 23:19:19 Done.
246 int expected = 0, int desired = 1)
alph 2016/04/07 22:38:17 just drop these. if at some point in the future th
lpy 2016/04/07 23:19:19 Done.
247 : atomic_(atomic),
248 expected_(expected),
249 is_success_(false) {
250 do {
251 is_success_ = atomic_->TrySetValue(expected, desired);
252 if (is_success_) break;
253 } while (is_block);
alph 2016/04/07 22:38:17 still, why don't you want to change it to: do { }
lpy 2016/04/07 23:19:19 Done.
254 }
255
256 bool is_success() { return is_success_; }
257
258 ~AtomicGuard() {
259 if (is_success_) {
260 atomic_->SetValue(expected_);
261 }
262 atomic_ = NULL;
263 }
264
265 private:
266 AtomicValue<int>* atomic_;
267 int expected_;
268 bool is_success_;
269 };
270 #endif // USE_SIGNALS
271
239 } // namespace 272 } // namespace
240 273
241 #if defined(USE_SIGNALS) 274 #if defined(USE_SIGNALS)
242 275
243 class Sampler::PlatformData : public PlatformDataCommon { 276 class Sampler::PlatformData : public PlatformDataCommon {
244 public: 277 public:
245 PlatformData() : vm_tid_(pthread_self()) {} 278 PlatformData() : vm_tid_(pthread_self()) {}
246 pthread_t vm_tid() const { return vm_tid_; } 279 pthread_t vm_tid() const { return vm_tid_; }
247 280
248 private: 281 private:
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 400
368 static void DecreaseSamplerCount() { 401 static void DecreaseSamplerCount() {
369 base::LockGuard<base::Mutex> lock_guard(mutex_); 402 base::LockGuard<base::Mutex> lock_guard(mutex_);
370 if (--client_count_ == 0) Restore(); 403 if (--client_count_ == 0) Restore();
371 } 404 }
372 405
373 static bool Installed() { 406 static bool Installed() {
374 return signal_handler_installed_; 407 return signal_handler_installed_;
375 } 408 }
376 409
410 #if !V8_OS_NACL
411 static void CollectSample(void* context, Sampler* sampler);
412 #endif
413
377 private: 414 private:
378 static void Install() { 415 static void Install() {
379 #if !V8_OS_NACL 416 #if !V8_OS_NACL
380 struct sigaction sa; 417 struct sigaction sa;
381 sa.sa_sigaction = &HandleProfilerSignal; 418 sa.sa_sigaction = &HandleProfilerSignal;
382 sigemptyset(&sa.sa_mask); 419 sigemptyset(&sa.sa_mask);
383 #if V8_OS_QNX 420 #if V8_OS_QNX
384 sa.sa_flags = SA_SIGINFO; 421 sa.sa_flags = SA_SIGINFO;
385 #else 422 #else
386 sa.sa_flags = SA_RESTART | SA_SIGINFO; 423 sa.sa_flags = SA_RESTART | SA_SIGINFO;
(...skipping 24 matching lines...) Expand all
411 448
412 449
413 base::Mutex* SignalHandler::mutex_ = NULL; 450 base::Mutex* SignalHandler::mutex_ = NULL;
414 int SignalHandler::client_count_ = 0; 451 int SignalHandler::client_count_ = 0;
415 struct sigaction SignalHandler::old_signal_handler_; 452 struct sigaction SignalHandler::old_signal_handler_;
416 bool SignalHandler::signal_handler_installed_ = false; 453 bool SignalHandler::signal_handler_installed_ = false;
417 454
418 455
419 // As Native Client does not support signal handling, profiling is disabled. 456 // As Native Client does not support signal handling, profiling is disabled.
420 #if !V8_OS_NACL 457 #if !V8_OS_NACL
421 void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info, 458 void SignalHandler::CollectSample(void* context, Sampler* sampler) {
422 void* context) { 459 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; 460 return;
429 } 461 Isolate* isolate = sampler->isolate();
462
463 // We require a fully initialized and entered isolate.
464 if (isolate == NULL || !isolate->IsInUse()) return;
465
430 if (v8::Locker::IsActive() && 466 if (v8::Locker::IsActive() &&
431 !isolate->thread_manager()->IsLockedByCurrentThread()) { 467 !isolate->thread_manager()->IsLockedByCurrentThread()) {
432 return; 468 return;
433 } 469 }
434 470
435 Sampler* sampler = isolate->logger()->sampler();
436 if (sampler == NULL) return;
437
438 v8::RegisterState state; 471 v8::RegisterState state;
439 472
440 #if defined(USE_SIMULATOR) 473 #if defined(USE_SIMULATOR)
441 SimulatorHelper helper; 474 SimulatorHelper helper;
442 if (!helper.Init(isolate)) return; 475 if (!helper.Init(isolate)) return;
443 helper.FillRegisters(&state); 476 helper.FillRegisters(&state);
444 // It possible that the simulator is interrupted while it is updating 477 // It possible that the simulator is interrupted while it is updating
445 // the sp or fp register. ARM64 simulator does this in two steps: 478 // 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. 479 // first setting it to zero and then setting it to the new value.
447 // Bailout if sp/fp doesn't contain the new value. 480 // 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 608 #elif V8_OS_AIX
576 state.pc = reinterpret_cast<Address>(mcontext.jmp_context.iar); 609 state.pc = reinterpret_cast<Address>(mcontext.jmp_context.iar);
577 state.sp = reinterpret_cast<Address>(mcontext.jmp_context.gpr[1]); 610 state.sp = reinterpret_cast<Address>(mcontext.jmp_context.gpr[1]);
578 state.fp = reinterpret_cast<Address>(mcontext.jmp_context.gpr[31]); 611 state.fp = reinterpret_cast<Address>(mcontext.jmp_context.gpr[31]);
579 #endif // V8_OS_AIX 612 #endif // V8_OS_AIX
580 #endif // USE_SIMULATOR 613 #endif // USE_SIMULATOR
581 sampler->SampleStack(state); 614 sampler->SampleStack(state);
582 } 615 }
583 #endif // V8_OS_NACL 616 #endif // V8_OS_NACL
584 617
585 #endif 618 #endif // USE_SIGNALS
586 619
587 620
588 class SamplerThread : public base::Thread { 621 class SamplerThread : public base::Thread {
589 public: 622 public:
590 static const int kSamplerThreadStackSize = 64 * KB; 623 static const int kSamplerThreadStackSize = 64 * KB;
591 624
592 explicit SamplerThread(int interval) 625 explicit SamplerThread(int interval)
593 : Thread(base::Thread::Options("SamplerThread", kSamplerThreadStackSize)), 626 : Thread(base::Thread::Options("SamplerThread", kSamplerThreadStackSize)),
594 interval_(interval) {} 627 interval_(interval) {}
595 628
596 static void SetUp() { if (!mutex_) mutex_ = new base::Mutex(); } 629 static void SetUp() { if (!mutex_) mutex_ = new base::Mutex(); }
597 static void TearDown() { delete mutex_; mutex_ = NULL; } 630 static void TearDown() { delete mutex_; mutex_ = NULL; }
598 631
599 static void AddActiveSampler(Sampler* sampler) { 632 static void AddActiveSampler(Sampler* sampler) {
600 bool need_to_start = false; 633 bool need_to_start = false;
601 base::LockGuard<base::Mutex> lock_guard(mutex_); 634 base::LockGuard<base::Mutex> lock_guard(mutex_);
602 if (instance_ == NULL) { 635 if (instance_ == NULL) {
603 // Start a thread that will send SIGPROF signal to VM threads, 636 // Start a thread that will send SIGPROF signal to VM threads,
604 // when CPU profiling will be enabled. 637 // when CPU profiling will be enabled.
605 instance_ = new SamplerThread(sampler->interval()); 638 instance_ = new SamplerThread(sampler->interval());
606 need_to_start = true; 639 need_to_start = true;
607 } 640 }
608 641
609 DCHECK(sampler->IsActive()); 642 DCHECK(sampler->IsActive());
643 DCHECK(instance_->interval_ == sampler->interval());
644
645 #if defined(USE_SIGNALS)
646 AddSampler(sampler);
647 #else
610 DCHECK(!instance_->active_samplers_.Contains(sampler)); 648 DCHECK(!instance_->active_samplers_.Contains(sampler));
611 DCHECK(instance_->interval_ == sampler->interval());
612 instance_->active_samplers_.Add(sampler); 649 instance_->active_samplers_.Add(sampler);
650 #endif // USE_SIGNALS
613 651
614 if (need_to_start) instance_->StartSynchronously(); 652 if (need_to_start) instance_->StartSynchronously();
615 } 653 }
616 654
617 static void RemoveActiveSampler(Sampler* sampler) { 655 static void RemoveSampler(Sampler* sampler) {
618 SamplerThread* instance_to_remove = NULL; 656 SamplerThread* instance_to_remove = NULL;
619 { 657 {
620 base::LockGuard<base::Mutex> lock_guard(mutex_); 658 base::LockGuard<base::Mutex> lock_guard(mutex_);
621 659
622 DCHECK(sampler->IsActive()); 660 DCHECK(sampler->IsActive() || sampler->IsRegistered());
661 #if defined(USE_SIGNALS)
662 {
663 AtomicGuard atomic_guard(true, &sampler_list_access_counter_);
664 // Remove sampler from map.
665 pthread_t thread_id = sampler->platform_data()->vm_tid();
666 uint32_t profiled_thread_id =
667 sampler->platform_data()->profiled_thread_id().ToInteger();
668 HashMap::Entry* entry =
669 thread_id_to_samplers_.Lookup(reinterpret_cast<void*>(thread_id),
670 profiled_thread_id);
671 DCHECK(entry != NULL);
672 SamplerList* samplers = reinterpret_cast<SamplerList*>(entry->value);
673 samplers->RemoveElement(sampler);
674 if (samplers->is_empty()) {
675 thread_id_to_samplers_.Remove(reinterpret_cast<void*>(thread_id),
676 profiled_thread_id);
677 delete samplers;
678 }
679 if (thread_id_to_samplers_.occupancy() == 0) {
680 instance_to_remove = instance_;
681 instance_ = NULL;
682 }
683 }
684 #else
623 bool removed = instance_->active_samplers_.RemoveElement(sampler); 685 bool removed = instance_->active_samplers_.RemoveElement(sampler);
624 DCHECK(removed); 686 DCHECK(removed);
625 USE(removed); 687 USE(removed);
626 688
627 // We cannot delete the instance immediately as we need to Join() the 689 // 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. 690 // thread but we are holding mutex_ and the thread may try to acquire it.
629 if (instance_->active_samplers_.is_empty()) { 691 if (instance_->active_samplers_.is_empty()) {
630 instance_to_remove = instance_; 692 instance_to_remove = instance_;
631 instance_ = NULL; 693 instance_ = NULL;
632 } 694 }
695 #endif // USE_SIGNALS
633 } 696 }
634 697
635 if (!instance_to_remove) return; 698 if (!instance_to_remove) return;
636 instance_to_remove->Join(); 699 instance_to_remove->Join();
637 delete instance_to_remove; 700 delete instance_to_remove;
638 } 701 }
639 702
703 // Unlike AddActiveSampler, this method only adds a sampler,
704 // but won't start the sampler thread.
705 static void RegisterSampler(Sampler* sampler) {
706 base::LockGuard<base::Mutex> lock_guard(mutex_);
707 #if defined(USE_SIGNALS)
708 AddSampler(sampler);
709 #endif // USE_SIGNALS
710 }
711
640 // Implement Thread::Run(). 712 // Implement Thread::Run().
641 virtual void Run() { 713 virtual void Run() {
642 while (true) { 714 while (true) {
643 { 715 {
644 base::LockGuard<base::Mutex> lock_guard(mutex_); 716 base::LockGuard<base::Mutex> lock_guard(mutex_);
717 #if defined(USE_SIGNALS)
718 if (thread_id_to_samplers_.occupancy() == 0) break;
719 if (SignalHandler::Installed()) {
720 for (HashMap::Entry *p = thread_id_to_samplers_.Start(); p != NULL;
721 p = thread_id_to_samplers_.Next(p)) {
722 pthread_t thread_id = reinterpret_cast<pthread_t>(p->key);
723 pthread_kill(thread_id, SIGPROF);
724 }
725 }
726 #else
645 if (active_samplers_.is_empty()) break; 727 if (active_samplers_.is_empty()) break;
646 // When CPU profiling is enabled both JavaScript and C++ code is 728 // When CPU profiling is enabled both JavaScript and C++ code is
647 // profiled. We must not suspend. 729 // profiled. We must not suspend.
648 for (int i = 0; i < active_samplers_.length(); ++i) { 730 for (int i = 0; i < active_samplers_.length(); ++i) {
649 Sampler* sampler = active_samplers_.at(i); 731 Sampler* sampler = active_samplers_.at(i);
650 if (!sampler->IsProfiling()) continue; 732 if (!sampler->IsProfiling()) continue;
651 sampler->DoSample(); 733 sampler->DoSample();
652 } 734 }
735 #endif // USE_SIGNALS
653 } 736 }
654 base::OS::Sleep(base::TimeDelta::FromMilliseconds(interval_)); 737 base::OS::Sleep(base::TimeDelta::FromMilliseconds(interval_));
655 } 738 }
656 } 739 }
657 740
658 private: 741 private:
659 // Protects the process wide state below. 742 // Protects the process wide state below.
660 static base::Mutex* mutex_; 743 static base::Mutex* mutex_;
661 static SamplerThread* instance_; 744 static SamplerThread* instance_;
662 745
663 const int interval_; 746 const int interval_;
664 List<Sampler*> active_samplers_; 747
748 #if defined(USE_SIGNALS)
749 friend class SignalHandler;
750 static HashMap thread_id_to_samplers_;
751 static AtomicValue<int> sampler_list_access_counter_;
752 static void AddSampler(Sampler* sampler) {
753 AtomicGuard atomic_guard(true, &sampler_list_access_counter_);
754 // Add sampler into map if needed.
755 pthread_t thread_id = sampler->platform_data()->vm_tid();
756 HashMap::Entry *entry =
757 thread_id_to_samplers_.LookupOrInsert(
758 reinterpret_cast<void*>(thread_id),
759 sampler->platform_data()->profiled_thread_id().ToInteger());
760 if (entry->value == NULL) {
761 SamplerList* samplers = new SamplerList();
762 samplers->Add(sampler);
763 entry->value = samplers;
764 } else {
765 SamplerList* samplers = reinterpret_cast<SamplerList*>(entry->value);
766 if (!samplers->Contains(sampler)) {
767 samplers->Add(sampler);
768 }
769 }
770 }
771 #else
772 SamplerList active_samplers_;
773 #endif // USE_SIGNALS
665 774
666 DISALLOW_COPY_AND_ASSIGN(SamplerThread); 775 DISALLOW_COPY_AND_ASSIGN(SamplerThread);
667 }; 776 };
668 777
669 778
670 base::Mutex* SamplerThread::mutex_ = NULL; 779 base::Mutex* SamplerThread::mutex_ = NULL;
671 SamplerThread* SamplerThread::instance_ = NULL; 780 SamplerThread* SamplerThread::instance_ = NULL;
781 #if defined(USE_SIGNALS)
782 HashMap SamplerThread::thread_id_to_samplers_(HashMap::PointersMatch);
783 AtomicValue<int> SamplerThread::sampler_list_access_counter_(0);
784
785 // As Native Client does not support signal handling, profiling is disabled.
786 #if !V8_OS_NACL
787 void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info,
788 void* context) {
789 USE(info);
790 if (signal != SIGPROF) return;
791 AtomicGuard atomic_guard(false, &SamplerThread::sampler_list_access_counter_);
792 if (!atomic_guard.is_success()) return;
793 pthread_t thread_id = pthread_self();
794 HashMap::Entry* entry = NULL;
795 for (HashMap::Entry *p = SamplerThread::thread_id_to_samplers_.Start();
796 p != NULL; p = SamplerThread::thread_id_to_samplers_.Next(p)) {
797 if (pthread_equal(thread_id, reinterpret_cast<pthread_t>(p->key)) != 0) {
798 entry = p;
799 break;
800 }
801 }
802 if (entry == NULL) {
alph 2016/04/07 22:38:16 nit: drop {}
lpy 2016/04/07 23:19:19 Done.
803 return;
804 }
805 SamplerList* samplers = reinterpret_cast<SamplerList*>(entry->value);
806 for (int i = 0; i < samplers->length(); ++i) {
807 Sampler* sampler = samplers->at(i);
808 CollectSample(context, sampler);
809 }
810 }
811 #endif // !V8_OS_NACL
812 #endif // USE_SIGNALs
672 813
673 814
674 // 815 //
675 // StackTracer implementation 816 // StackTracer implementation
676 // 817 //
677 DISABLE_ASAN void TickSample::Init(Isolate* isolate, 818 DISABLE_ASAN void TickSample::Init(Isolate* isolate,
678 const v8::RegisterState& regs, 819 const v8::RegisterState& regs,
679 RecordCEntryFrame record_c_entry_frame, 820 RecordCEntryFrame record_c_entry_frame,
680 bool update_stats) { 821 bool update_stats) {
681 timestamp = base::TimeTicks::HighResolutionNow(); 822 timestamp = base::TimeTicks::HighResolutionNow();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 SignalHandler::TearDown(); 923 SignalHandler::TearDown();
783 #endif 924 #endif
784 } 925 }
785 926
786 Sampler::Sampler(Isolate* isolate, int interval) 927 Sampler::Sampler(Isolate* isolate, int interval)
787 : isolate_(isolate), 928 : isolate_(isolate),
788 interval_(interval), 929 interval_(interval),
789 profiling_(false), 930 profiling_(false),
790 has_processing_thread_(false), 931 has_processing_thread_(false),
791 active_(false), 932 active_(false),
933 registered_(false),
792 is_counting_samples_(false), 934 is_counting_samples_(false),
793 js_sample_count_(0), 935 js_sample_count_(0),
794 external_sample_count_(0) { 936 external_sample_count_(0) {
795 data_ = new PlatformData; 937 data_ = new PlatformData;
796 } 938 }
797 939
798 Sampler::~Sampler() { 940 Sampler::~Sampler() {
799 DCHECK(!IsActive()); 941 DCHECK(!IsActive());
942 if (IsRegistered()) {
943 SamplerThread::RemoveSampler(this);
944 }
800 delete data_; 945 delete data_;
801 } 946 }
802 947
803 void Sampler::Start() { 948 void Sampler::Start() {
804 DCHECK(!IsActive()); 949 DCHECK(!IsActive());
805 SetActive(true); 950 SetActive(true);
806 SamplerThread::AddActiveSampler(this); 951 SamplerThread::AddActiveSampler(this);
807 } 952 }
808 953
809 954
810 void Sampler::Stop() { 955 void Sampler::Stop() {
811 DCHECK(IsActive()); 956 DCHECK(IsActive());
812 SamplerThread::RemoveActiveSampler(this); 957 SamplerThread::RemoveSampler(this);
813 SetActive(false); 958 SetActive(false);
959 SetRegistered(false);
814 } 960 }
815 961
816 962
817 void Sampler::IncreaseProfilingDepth() { 963 void Sampler::IncreaseProfilingDepth() {
818 base::NoBarrier_AtomicIncrement(&profiling_, 1); 964 base::NoBarrier_AtomicIncrement(&profiling_, 1);
819 #if defined(USE_SIGNALS) 965 #if defined(USE_SIGNALS)
820 SignalHandler::IncreaseSamplerCount(); 966 SignalHandler::IncreaseSamplerCount();
821 #endif 967 #endif
822 } 968 }
823 969
(...skipping 19 matching lines...) Expand all
843 if (sample != &sample_obj) { 989 if (sample != &sample_obj) {
844 isolate_->cpu_profiler()->FinishTickSample(); 990 isolate_->cpu_profiler()->FinishTickSample();
845 } 991 }
846 } 992 }
847 993
848 994
849 #if defined(USE_SIGNALS) 995 #if defined(USE_SIGNALS)
850 996
851 void Sampler::DoSample() { 997 void Sampler::DoSample() {
852 if (!SignalHandler::Installed()) return; 998 if (!SignalHandler::Installed()) return;
999 if (!IsActive() && !IsRegistered()) {
1000 SamplerThread::RegisterSampler(this);
1001 SetRegistered(true);
1002 }
853 pthread_kill(platform_data()->vm_tid(), SIGPROF); 1003 pthread_kill(platform_data()->vm_tid(), SIGPROF);
854 } 1004 }
855 1005
856 #elif V8_OS_WIN || V8_OS_CYGWIN 1006 #elif V8_OS_WIN || V8_OS_CYGWIN
857 1007
858 void Sampler::DoSample() { 1008 void Sampler::DoSample() {
859 HANDLE profiled_thread = platform_data()->profiled_thread(); 1009 HANDLE profiled_thread = platform_data()->profiled_thread();
860 if (profiled_thread == NULL) return; 1010 if (profiled_thread == NULL) return;
861 1011
862 #if defined(USE_SIMULATOR) 1012 #if defined(USE_SIMULATOR)
(...skipping 26 matching lines...) Expand all
889 SampleStack(state); 1039 SampleStack(state);
890 } 1040 }
891 ResumeThread(profiled_thread); 1041 ResumeThread(profiled_thread);
892 } 1042 }
893 1043
894 #endif // USE_SIGNALS 1044 #endif // USE_SIGNALS
895 1045
896 1046
897 } // namespace internal 1047 } // namespace internal
898 } // namespace v8 1048 } // namespace v8
OLDNEW
« no previous file with comments | « src/profiler/sampler.h ('k') | tools/check-static-initializers.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698