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. This is a modified version of r16549 whith a fix for test flakiness. The test flakiness introduced by the previous version of this changed was fixed by changing return type of ProfilerEventsProcessor::ProcessOneSample from bool to enum with 3 options. In the main profiling loop we decide that the next code event should be processed when sample with a greater ordinal number is encountered. When processing remaining samples we shouldn't wait for more samples and if the samples queue is empty we just process next code event. BUG=v8:2814,v8:2871 R=bmeurer@chromium.org, loislo@chromium.org Review URL: https://codereview.chromium.org/23455036 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16564 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
d1cfe6c8dd
commit
43780dbdc9
@ -103,50 +103,54 @@ bool ProfilerEventsProcessor::ProcessCodeEvent() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool ProfilerEventsProcessor::ProcessTicks() {
|
||||
while (true) {
|
||||
while (!ticks_from_vm_buffer_.IsEmpty()
|
||||
ProfilerEventsProcessor::SampleProcessingResult
|
||||
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 OneSampleProcessed;
|
||||
}
|
||||
|
||||
const TickSampleEventRecord* record = ticks_buffer_.Peek();
|
||||
if (record == NULL) return !ticks_from_vm_buffer_.IsEmpty();
|
||||
if (record->order != last_processed_code_event_id_) return true;
|
||||
if (record == NULL) {
|
||||
if (ticks_from_vm_buffer_.IsEmpty()) return NoSamplesInQueue;
|
||||
return FoundSampleForNextCodeEvent;
|
||||
}
|
||||
if (record->order != last_processed_code_event_id_) {
|
||||
return FoundSampleForNextCodeEvent;
|
||||
}
|
||||
generator_->RecordTickSample(record->sample);
|
||||
ticks_buffer_.Remove();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
return OneSampleProcessed;
|
||||
}
|
||||
|
||||
|
||||
void ProfilerEventsProcessor::Run() {
|
||||
while (running_) {
|
||||
ProcessEventsAndDoSample();
|
||||
ElapsedTimer timer;
|
||||
timer.Start();
|
||||
// Keep processing existing events until we need to do next sample.
|
||||
do {
|
||||
if (FoundSampleForNextCodeEvent == 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();
|
||||
SampleProcessingResult result;
|
||||
do {
|
||||
result = ProcessOneSample();
|
||||
} while (result == OneSampleProcessed);
|
||||
} while (ProcessCodeEvent());
|
||||
}
|
||||
|
||||
|
@ -161,9 +161,13 @@ class ProfilerEventsProcessor : public Thread {
|
||||
private:
|
||||
// Called from events processing thread (Run() method.)
|
||||
bool ProcessCodeEvent();
|
||||
bool ProcessTicks();
|
||||
|
||||
void ProcessEventsAndDoSample();
|
||||
enum SampleProcessingResult {
|
||||
OneSampleProcessed,
|
||||
FoundSampleForNextCodeEvent,
|
||||
NoSamplesInQueue
|
||||
};
|
||||
SampleProcessingResult ProcessOneSample();
|
||||
|
||||
ProfileGenerator* generator_;
|
||||
Sampler* sampler_;
|
||||
|
Loading…
Reference in New Issue
Block a user