OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 return; | 724 return; |
725 } | 725 } |
726 if (v8::Locker::IsActive() && | 726 if (v8::Locker::IsActive() && |
727 !isolate->thread_manager()->IsLockedByCurrentThread()) { | 727 !isolate->thread_manager()->IsLockedByCurrentThread()) { |
728 return; | 728 return; |
729 } | 729 } |
730 | 730 |
731 Sampler* sampler = isolate->logger()->sampler(); | 731 Sampler* sampler = isolate->logger()->sampler(); |
732 if (sampler == NULL || !sampler->IsActive()) return; | 732 if (sampler == NULL || !sampler->IsActive()) return; |
733 | 733 |
734 TickSample* sample = CpuProfiler::StartTickSampleEvent(isolate); | 734 TickSample sample_obj; |
735 if (sample == NULL) return; | 735 TickSample* sample = CpuProfiler::TickSampleEvent(isolate); |
| 736 if (sample == NULL) sample = &sample_obj; |
736 | 737 |
737 // Extracting the sample from the context is extremely machine dependent. | 738 // Extracting the sample from the context is extremely machine dependent. |
738 sample->state = isolate->current_vm_state(); | 739 sample->state = isolate->current_vm_state(); |
739 ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context); | 740 ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context); |
740 #ifdef __NetBSD__ | 741 #ifdef __NetBSD__ |
741 mcontext_t& mcontext = ucontext->uc_mcontext; | 742 mcontext_t& mcontext = ucontext->uc_mcontext; |
742 #if V8_HOST_ARCH_IA32 | 743 #if V8_HOST_ARCH_IA32 |
743 sample->pc = reinterpret_cast<Address>(mcontext.__gregs[_REG_EIP]); | 744 sample->pc = reinterpret_cast<Address>(mcontext.__gregs[_REG_EIP]); |
744 sample->sp = reinterpret_cast<Address>(mcontext.__gregs[_REG_ESP]); | 745 sample->sp = reinterpret_cast<Address>(mcontext.__gregs[_REG_ESP]); |
745 sample->fp = reinterpret_cast<Address>(mcontext.__gregs[_REG_EBP]); | 746 sample->fp = reinterpret_cast<Address>(mcontext.__gregs[_REG_EBP]); |
746 #elif V8_HOST_ARCH_X64 | 747 #elif V8_HOST_ARCH_X64 |
747 sample->pc = reinterpret_cast<Address>(mcontext.__gregs[_REG_RIP]); | 748 sample->pc = reinterpret_cast<Address>(mcontext.__gregs[_REG_RIP]); |
748 sample->sp = reinterpret_cast<Address>(mcontext.__gregs[_REG_RSP]); | 749 sample->sp = reinterpret_cast<Address>(mcontext.__gregs[_REG_RSP]); |
749 sample->fp = reinterpret_cast<Address>(mcontext.__gregs[_REG_RBP]); | 750 sample->fp = reinterpret_cast<Address>(mcontext.__gregs[_REG_RBP]); |
750 #endif // V8_HOST_ARCH | 751 #endif // V8_HOST_ARCH |
751 #else // OpenBSD | 752 #else // OpenBSD |
752 #if V8_HOST_ARCH_IA32 | 753 #if V8_HOST_ARCH_IA32 |
753 sample->pc = reinterpret_cast<Address>(ucontext->sc_eip); | 754 sample->pc = reinterpret_cast<Address>(ucontext->sc_eip); |
754 sample->sp = reinterpret_cast<Address>(ucontext->sc_esp); | 755 sample->sp = reinterpret_cast<Address>(ucontext->sc_esp); |
755 sample->fp = reinterpret_cast<Address>(ucontext->sc_ebp); | 756 sample->fp = reinterpret_cast<Address>(ucontext->sc_ebp); |
756 #elif V8_HOST_ARCH_X64 | 757 #elif V8_HOST_ARCH_X64 |
757 sample->pc = reinterpret_cast<Address>(ucontext->sc_rip); | 758 sample->pc = reinterpret_cast<Address>(ucontext->sc_rip); |
758 sample->sp = reinterpret_cast<Address>(ucontext->sc_rsp); | 759 sample->sp = reinterpret_cast<Address>(ucontext->sc_rsp); |
759 sample->fp = reinterpret_cast<Address>(ucontext->sc_rbp); | 760 sample->fp = reinterpret_cast<Address>(ucontext->sc_rbp); |
760 #endif // V8_HOST_ARCH | 761 #endif // V8_HOST_ARCH |
761 #endif // __NetBSD__ | 762 #endif // __NetBSD__ |
762 sampler->SampleStack(sample); | 763 sampler->SampleStack(sample); |
763 sampler->Tick(sample); | 764 sampler->Tick(sample); |
764 CpuProfiler::FinishTickSampleEvent(isolate); | |
765 } | 765 } |
766 | 766 |
767 | 767 |
768 class Sampler::PlatformData : public Malloced { | 768 class Sampler::PlatformData : public Malloced { |
769 public: | 769 public: |
770 PlatformData() : vm_tid_(GetThreadID()) {} | 770 PlatformData() : vm_tid_(GetThreadID()) {} |
771 | 771 |
772 pthread_t vm_tid() const { return vm_tid_; } | 772 pthread_t vm_tid() const { return vm_tid_; } |
773 | 773 |
774 private: | 774 private: |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 data_ = new PlatformData; | 957 data_ = new PlatformData; |
958 } | 958 } |
959 | 959 |
960 | 960 |
961 Sampler::~Sampler() { | 961 Sampler::~Sampler() { |
962 ASSERT(!IsActive()); | 962 ASSERT(!IsActive()); |
963 delete data_; | 963 delete data_; |
964 } | 964 } |
965 | 965 |
966 | 966 |
967 void Sampler::DoSample() { | |
968 // TODO(rogulenko): implement | |
969 } | |
970 | |
971 | |
972 void Sampler::Start() { | 967 void Sampler::Start() { |
973 ASSERT(!IsActive()); | 968 ASSERT(!IsActive()); |
974 SetActive(true); | 969 SetActive(true); |
975 SignalSender::AddActiveSampler(this); | 970 SignalSender::AddActiveSampler(this); |
976 } | 971 } |
977 | 972 |
978 | 973 |
979 void Sampler::Stop() { | 974 void Sampler::Stop() { |
980 ASSERT(IsActive()); | 975 ASSERT(IsActive()); |
981 SignalSender::RemoveActiveSampler(this); | 976 SignalSender::RemoveActiveSampler(this); |
982 SetActive(false); | 977 SetActive(false); |
983 } | 978 } |
984 | 979 |
985 | 980 |
986 } } // namespace v8::internal | 981 } } // namespace v8::internal |
OLD | NEW |