| 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" | |
| 46 #include "src/base/platform/platform.h" | 45 #include "src/base/platform/platform.h" |
| 47 #include "src/flags.h" | 46 #include "src/flags.h" |
| 48 #include "src/frames-inl.h" | 47 #include "src/frames-inl.h" |
| 49 #include "src/log.h" | 48 #include "src/log.h" |
| 50 #include "src/profiler/cpu-profiler-inl.h" | 49 #include "src/profiler/cpu-profiler-inl.h" |
| 51 #include "src/simulator.h" | 50 #include "src/simulator.h" |
| 52 #include "src/v8threads.h" | 51 #include "src/v8threads.h" |
| 53 #include "src/vm-state-inl.h" | 52 #include "src/vm-state-inl.h" |
| 54 | 53 |
| 55 | 54 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 // pessimistically assume it could be the entire pattern match. | 229 // pessimistically assume it could be the entire pattern match. |
| 231 MSAN_MEMORY_IS_INITIALIZED(pc, pattern->bytes_count - offset); | 230 MSAN_MEMORY_IS_INITIALIZED(pc, pattern->bytes_count - offset); |
| 232 if (!memcmp(pc, pattern->bytes + offset, pattern->bytes_count - offset)) | 231 if (!memcmp(pc, pattern->bytes + offset, pattern->bytes_count - offset)) |
| 233 return true; | 232 return true; |
| 234 } | 233 } |
| 235 } | 234 } |
| 236 } | 235 } |
| 237 return false; | 236 return false; |
| 238 } | 237 } |
| 239 | 238 |
| 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 | |
| 284 } // namespace | 239 } // namespace |
| 285 | 240 |
| 286 #if defined(USE_SIGNALS) | 241 #if defined(USE_SIGNALS) |
| 287 | 242 |
| 288 class Sampler::PlatformData : public PlatformDataCommon { | 243 class Sampler::PlatformData : public PlatformDataCommon { |
| 289 public: | 244 public: |
| 290 PlatformData() : vm_tid_(pthread_self()) {} | 245 PlatformData() : vm_tid_(pthread_self()) {} |
| 291 pthread_t vm_tid() const { return vm_tid_; } | 246 pthread_t vm_tid() const { return vm_tid_; } |
| 292 | 247 |
| 293 private: | 248 private: |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 | 367 |
| 413 static void DecreaseSamplerCount() { | 368 static void DecreaseSamplerCount() { |
| 414 base::LockGuard<base::Mutex> lock_guard(mutex_); | 369 base::LockGuard<base::Mutex> lock_guard(mutex_); |
| 415 if (--client_count_ == 0) Restore(); | 370 if (--client_count_ == 0) Restore(); |
| 416 } | 371 } |
| 417 | 372 |
| 418 static bool Installed() { | 373 static bool Installed() { |
| 419 return signal_handler_installed_; | 374 return signal_handler_installed_; |
| 420 } | 375 } |
| 421 | 376 |
| 422 #if !V8_OS_NACL | |
| 423 static void CollectSample(void* context, Sampler* sampler); | |
| 424 #endif | |
| 425 | |
| 426 private: | 377 private: |
| 427 static void Install() { | 378 static void Install() { |
| 428 #if !V8_OS_NACL | 379 #if !V8_OS_NACL |
| 429 struct sigaction sa; | 380 struct sigaction sa; |
| 430 sa.sa_sigaction = &HandleProfilerSignal; | 381 sa.sa_sigaction = &HandleProfilerSignal; |
| 431 sigemptyset(&sa.sa_mask); | 382 sigemptyset(&sa.sa_mask); |
| 432 #if V8_OS_QNX | 383 #if V8_OS_QNX |
| 433 sa.sa_flags = SA_SIGINFO; | 384 sa.sa_flags = SA_SIGINFO; |
| 434 #else | 385 #else |
| 435 sa.sa_flags = SA_RESTART | SA_SIGINFO; | 386 sa.sa_flags = SA_RESTART | SA_SIGINFO; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 460 | 411 |
| 461 | 412 |
| 462 base::Mutex* SignalHandler::mutex_ = NULL; | 413 base::Mutex* SignalHandler::mutex_ = NULL; |
| 463 int SignalHandler::client_count_ = 0; | 414 int SignalHandler::client_count_ = 0; |
| 464 struct sigaction SignalHandler::old_signal_handler_; | 415 struct sigaction SignalHandler::old_signal_handler_; |
| 465 bool SignalHandler::signal_handler_installed_ = false; | 416 bool SignalHandler::signal_handler_installed_ = false; |
| 466 | 417 |
| 467 | 418 |
| 468 // As Native Client does not support signal handling, profiling is disabled. | 419 // As Native Client does not support signal handling, profiling is disabled. |
| 469 #if !V8_OS_NACL | 420 #if !V8_OS_NACL |
| 470 void SignalHandler::CollectSample(void* context, Sampler* sampler) { | 421 void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info, |
| 471 if (sampler == NULL || (!sampler->IsProfiling() && | 422 void* context) { |
| 472 !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. |
| 473 return; | 428 return; |
| 474 } | 429 } |
| 475 Isolate* isolate = sampler->isolate(); | |
| 476 | |
| 477 // We require a fully initialized and entered isolate. | |
| 478 if (isolate == NULL || !isolate->IsInUse()) return; | |
| 479 | |
| 480 if (v8::Locker::IsActive() && | 430 if (v8::Locker::IsActive() && |
| 481 !isolate->thread_manager()->IsLockedByCurrentThread()) { | 431 !isolate->thread_manager()->IsLockedByCurrentThread()) { |
| 482 return; | 432 return; |
| 483 } | 433 } |
| 484 | 434 |
| 435 Sampler* sampler = isolate->logger()->sampler(); |
| 436 if (sampler == NULL) return; |
| 437 |
| 485 v8::RegisterState state; | 438 v8::RegisterState state; |
| 486 | 439 |
| 487 #if defined(USE_SIMULATOR) | 440 #if defined(USE_SIMULATOR) |
| 488 SimulatorHelper helper; | 441 SimulatorHelper helper; |
| 489 if (!helper.Init(isolate)) return; | 442 if (!helper.Init(isolate)) return; |
| 490 helper.FillRegisters(&state); | 443 helper.FillRegisters(&state); |
| 491 // It possible that the simulator is interrupted while it is updating | 444 // It possible that the simulator is interrupted while it is updating |
| 492 // the sp or fp register. ARM64 simulator does this in two steps: | 445 // the sp or fp register. ARM64 simulator does this in two steps: |
| 493 // first setting it to zero and then setting it to the new value. | 446 // first setting it to zero and then setting it to the new value. |
| 494 // Bailout if sp/fp doesn't contain the new value. | 447 // Bailout if sp/fp doesn't contain the new value. |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 #elif V8_OS_AIX | 575 #elif V8_OS_AIX |
| 623 state.pc = reinterpret_cast<Address>(mcontext.jmp_context.iar); | 576 state.pc = reinterpret_cast<Address>(mcontext.jmp_context.iar); |
| 624 state.sp = reinterpret_cast<Address>(mcontext.jmp_context.gpr[1]); | 577 state.sp = reinterpret_cast<Address>(mcontext.jmp_context.gpr[1]); |
| 625 state.fp = reinterpret_cast<Address>(mcontext.jmp_context.gpr[31]); | 578 state.fp = reinterpret_cast<Address>(mcontext.jmp_context.gpr[31]); |
| 626 #endif // V8_OS_AIX | 579 #endif // V8_OS_AIX |
| 627 #endif // USE_SIMULATOR | 580 #endif // USE_SIMULATOR |
| 628 sampler->SampleStack(state); | 581 sampler->SampleStack(state); |
| 629 } | 582 } |
| 630 #endif // V8_OS_NACL | 583 #endif // V8_OS_NACL |
| 631 | 584 |
| 632 #endif // USE_SIGNALS | 585 #endif |
| 633 | 586 |
| 634 | 587 |
| 635 class SamplerThread : public base::Thread { | 588 class SamplerThread : public base::Thread { |
| 636 public: | 589 public: |
| 637 static const int kSamplerThreadStackSize = 64 * KB; | 590 static const int kSamplerThreadStackSize = 64 * KB; |
| 638 | 591 |
| 639 explicit SamplerThread(int interval) | 592 explicit SamplerThread(int interval) |
| 640 : Thread(base::Thread::Options("SamplerThread", kSamplerThreadStackSize)), | 593 : Thread(base::Thread::Options("SamplerThread", kSamplerThreadStackSize)), |
| 641 interval_(interval) {} | 594 interval_(interval) {} |
| 642 | 595 |
| 643 static void SetUp() { if (!mutex_) mutex_ = new base::Mutex(); } | 596 static void SetUp() { if (!mutex_) mutex_ = new base::Mutex(); } |
| 644 static void TearDown() { delete mutex_; mutex_ = NULL; } | 597 static void TearDown() { delete mutex_; mutex_ = NULL; } |
| 645 | 598 |
| 646 static void AddActiveSampler(Sampler* sampler) { | 599 static void AddActiveSampler(Sampler* sampler) { |
| 647 bool need_to_start = false; | 600 bool need_to_start = false; |
| 648 base::LockGuard<base::Mutex> lock_guard(mutex_); | 601 base::LockGuard<base::Mutex> lock_guard(mutex_); |
| 649 if (instance_ == NULL) { | 602 if (instance_ == NULL) { |
| 650 // Start a thread that will send SIGPROF signal to VM threads, | 603 // Start a thread that will send SIGPROF signal to VM threads, |
| 651 // when CPU profiling will be enabled. | 604 // when CPU profiling will be enabled. |
| 652 instance_ = new SamplerThread(sampler->interval()); | 605 instance_ = new SamplerThread(sampler->interval()); |
| 653 need_to_start = true; | 606 need_to_start = true; |
| 654 } | 607 } |
| 655 | 608 |
| 656 DCHECK(sampler->IsActive()); | 609 DCHECK(sampler->IsActive()); |
| 610 DCHECK(!instance_->active_samplers_.Contains(sampler)); |
| 657 DCHECK(instance_->interval_ == sampler->interval()); | 611 DCHECK(instance_->interval_ == sampler->interval()); |
| 658 | |
| 659 #if defined(USE_SIGNALS) | |
| 660 AddSampler(sampler); | |
| 661 #else | |
| 662 DCHECK(!instance_->active_samplers_.Contains(sampler)); | |
| 663 instance_->active_samplers_.Add(sampler); | 612 instance_->active_samplers_.Add(sampler); |
| 664 #endif // USE_SIGNALS | |
| 665 | 613 |
| 666 if (need_to_start) instance_->StartSynchronously(); | 614 if (need_to_start) instance_->StartSynchronously(); |
| 667 } | 615 } |
| 668 | 616 |
| 669 static void RemoveSampler(Sampler* sampler) { | 617 static void RemoveActiveSampler(Sampler* sampler) { |
| 670 SamplerThread* instance_to_remove = NULL; | 618 SamplerThread* instance_to_remove = NULL; |
| 671 { | 619 { |
| 672 base::LockGuard<base::Mutex> lock_guard(mutex_); | 620 base::LockGuard<base::Mutex> lock_guard(mutex_); |
| 673 | 621 |
| 674 DCHECK(sampler->IsActive() || sampler->IsRegistered()); | 622 DCHECK(sampler->IsActive()); |
| 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 | |
| 697 bool removed = instance_->active_samplers_.RemoveElement(sampler); | 623 bool removed = instance_->active_samplers_.RemoveElement(sampler); |
| 698 DCHECK(removed); | 624 DCHECK(removed); |
| 699 USE(removed); | 625 USE(removed); |
| 700 | 626 |
| 701 // We cannot delete the instance immediately as we need to Join() the | 627 // We cannot delete the instance immediately as we need to Join() the |
| 702 // thread but we are holding mutex_ and the thread may try to acquire it. | 628 // thread but we are holding mutex_ and the thread may try to acquire it. |
| 703 if (instance_->active_samplers_.is_empty()) { | 629 if (instance_->active_samplers_.is_empty()) { |
| 704 instance_to_remove = instance_; | 630 instance_to_remove = instance_; |
| 705 instance_ = NULL; | 631 instance_ = NULL; |
| 706 } | 632 } |
| 707 #endif // USE_SIGNALS | |
| 708 } | 633 } |
| 709 | 634 |
| 710 if (!instance_to_remove) return; | 635 if (!instance_to_remove) return; |
| 711 instance_to_remove->Join(); | 636 instance_to_remove->Join(); |
| 712 delete instance_to_remove; | 637 delete instance_to_remove; |
| 713 } | 638 } |
| 714 | 639 |
| 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 | |
| 724 // Implement Thread::Run(). | 640 // Implement Thread::Run(). |
| 725 virtual void Run() { | 641 virtual void Run() { |
| 726 while (true) { | 642 while (true) { |
| 727 { | 643 { |
| 728 base::LockGuard<base::Mutex> lock_guard(mutex_); | 644 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 | |
| 739 if (active_samplers_.is_empty()) break; | 645 if (active_samplers_.is_empty()) break; |
| 740 // When CPU profiling is enabled both JavaScript and C++ code is | 646 // When CPU profiling is enabled both JavaScript and C++ code is |
| 741 // profiled. We must not suspend. | 647 // profiled. We must not suspend. |
| 742 for (int i = 0; i < active_samplers_.length(); ++i) { | 648 for (int i = 0; i < active_samplers_.length(); ++i) { |
| 743 Sampler* sampler = active_samplers_.at(i); | 649 Sampler* sampler = active_samplers_.at(i); |
| 744 if (!sampler->IsProfiling()) continue; | 650 if (!sampler->IsProfiling()) continue; |
| 745 sampler->DoSample(); | 651 sampler->DoSample(); |
| 746 } | 652 } |
| 747 #endif // USE_SIGNALS | |
| 748 } | 653 } |
| 749 base::OS::Sleep(base::TimeDelta::FromMilliseconds(interval_)); | 654 base::OS::Sleep(base::TimeDelta::FromMilliseconds(interval_)); |
| 750 } | 655 } |
| 751 } | 656 } |
| 752 | 657 |
| 753 private: | 658 private: |
| 754 // Protects the process wide state below. | 659 // Protects the process wide state below. |
| 755 static base::Mutex* mutex_; | 660 static base::Mutex* mutex_; |
| 756 static SamplerThread* instance_; | 661 static SamplerThread* instance_; |
| 757 | 662 |
| 758 const int interval_; | 663 const int interval_; |
| 759 | 664 List<Sampler*> active_samplers_; |
| 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 | |
| 791 | 665 |
| 792 DISALLOW_COPY_AND_ASSIGN(SamplerThread); | 666 DISALLOW_COPY_AND_ASSIGN(SamplerThread); |
| 793 }; | 667 }; |
| 794 | 668 |
| 795 | 669 |
| 796 base::Mutex* SamplerThread::mutex_ = NULL; | 670 base::Mutex* SamplerThread::mutex_ = NULL; |
| 797 SamplerThread* SamplerThread::instance_ = NULL; | 671 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 | |
| 825 | 672 |
| 826 | 673 |
| 827 // | 674 // |
| 828 // StackTracer implementation | 675 // StackTracer implementation |
| 829 // | 676 // |
| 830 DISABLE_ASAN void TickSample::Init(Isolate* isolate, | 677 DISABLE_ASAN void TickSample::Init(Isolate* isolate, |
| 831 const v8::RegisterState& regs, | 678 const v8::RegisterState& regs, |
| 832 RecordCEntryFrame record_c_entry_frame, | 679 RecordCEntryFrame record_c_entry_frame, |
| 833 bool update_stats) { | 680 bool update_stats) { |
| 834 timestamp = base::TimeTicks::HighResolutionNow(); | 681 timestamp = base::TimeTicks::HighResolutionNow(); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 935 SignalHandler::TearDown(); | 782 SignalHandler::TearDown(); |
| 936 #endif | 783 #endif |
| 937 } | 784 } |
| 938 | 785 |
| 939 Sampler::Sampler(Isolate* isolate, int interval) | 786 Sampler::Sampler(Isolate* isolate, int interval) |
| 940 : isolate_(isolate), | 787 : isolate_(isolate), |
| 941 interval_(interval), | 788 interval_(interval), |
| 942 profiling_(false), | 789 profiling_(false), |
| 943 has_processing_thread_(false), | 790 has_processing_thread_(false), |
| 944 active_(false), | 791 active_(false), |
| 945 registered_(false), | |
| 946 is_counting_samples_(false), | 792 is_counting_samples_(false), |
| 947 js_sample_count_(0), | 793 js_sample_count_(0), |
| 948 external_sample_count_(0) { | 794 external_sample_count_(0) { |
| 949 data_ = new PlatformData; | 795 data_ = new PlatformData; |
| 950 } | 796 } |
| 951 | 797 |
| 952 Sampler::~Sampler() { | 798 Sampler::~Sampler() { |
| 953 DCHECK(!IsActive()); | 799 DCHECK(!IsActive()); |
| 954 if (IsRegistered()) { | |
| 955 SamplerThread::RemoveSampler(this); | |
| 956 } | |
| 957 delete data_; | 800 delete data_; |
| 958 } | 801 } |
| 959 | 802 |
| 960 void Sampler::Start() { | 803 void Sampler::Start() { |
| 961 DCHECK(!IsActive()); | 804 DCHECK(!IsActive()); |
| 962 SetActive(true); | 805 SetActive(true); |
| 963 SamplerThread::AddActiveSampler(this); | 806 SamplerThread::AddActiveSampler(this); |
| 964 } | 807 } |
| 965 | 808 |
| 966 | 809 |
| 967 void Sampler::Stop() { | 810 void Sampler::Stop() { |
| 968 DCHECK(IsActive()); | 811 DCHECK(IsActive()); |
| 969 SamplerThread::RemoveSampler(this); | 812 SamplerThread::RemoveActiveSampler(this); |
| 970 SetActive(false); | 813 SetActive(false); |
| 971 SetRegistered(false); | |
| 972 } | 814 } |
| 973 | 815 |
| 974 | 816 |
| 975 void Sampler::IncreaseProfilingDepth() { | 817 void Sampler::IncreaseProfilingDepth() { |
| 976 base::NoBarrier_AtomicIncrement(&profiling_, 1); | 818 base::NoBarrier_AtomicIncrement(&profiling_, 1); |
| 977 #if defined(USE_SIGNALS) | 819 #if defined(USE_SIGNALS) |
| 978 SignalHandler::IncreaseSamplerCount(); | 820 SignalHandler::IncreaseSamplerCount(); |
| 979 #endif | 821 #endif |
| 980 } | 822 } |
| 981 | 823 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1001 if (sample != &sample_obj) { | 843 if (sample != &sample_obj) { |
| 1002 isolate_->cpu_profiler()->FinishTickSample(); | 844 isolate_->cpu_profiler()->FinishTickSample(); |
| 1003 } | 845 } |
| 1004 } | 846 } |
| 1005 | 847 |
| 1006 | 848 |
| 1007 #if defined(USE_SIGNALS) | 849 #if defined(USE_SIGNALS) |
| 1008 | 850 |
| 1009 void Sampler::DoSample() { | 851 void Sampler::DoSample() { |
| 1010 if (!SignalHandler::Installed()) return; | 852 if (!SignalHandler::Installed()) return; |
| 1011 if (!IsActive() && !IsRegistered()) { | |
| 1012 SamplerThread::RegisterSampler(this); | |
| 1013 SetRegistered(true); | |
| 1014 } | |
| 1015 pthread_kill(platform_data()->vm_tid(), SIGPROF); | 853 pthread_kill(platform_data()->vm_tid(), SIGPROF); |
| 1016 } | 854 } |
| 1017 | 855 |
| 1018 #elif V8_OS_WIN || V8_OS_CYGWIN | 856 #elif V8_OS_WIN || V8_OS_CYGWIN |
| 1019 | 857 |
| 1020 void Sampler::DoSample() { | 858 void Sampler::DoSample() { |
| 1021 HANDLE profiled_thread = platform_data()->profiled_thread(); | 859 HANDLE profiled_thread = platform_data()->profiled_thread(); |
| 1022 if (profiled_thread == NULL) return; | 860 if (profiled_thread == NULL) return; |
| 1023 | 861 |
| 1024 #if defined(USE_SIMULATOR) | 862 #if defined(USE_SIMULATOR) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1051 SampleStack(state); | 889 SampleStack(state); |
| 1052 } | 890 } |
| 1053 ResumeThread(profiled_thread); | 891 ResumeThread(profiled_thread); |
| 1054 } | 892 } |
| 1055 | 893 |
| 1056 #endif // USE_SIGNALS | 894 #endif // USE_SIGNALS |
| 1057 | 895 |
| 1058 | 896 |
| 1059 } // namespace internal | 897 } // namespace internal |
| 1060 } // namespace v8 | 898 } // namespace v8 |
| OLD | NEW |