Index: src/cpu-profiler.cc |
diff --git a/src/cpu-profiler.cc b/src/cpu-profiler.cc |
index 3cbac77858d5560feb3cab420f08c9e461f2422e..31892902be0fd881ff0ee49d6c7857f2274c57f1 100644 |
--- a/src/cpu-profiler.cc |
+++ b/src/cpu-profiler.cc |
@@ -45,10 +45,12 @@ static const int kTickSamplesBufferChunksCount = 16; |
static const int kProfilerStackSize = 64 * KB; |
-ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator) |
- : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), |
+ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator, Sampler* sampler, int interval_in_useconds) |
+ : Thread(Thread::Options("CpuProfiler", kProfilerStackSize)), |
generator_(generator), |
+ sampler_(sampler), |
running_(true), |
+ interval_in_useconds_(interval_in_useconds), |
ticks_buffer_(sizeof(TickSampleEventRecord), |
kTickSamplesBufferChunkSize, |
kTickSamplesBufferChunksCount), |
@@ -206,8 +208,8 @@ bool ProfilerEventsProcessor::ProcessCodeEvent(unsigned* dequeue_order) { |
} |
-bool ProfilerEventsProcessor::ProcessTicks(unsigned dequeue_order) { |
- while (true) { |
+bool ProfilerEventsProcessor::ProcessTicks(int64_t stop_time, unsigned dequeue_order) { |
+ while (stop_time == -1 || OS::Ticks() < stop_time) { |
if (!ticks_from_vm_buffer_.IsEmpty() |
&& ticks_from_vm_buffer_.Peek()->order == dequeue_order) { |
TickSampleEventRecord record; |
@@ -236,6 +238,18 @@ bool ProfilerEventsProcessor::ProcessTicks(unsigned dequeue_order) { |
return true; |
} |
} |
+ return false; |
+} |
+ |
+ |
+void ProfilerEventsProcessor::ProcessEventsQueue(int64_t stop_time, unsigned* dequeue_order) { |
+ while (OS::Ticks() < stop_time) |
+ // Process ticks until we have any. |
+ if (ProcessTicks(stop_time, *dequeue_order)) { |
+ // All ticks of the current dequeue_order are processed, |
+ // proceed to the next code event. |
+ ProcessCodeEvent(dequeue_order); |
+ } |
} |
@@ -243,19 +257,25 @@ void ProfilerEventsProcessor::Run() { |
unsigned dequeue_order = 0; |
while (running_) { |
- // 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); |
+ if (FLAG_sample_stack_in_postprocessor_thread) { |
caseq
2012/08/17 16:59:28
if (sampler_ != NULL)
|
+ int64_t stop_time = OS::Ticks() + interval_in_useconds_; |
+ sampler_->DoSample(); |
+ ProcessEventsQueue(stop_time, &dequeue_order); |
+ } else { |
+ // Process ticks until we have any. |
+ if (ProcessTicks(-1, dequeue_order)) { |
+ // All ticks of the current dequeue_order are processed, |
+ // proceed to the next code event. |
+ ProcessCodeEvent(&dequeue_order); |
+ } |
+ YieldCPU(); |
} |
- 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)) { } |
+ while (ProcessTicks(-1, dequeue_order) && ProcessCodeEvent(&dequeue_order)) { } |
} |
@@ -486,11 +506,15 @@ 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_); |
+ if (FLAG_sample_stack_in_postprocessor_thread) |
+ processor_ = new ProfilerEventsProcessor(generator_, sampler, sampler->interval() * 1000); |
+ else |
+ processor_ = new ProfilerEventsProcessor(generator_, NULL, sampler->interval() * 1000); |
NoBarrier_Store(&is_profiling_, true); |
processor_->Start(); |
// Enumerate stuff we already have in the heap. |
@@ -505,7 +529,6 @@ void CpuProfiler::StartProcessorIfNotStarted() { |
isolate->logger()->LogAccessorCallbacks(); |
} |
// Enable stack sampling. |
- Sampler* sampler = reinterpret_cast<Sampler*>(isolate->logger()->ticker_); |
if (!sampler->IsActive()) { |
sampler->Start(); |
need_to_stop_sampler_ = true; |