From 62223bd2c0f7a12698f74a398cdb4c0e06e4b4d7 Mon Sep 17 00:00:00 2001 From: "jkummerow@chromium.org" Date: Wed, 17 Oct 2012 12:24:31 +0000 Subject: [PATCH] Revert recent CPU profiler changes because they broke --prof. This reverts r12649 and r12650. BUG=v8:2364 Review URL: https://codereview.chromium.org/11193020 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12745 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/cpu-profiler-inl.h | 16 ++--- src/cpu-profiler.cc | 90 +++++++++++------------ src/cpu-profiler.h | 28 +++----- src/flag-definitions.h | 4 -- src/platform-cygwin.cc | 11 +-- src/platform-freebsd.cc | 11 +-- src/platform-linux.cc | 151 ++++++++++++++++++++------------------- src/platform-macos.cc | 11 +-- src/platform-openbsd.cc | 11 +-- src/platform-solaris.cc | 11 +-- src/platform-win32.cc | 11 +-- src/platform.h | 3 - test/cctest/test-cpu-profiler.cc | 41 +++++------ 13 files changed, 166 insertions(+), 233 deletions(-) diff --git a/src/cpu-profiler-inl.h b/src/cpu-profiler-inl.h index 1133b20..4982197 100644 --- a/src/cpu-profiler-inl.h +++ b/src/cpu-profiler-inl.h @@ -31,6 +31,7 @@ #include "cpu-profiler.h" #include +#include "circular-queue-inl.h" #include "profile-generator-inl.h" #include "unbound-queue-inl.h" @@ -55,18 +56,11 @@ void SharedFunctionInfoMoveEventRecord::UpdateCodeMap(CodeMap* code_map) { } -TickSample* ProfilerEventsProcessor::StartTickSampleEvent() { - if (!ticks_buffer_is_empty_ || ticks_buffer_is_initialized_) return NULL; - ticks_buffer_is_initialized_ = true; +TickSample* ProfilerEventsProcessor::TickSampleEvent() { generator_->Tick(); - ticks_buffer_ = TickSampleEventRecord(enqueue_order_); - return &ticks_buffer_.sample; -} - - -void ProfilerEventsProcessor::FinishTickSampleEvent() { - ASSERT(ticks_buffer_is_initialized_ && ticks_buffer_is_empty_); - ticks_buffer_is_empty_ = false; + TickSampleEventRecord* evt = + new(ticks_buffer_.Enqueue()) TickSampleEventRecord(enqueue_order_); + return &evt->sample; } diff --git a/src/cpu-profiler.cc b/src/cpu-profiler.cc index 8f72c17..3cbac77 100644 --- a/src/cpu-profiler.cc +++ b/src/cpu-profiler.cc @@ -39,19 +39,19 @@ namespace v8 { namespace internal { +static const int kEventsBufferSize = 256 * KB; +static const int kTickSamplesBufferChunkSize = 64 * KB; +static const int kTickSamplesBufferChunksCount = 16; static const int kProfilerStackSize = 64 * KB; -ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator, - Sampler* sampler, - int period_in_useconds) +ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator) : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), generator_(generator), - sampler_(sampler), running_(true), - period_in_useconds_(period_in_useconds), - ticks_buffer_is_empty_(true), - ticks_buffer_is_initialized_(false), + ticks_buffer_(sizeof(TickSampleEventRecord), + kTickSamplesBufferChunkSize, + kTickSamplesBufferChunksCount), enqueue_order_(0) { } @@ -215,17 +215,23 @@ bool ProfilerEventsProcessor::ProcessTicks(unsigned dequeue_order) { generator_->RecordTickSample(record.sample); } - if (ticks_buffer_is_empty_) return !ticks_from_vm_buffer_.IsEmpty(); - if (ticks_buffer_.order == dequeue_order) { + const TickSampleEventRecord* rec = + TickSampleEventRecord::cast(ticks_buffer_.StartDequeue()); + if (rec == NULL) return !ticks_from_vm_buffer_.IsEmpty(); + // Make a local copy of tick sample record to ensure that it won't + // be modified as we are processing it. This is possible as the + // sampler writes w/o any sync to the queue, so if the processor + // will get far behind, a record may be modified right under its + // feet. + TickSampleEventRecord record = *rec; + if (record.order == dequeue_order) { // A paranoid check to make sure that we don't get a memory overrun // in case of frames_count having a wild value. - if (ticks_buffer_.sample.frames_count < 0 - || ticks_buffer_.sample.frames_count > TickSample::kMaxFramesCount) { - ticks_buffer_.sample.frames_count = 0; - } - generator_->RecordTickSample(ticks_buffer_.sample); - ticks_buffer_is_empty_ = true; - ticks_buffer_is_initialized_ = false; + if (record.sample.frames_count < 0 + || record.sample.frames_count > TickSample::kMaxFramesCount) + record.sample.frames_count = 0; + generator_->RecordTickSample(record.sample); + ticks_buffer_.FinishDequeue(); } else { return true; } @@ -233,29 +239,22 @@ bool ProfilerEventsProcessor::ProcessTicks(unsigned dequeue_order) { } -void ProfilerEventsProcessor::ProcessEventsQueue(int64_t stop_time, - unsigned* dequeue_order) { - while (OS::Ticks() < stop_time) { - if (ProcessTicks(*dequeue_order)) { - // All ticks of the current dequeue_order are processed, - // proceed to the next code event. - ProcessCodeEvent(dequeue_order); - } - } -} - - void ProfilerEventsProcessor::Run() { unsigned dequeue_order = 0; while (running_) { - int64_t stop_time = OS::Ticks() + period_in_useconds_; - if (sampler_ != NULL) { - sampler_->DoSample(); + // Process ticks until we have any. + if (ProcessTicks(dequeue_order)) { + // All ticks of the current dequeue_order are processed, + // proceed to the next code event. + ProcessCodeEvent(&dequeue_order); } - ProcessEventsQueue(stop_time, &dequeue_order); + YieldCPU(); } + // Process remaining tick events. + ticks_buffer_.FlushResidualRecords(); + // Perform processing until we have tick events, skip remaining code events. while (ProcessTicks(dequeue_order) && ProcessCodeEvent(&dequeue_order)) { } } @@ -311,22 +310,15 @@ CpuProfile* CpuProfiler::FindProfile(Object* security_token, unsigned uid) { } -TickSample* CpuProfiler::StartTickSampleEvent(Isolate* isolate) { +TickSample* CpuProfiler::TickSampleEvent(Isolate* isolate) { if (CpuProfiler::is_profiling(isolate)) { - return isolate->cpu_profiler()->processor_->StartTickSampleEvent(); + return isolate->cpu_profiler()->processor_->TickSampleEvent(); } else { return NULL; } } -void CpuProfiler::FinishTickSampleEvent(Isolate* isolate) { - if (CpuProfiler::is_profiling(isolate)) { - isolate->cpu_profiler()->processor_->FinishTickSampleEvent(); - } -} - - void CpuProfiler::DeleteAllProfiles() { Isolate* isolate = Isolate::Current(); ASSERT(isolate->cpu_profiler() != NULL); @@ -494,15 +486,13 @@ void CpuProfiler::StartProcessorIfNotStarted() { if (processor_ == NULL) { Isolate* isolate = Isolate::Current(); - Sampler* sampler = isolate->logger()->sampler(); // Disable logging when using the new implementation. saved_logging_nesting_ = isolate->logger()->logging_nesting_; isolate->logger()->logging_nesting_ = 0; generator_ = new ProfileGenerator(profiles_); - processor_ = new ProfilerEventsProcessor(generator_, - sampler, - FLAG_cpu_profiler_sampling_period); + processor_ = new ProfilerEventsProcessor(generator_); NoBarrier_Store(&is_profiling_, true); + processor_->Start(); // Enumerate stuff we already have in the heap. if (isolate->heap()->HasBeenSetUp()) { if (!FLAG_prof_browser_mode) { @@ -515,12 +505,12 @@ void CpuProfiler::StartProcessorIfNotStarted() { isolate->logger()->LogAccessorCallbacks(); } // Enable stack sampling. + Sampler* sampler = reinterpret_cast(isolate->logger()->ticker_); if (!sampler->IsActive()) { sampler->Start(); need_to_stop_sampler_ = true; } sampler->IncreaseProfilingDepth(); - processor_->Start(); } } @@ -555,16 +545,16 @@ void CpuProfiler::StopProcessorIfLastProfile(const char* title) { void CpuProfiler::StopProcessor() { - NoBarrier_Store(&is_profiling_, false); - processor_->Stop(); - processor_->Join(); Logger* logger = Isolate::Current()->logger(); - Sampler* sampler = logger->sampler(); + Sampler* sampler = reinterpret_cast(logger->ticker_); sampler->DecreaseProfilingDepth(); if (need_to_stop_sampler_) { sampler->Stop(); need_to_stop_sampler_ = false; } + NoBarrier_Store(&is_profiling_, false); + processor_->Stop(); + processor_->Join(); delete processor_; delete generator_; processor_ = NULL; diff --git a/src/cpu-profiler.h b/src/cpu-profiler.h index f4bc0c7..9cd4484 100644 --- a/src/cpu-profiler.h +++ b/src/cpu-profiler.h @@ -124,9 +124,7 @@ class TickSampleEventRecord { // methods called by event producers: VM and stack sampler threads. class ProfilerEventsProcessor : public Thread { public: - explicit ProfilerEventsProcessor(ProfileGenerator* generator, - Sampler* sampler, - int period_in_useconds); + explicit ProfilerEventsProcessor(ProfileGenerator* generator); virtual ~ProfilerEventsProcessor() {} // Thread control. @@ -158,12 +156,11 @@ class ProfilerEventsProcessor : public Thread { // Puts current stack into tick sample events buffer. void AddCurrentStack(); - // StartTickSampleEvent returns a pointer only if the ticks_buffer_ is empty, - // FinishTickSampleEvent marks the ticks_buffer_ as filled. - // Finish should be called only after successful Start (returning non-NULL - // pointer). - INLINE(TickSample* StartTickSampleEvent()); - INLINE(void FinishTickSampleEvent()); + // Tick sample events are filled directly in the buffer of the circular + // queue (because the structure is of fixed width, but usually not all + // stack frame entries are filled.) This method returns a pointer to the + // next record of the buffer. + INLINE(TickSample* TickSampleEvent()); private: union CodeEventsContainer { @@ -176,19 +173,13 @@ class ProfilerEventsProcessor : public Thread { // Called from events processing thread (Run() method.) bool ProcessCodeEvent(unsigned* dequeue_order); bool ProcessTicks(unsigned dequeue_order); - void ProcessEventsQueue(int64_t stop_time, unsigned* dequeue_order); INLINE(static bool FilterOutCodeCreateEvent(Logger::LogEventsAndTags tag)); ProfileGenerator* generator_; - Sampler* sampler_; bool running_; - // Sampling period in microseconds. - const int period_in_useconds_; UnboundQueue events_buffer_; - TickSampleEventRecord ticks_buffer_; - bool ticks_buffer_is_empty_; - bool ticks_buffer_is_initialized_; + SamplingCircularQueue ticks_buffer_; UnboundQueue ticks_from_vm_buffer_; unsigned enqueue_order_; }; @@ -227,10 +218,7 @@ class CpuProfiler { static bool HasDetachedProfiles(); // Invoked from stack sampler (thread or signal handler.) - // Finish should be called only after successful Start (returning non-NULL - // pointer). - static TickSample* StartTickSampleEvent(Isolate* isolate); - static void FinishTickSampleEvent(Isolate* isolate); + static TickSample* TickSampleEvent(Isolate* isolate); // Must be called via PROFILE macro, otherwise will crash when // profiling is not enabled. diff --git a/src/flag-definitions.h b/src/flag-definitions.h index f925d63..f040247 100644 --- a/src/flag-definitions.h +++ b/src/flag-definitions.h @@ -339,10 +339,6 @@ DEFINE_bool(compilation_cache, true, "enable compilation cache") DEFINE_bool(cache_prototype_transitions, true, "cache prototype transitions") -// cpu-profiler.cc -DEFINE_int(cpu_profiler_sampling_period, 1000, - "CPU profiler sampling period in microseconds") - // debug.cc DEFINE_bool(trace_debug_json, false, "trace debugging JSON request/response") DEFINE_bool(debugger_auto_break, true, diff --git a/src/platform-cygwin.cc b/src/platform-cygwin.cc index b39dfc0..089ea38 100644 --- a/src/platform-cygwin.cc +++ b/src/platform-cygwin.cc @@ -692,8 +692,9 @@ class SamplerThread : public Thread { CONTEXT context; memset(&context, 0, sizeof(context)); - TickSample* sample = CpuProfiler::StartTickSampleEvent(sampler->isolate()); - if (sample == NULL) return; + TickSample sample_obj; + TickSample* sample = CpuProfiler::TickSampleEvent(sampler->isolate()); + if (sample == NULL) sample = &sample_obj; static const DWORD kSuspendFailed = static_cast(-1); if (SuspendThread(profiled_thread) == kSuspendFailed) return; @@ -713,7 +714,6 @@ class SamplerThread : public Thread { sampler->SampleStack(sample); sampler->Tick(sample); } - CpuProfiler::FinishTickSampleEvent(sampler->isolate()); ResumeThread(profiled_thread); } @@ -768,11 +768,6 @@ Sampler::~Sampler() { } -void Sampler::DoSample() { - // TODO(rogulenko): implement -} - - void Sampler::Start() { ASSERT(!IsActive()); SetActive(true); diff --git a/src/platform-freebsd.cc b/src/platform-freebsd.cc index 6d1bccd..511759c 100644 --- a/src/platform-freebsd.cc +++ b/src/platform-freebsd.cc @@ -678,8 +678,9 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { Sampler* sampler = isolate->logger()->sampler(); if (sampler == NULL || !sampler->IsActive()) return; - TickSample* sample = CpuProfiler::StartTickSampleEvent(isolate); - if (sample == NULL) return; + TickSample sample_obj; + TickSample* sample = CpuProfiler::TickSampleEvent(isolate); + if (sample == NULL) sample = &sample_obj; // Extracting the sample from the context is extremely machine dependent. ucontext_t* ucontext = reinterpret_cast(context); @@ -700,7 +701,6 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { #endif sampler->SampleStack(sample); sampler->Tick(sample); - CpuProfiler::FinishTickSampleEvent(isolate); } @@ -884,11 +884,6 @@ Sampler::~Sampler() { } -void Sampler::DoSample() { - // TODO(rogulenko): implement -} - - void Sampler::Start() { ASSERT(!IsActive()); SetActive(true); diff --git a/src/platform-linux.cc b/src/platform-linux.cc index fe366c9..b9ce9d9 100644 --- a/src/platform-linux.cc +++ b/src/platform-linux.cc @@ -1015,8 +1015,9 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { Sampler* sampler = isolate->logger()->sampler(); if (sampler == NULL || !sampler->IsActive()) return; - TickSample* sample = CpuProfiler::StartTickSampleEvent(isolate); - if (sample == NULL) return; + TickSample sample_obj; + TickSample* sample = CpuProfiler::TickSampleEvent(isolate); + if (sample == NULL) sample = &sample_obj; // Extracting the sample from the context is extremely machine dependent. ucontext_t* ucontext = reinterpret_cast(context); @@ -1051,74 +1052,16 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { #endif // V8_HOST_ARCH_* sampler->SampleStack(sample); sampler->Tick(sample); - CpuProfiler::FinishTickSampleEvent(isolate); } -class CpuProfilerSignalHandler { - public: - static void SetUp() { if (!mutex_) mutex_ = OS::CreateMutex(); } - static void TearDown() { delete mutex_; } - - static void InstallSignalHandler() { - struct sigaction sa; - ScopedLock lock(mutex_); - if (signal_handler_installed_counter_ > 0) { - signal_handler_installed_counter_++; - return; - } - sa.sa_sigaction = ProfilerSignalHandler; - sigemptyset(&sa.sa_mask); - sa.sa_flags = SA_RESTART | SA_SIGINFO; - if (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0) { - signal_handler_installed_counter_++; - } - } - - static void RestoreSignalHandler() { - ScopedLock lock(mutex_); - if (signal_handler_installed_counter_ == 0) - return; - if (signal_handler_installed_counter_ == 1) { - sigaction(SIGPROF, &old_signal_handler_, 0); - } - signal_handler_installed_counter_--; - } - - static bool signal_handler_installed() { - return signal_handler_installed_counter_ > 0; - } - - private: - static int signal_handler_installed_counter_; - static struct sigaction old_signal_handler_; - static Mutex* mutex_; -}; - - -int CpuProfilerSignalHandler::signal_handler_installed_counter_ = 0; -struct sigaction CpuProfilerSignalHandler::old_signal_handler_; -Mutex* CpuProfilerSignalHandler::mutex_ = NULL; - - class Sampler::PlatformData : public Malloced { public: - PlatformData() - : vm_tgid_(getpid()), - vm_tid_(GetThreadID()) {} + PlatformData() : vm_tid_(GetThreadID()) {} - void SendProfilingSignal() { - if (!CpuProfilerSignalHandler::signal_handler_installed()) return; - // Glibc doesn't provide a wrapper for tgkill(2). -#if defined(ANDROID) - syscall(__NR_tgkill, vm_tgid_, vm_tid_, SIGPROF); -#else - syscall(SYS_tgkill, vm_tgid_, vm_tid_, SIGPROF); -#endif - } + int vm_tid() const { return vm_tid_; } private: - const int vm_tgid_; const int vm_tid_; }; @@ -1134,11 +1077,28 @@ class SignalSender : public Thread { explicit SignalSender(int interval) : Thread(Thread::Options("SignalSender", kSignalSenderStackSize)), + vm_tgid_(getpid()), interval_(interval) {} static void SetUp() { if (!mutex_) mutex_ = OS::CreateMutex(); } static void TearDown() { delete mutex_; } + static void InstallSignalHandler() { + struct sigaction sa; + sa.sa_sigaction = ProfilerSignalHandler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_RESTART | SA_SIGINFO; + signal_handler_installed_ = + (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0); + } + + static void RestoreSignalHandler() { + if (signal_handler_installed_) { + sigaction(SIGPROF, &old_signal_handler_, 0); + signal_handler_installed_ = false; + } + } + static void AddActiveSampler(Sampler* sampler) { ScopedLock lock(mutex_); SamplerRegistry::AddActiveSampler(sampler); @@ -1159,6 +1119,7 @@ class SignalSender : public Thread { RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); delete instance_; instance_ = NULL; + RestoreSignalHandler(); } } @@ -1167,21 +1128,67 @@ class SignalSender : public Thread { SamplerRegistry::State state; while ((state = SamplerRegistry::GetState()) != SamplerRegistry::HAS_NO_SAMPLERS) { - if (rate_limiter_.SuspendIfNecessary()) continue; - if (RuntimeProfiler::IsEnabled()) { + bool cpu_profiling_enabled = + (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS); + bool runtime_profiler_enabled = RuntimeProfiler::IsEnabled(); + if (cpu_profiling_enabled && !signal_handler_installed_) { + InstallSignalHandler(); + } else if (!cpu_profiling_enabled && signal_handler_installed_) { + RestoreSignalHandler(); + } + // When CPU profiling is enabled both JavaScript and C++ code is + // profiled. We must not suspend. + if (!cpu_profiling_enabled) { + if (rate_limiter_.SuspendIfNecessary()) continue; + } + if (cpu_profiling_enabled && runtime_profiler_enabled) { + if (!SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this)) { + return; + } + Sleep(HALF_INTERVAL); if (!SamplerRegistry::IterateActiveSamplers(&DoRuntimeProfile, NULL)) { return; } + Sleep(HALF_INTERVAL); + } else { + if (cpu_profiling_enabled) { + if (!SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, + this)) { + return; + } + } + if (runtime_profiler_enabled) { + if (!SamplerRegistry::IterateActiveSamplers(&DoRuntimeProfile, + NULL)) { + return; + } + } + Sleep(FULL_INTERVAL); } - Sleep(FULL_INTERVAL); } } + static void DoCpuProfile(Sampler* sampler, void* raw_sender) { + if (!sampler->IsProfiling()) return; + SignalSender* sender = reinterpret_cast(raw_sender); + sender->SendProfilingSignal(sampler->platform_data()->vm_tid()); + } + static void DoRuntimeProfile(Sampler* sampler, void* ignored) { if (!sampler->isolate()->IsInitialized()) return; sampler->isolate()->runtime_profiler()->NotifyTick(); } + void SendProfilingSignal(int tid) { + if (!signal_handler_installed_) return; + // Glibc doesn't provide a wrapper for tgkill(2). +#if defined(ANDROID) + syscall(__NR_tgkill, vm_tgid_, tid, SIGPROF); +#else + syscall(SYS_tgkill, vm_tgid_, tid, SIGPROF); +#endif + } + void Sleep(SleepInterval full_or_half) { // Convert ms to us and subtract 100 us to compensate delays // occuring during signal delivery. @@ -1204,12 +1211,15 @@ class SignalSender : public Thread { #endif // ANDROID } + const int vm_tgid_; const int interval_; RuntimeProfilerRateLimiter rate_limiter_; // Protects the process wide state below. static Mutex* mutex_; static SignalSender* instance_; + static bool signal_handler_installed_; + static struct sigaction old_signal_handler_; private: DISALLOW_COPY_AND_ASSIGN(SignalSender); @@ -1218,6 +1228,8 @@ class SignalSender : public Thread { Mutex* SignalSender::mutex_ = NULL; SignalSender* SignalSender::instance_ = NULL; +struct sigaction SignalSender::old_signal_handler_; +bool SignalSender::signal_handler_installed_ = false; void OS::SetUp() { @@ -1245,13 +1257,11 @@ void OS::SetUp() { } #endif SignalSender::SetUp(); - CpuProfilerSignalHandler::SetUp(); } void OS::TearDown() { SignalSender::TearDown(); - CpuProfilerSignalHandler::TearDown(); delete limit_mutex; } @@ -1272,14 +1282,8 @@ Sampler::~Sampler() { } -void Sampler::DoSample() { - platform_data()->SendProfilingSignal(); -} - - void Sampler::Start() { ASSERT(!IsActive()); - CpuProfilerSignalHandler::InstallSignalHandler(); SetActive(true); SignalSender::AddActiveSampler(this); } @@ -1287,7 +1291,6 @@ void Sampler::Start() { void Sampler::Stop() { ASSERT(IsActive()); - CpuProfilerSignalHandler::RestoreSignalHandler(); SignalSender::RemoveActiveSampler(this); SetActive(false); } diff --git a/src/platform-macos.cc b/src/platform-macos.cc index a570868..a216f6e 100644 --- a/src/platform-macos.cc +++ b/src/platform-macos.cc @@ -819,8 +819,9 @@ class SamplerThread : public Thread { void SampleContext(Sampler* sampler) { thread_act_t profiled_thread = sampler->platform_data()->profiled_thread(); - TickSample* sample = CpuProfiler::StartTickSampleEvent(sampler->isolate()); - if (sample == NULL) return; + TickSample sample_obj; + TickSample* sample = CpuProfiler::TickSampleEvent(sampler->isolate()); + if (sample == NULL) sample = &sample_obj; if (KERN_SUCCESS != thread_suspend(profiled_thread)) return; @@ -857,7 +858,6 @@ class SamplerThread : public Thread { sampler->SampleStack(sample); sampler->Tick(sample); } - CpuProfiler::FinishTickSampleEvent(sampler->isolate()); thread_resume(profiled_thread); } @@ -910,11 +910,6 @@ Sampler::~Sampler() { } -void Sampler::DoSample() { - // TODO(rogulenko): implement -} - - void Sampler::Start() { ASSERT(!IsActive()); SetActive(true); diff --git a/src/platform-openbsd.cc b/src/platform-openbsd.cc index f96d9e3..408d4dc 100644 --- a/src/platform-openbsd.cc +++ b/src/platform-openbsd.cc @@ -731,8 +731,9 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { Sampler* sampler = isolate->logger()->sampler(); if (sampler == NULL || !sampler->IsActive()) return; - TickSample* sample = CpuProfiler::StartTickSampleEvent(isolate); - if (sample == NULL) return; + TickSample sample_obj; + TickSample* sample = CpuProfiler::TickSampleEvent(isolate); + if (sample == NULL) sample = &sample_obj; // Extracting the sample from the context is extremely machine dependent. sample->state = isolate->current_vm_state(); @@ -761,7 +762,6 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { #endif // __NetBSD__ sampler->SampleStack(sample); sampler->Tick(sample); - CpuProfiler::FinishTickSampleEvent(isolate); } @@ -964,11 +964,6 @@ Sampler::~Sampler() { } -void Sampler::DoSample() { - // TODO(rogulenko): implement -} - - void Sampler::Start() { ASSERT(!IsActive()); SetActive(true); diff --git a/src/platform-solaris.cc b/src/platform-solaris.cc index 36d89e6..4248ea2 100644 --- a/src/platform-solaris.cc +++ b/src/platform-solaris.cc @@ -669,8 +669,9 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { Sampler* sampler = isolate->logger()->sampler(); if (sampler == NULL || !sampler->IsActive()) return; - TickSample* sample = CpuProfiler::StartTickSampleEvent(isolate); - if (sample == NULL) return; + TickSample sample_obj; + TickSample* sample = CpuProfiler::TickSampleEvent(isolate); + if (sample == NULL) sample = &sample_obj; // Extracting the sample from the context is extremely machine dependent. ucontext_t* ucontext = reinterpret_cast(context); @@ -683,7 +684,6 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { sampler->SampleStack(sample); sampler->Tick(sample); - CpuProfiler::FinishTickSampleEvent(isolate); } class Sampler::PlatformData : public Malloced { @@ -887,11 +887,6 @@ Sampler::~Sampler() { } -void Sampler::DoSample() { - // TODO(rogulenko): implement -} - - void Sampler::Start() { ASSERT(!IsActive()); SetActive(true); diff --git a/src/platform-win32.cc b/src/platform-win32.cc index 65d31a9..49463be 100644 --- a/src/platform-win32.cc +++ b/src/platform-win32.cc @@ -2038,8 +2038,9 @@ class SamplerThread : public Thread { CONTEXT context; memset(&context, 0, sizeof(context)); - TickSample* sample = CpuProfiler::StartTickSampleEvent(sampler->isolate()); - if (sample == NULL) return; + TickSample sample_obj; + TickSample* sample = CpuProfiler::TickSampleEvent(sampler->isolate()); + if (sample == NULL) sample = &sample_obj; static const DWORD kSuspendFailed = static_cast(-1); if (SuspendThread(profiled_thread) == kSuspendFailed) return; @@ -2059,7 +2060,6 @@ class SamplerThread : public Thread { sampler->SampleStack(sample); sampler->Tick(sample); } - CpuProfiler::FinishTickSampleEvent(sampler->isolate()); ResumeThread(profiled_thread); } @@ -2114,11 +2114,6 @@ Sampler::~Sampler() { } -void Sampler::DoSample() { - // TODO(rogulenko): implement -} - - void Sampler::Start() { ASSERT(!IsActive()); SetActive(true); diff --git a/src/platform.h b/src/platform.h index 4f8fdc3..f50e713 100644 --- a/src/platform.h +++ b/src/platform.h @@ -741,9 +741,6 @@ class Sampler { IncSamplesTaken(); } - // Performs platform-specific stack sampling. - void DoSample(); - // This method is called for each sampling period with the current // program counter. virtual void Tick(TickSample* sample) = 0; diff --git a/test/cctest/test-cpu-profiler.cc b/test/cctest/test-cpu-profiler.cc index 589e6d8..b10e688 100644 --- a/test/cctest/test-cpu-profiler.cc +++ b/test/cctest/test-cpu-profiler.cc @@ -5,7 +5,6 @@ #include "v8.h" #include "cpu-profiler-inl.h" #include "cctest.h" -#include "platform.h" #include "../include/v8-profiler.h" using i::CodeEntry; @@ -21,7 +20,7 @@ using i::TokenEnumerator; TEST(StartStop) { CpuProfilesCollection profiles; ProfileGenerator generator(&profiles); - ProfilerEventsProcessor processor(&generator, NULL, 1000); + ProfilerEventsProcessor processor(&generator); processor.Start(); processor.Stop(); processor.Join(); @@ -39,13 +38,11 @@ static inline i::Address ToAddress(int n) { return reinterpret_cast(n); } -static void AddTickSampleEvent(ProfilerEventsProcessor* processor, - i::Address frame1, - i::Address frame2 = NULL, - i::Address frame3 = NULL) { - i::TickSample* sample; - i::OS::Sleep(20); - while ((sample = processor->StartTickSampleEvent()) == NULL) i::OS::Sleep(20); +static void EnqueueTickSampleEvent(ProfilerEventsProcessor* proc, + i::Address frame1, + i::Address frame2 = NULL, + i::Address frame3 = NULL) { + i::TickSample* sample = proc->TickSampleEvent(); sample->pc = frame1; sample->tos = frame1; sample->frames_count = 0; @@ -57,7 +54,6 @@ static void AddTickSampleEvent(ProfilerEventsProcessor* processor, sample->stack[1] = frame3; sample->frames_count = 2; } - processor->FinishTickSampleEvent(); } namespace { @@ -85,7 +81,7 @@ TEST(CodeEvents) { CpuProfilesCollection profiles; profiles.StartProfiling("", 1); ProfileGenerator generator(&profiles); - ProfilerEventsProcessor processor(&generator, NULL, 1000); + ProfilerEventsProcessor processor(&generator); processor.Start(); // Enqueue code creation events. @@ -112,8 +108,8 @@ TEST(CodeEvents) { processor.CodeMoveEvent(ToAddress(0x1400), ToAddress(0x1500)); processor.CodeCreateEvent(i::Logger::STUB_TAG, 3, ToAddress(0x1600), 0x10); processor.CodeCreateEvent(i::Logger::STUB_TAG, 4, ToAddress(0x1605), 0x10); - // Add a tick event to enable code events processing. - AddTickSampleEvent(&processor, ToAddress(0x1000)); + // Enqueue a tick event to enable code events processing. + EnqueueTickSampleEvent(&processor, ToAddress(0x1000)); processor.Stop(); processor.Join(); @@ -146,7 +142,7 @@ TEST(TickEvents) { CpuProfilesCollection profiles; profiles.StartProfiling("", 1); ProfileGenerator generator(&profiles); - ProfilerEventsProcessor processor(&generator, NULL, 1000); + ProfilerEventsProcessor processor(&generator); processor.Start(); processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, @@ -158,12 +154,12 @@ TEST(TickEvents) { "ddd", ToAddress(0x1400), 0x80); - AddTickSampleEvent(&processor, ToAddress(0x1210)); - AddTickSampleEvent(&processor, ToAddress(0x1305), ToAddress(0x1220)); - AddTickSampleEvent(&processor, - ToAddress(0x1404), - ToAddress(0x1305), - ToAddress(0x1230)); + EnqueueTickSampleEvent(&processor, ToAddress(0x1210)); + EnqueueTickSampleEvent(&processor, ToAddress(0x1305), ToAddress(0x1220)); + EnqueueTickSampleEvent(&processor, + ToAddress(0x1404), + ToAddress(0x1305), + ToAddress(0x1230)); processor.Stop(); processor.Join(); @@ -236,7 +232,7 @@ TEST(Issue1398) { CpuProfilesCollection profiles; profiles.StartProfiling("", 1); ProfileGenerator generator(&profiles); - ProfilerEventsProcessor processor(&generator, NULL, 1000); + ProfilerEventsProcessor processor(&generator); processor.Start(); processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, @@ -244,14 +240,13 @@ TEST(Issue1398) { ToAddress(0x1200), 0x80); - i::TickSample* sample = processor.StartTickSampleEvent(); + i::TickSample* sample = processor.TickSampleEvent(); sample->pc = ToAddress(0x1200); sample->tos = 0; sample->frames_count = i::TickSample::kMaxFramesCount; for (int i = 0; i < sample->frames_count; ++i) { sample->stack[i] = ToAddress(0x1200); } - processor.FinishTickSampleEvent(); processor.Stop(); processor.Join(); -- 2.7.4