Commit 8d6a096c authored by yurys@chromium.org's avatar yurys@chromium.org

Check if timeout has expired after processing each sample

To avoid long intervals between taking samples due to processing all accumulated samples at once, the samples are processed one by one and we check if the sampling interval has elapsed after each step rather than after processing all the samples in the queue.

BUG=v8:2814
R=bmeurer@chromium.org, loislo@chromium.org

Review URL: https://codereview.chromium.org/23583036

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16548 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 215ae8aa
......@@ -104,49 +104,45 @@ bool ProfilerEventsProcessor::ProcessCodeEvent() {
}
bool ProfilerEventsProcessor::ProcessTicks() {
while (true) {
while (!ticks_from_vm_buffer_.IsEmpty()
&& ticks_from_vm_buffer_.Peek()->order ==
last_processed_code_event_id_) {
TickSampleEventRecord record;
ticks_from_vm_buffer_.Dequeue(&record);
generator_->RecordTickSample(record.sample);
}
const TickSampleEventRecord* record = ticks_buffer_.StartDequeue();
if (record == NULL) return !ticks_from_vm_buffer_.IsEmpty();
if (record->order != last_processed_code_event_id_) return true;
generator_->RecordTickSample(record->sample);
ticks_buffer_.FinishDequeue();
bool ProfilerEventsProcessor::ProcessOneSample() {
if (!ticks_from_vm_buffer_.IsEmpty()
&& ticks_from_vm_buffer_.Peek()->order ==
last_processed_code_event_id_) {
TickSampleEventRecord record;
ticks_from_vm_buffer_.Dequeue(&record);
generator_->RecordTickSample(record.sample);
return false;
}
}
void ProfilerEventsProcessor::ProcessEventsAndDoSample() {
ElapsedTimer timer;
timer.Start();
// Keep processing existing events until we need to do next sample.
while (!timer.HasExpired(period_)) {
if (ProcessTicks()) {
// All ticks of the current dequeue_order are processed,
// proceed to the next code event.
ProcessCodeEvent();
}
}
// Schedule next sample. sampler_ is NULL in tests.
if (sampler_) sampler_->DoSample();
const TickSampleEventRecord* record = ticks_buffer_.StartDequeue();
if (record == NULL) return true;
if (record->order != last_processed_code_event_id_) return true;
generator_->RecordTickSample(record->sample);
ticks_buffer_.FinishDequeue();
return false;
}
void ProfilerEventsProcessor::Run() {
while (running_) {
ProcessEventsAndDoSample();
ElapsedTimer timer;
timer.Start();
// Keep processing existing events until we need to do next sample.
do {
if (ProcessOneSample()) {
// All ticks of the current last_processed_code_event_id_ are
// processed, proceed to the next code event.
ProcessCodeEvent();
}
} while (!timer.HasExpired(period_));
// Schedule next sample. sampler_ is NULL in tests.
if (sampler_) sampler_->DoSample();
}
// Process remaining tick events.
do {
ProcessTicks();
while (!ProcessOneSample());
} while (ProcessCodeEvent());
}
......
......@@ -161,9 +161,7 @@ class ProfilerEventsProcessor : public Thread {
private:
// Called from events processing thread (Run() method.)
bool ProcessCodeEvent();
bool ProcessTicks();
void ProcessEventsAndDoSample();
bool ProcessOneSample();
ProfileGenerator* generator_;
Sampler* sampler_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment