Index: src/cpu-profiler.cc |
diff --git a/src/cpu-profiler.cc b/src/cpu-profiler.cc |
index a8a57d1d67c6679eb61233db32a3a2903fd33810..5d021ec5358f3991e085873d156252ad1d1120fa 100644 |
--- a/src/cpu-profiler.cc |
+++ b/src/cpu-profiler.cc |
@@ -120,16 +120,32 @@ ProfilerEventsProcessor::SampleProcessingResult |
void ProfilerEventsProcessor::Run() { |
while (!!base::NoBarrier_Load(&running_)) { |
- base::ElapsedTimer timer; |
- timer.Start(); |
- // Keep processing existing events until we need to do next sample. |
+ base::TimeTicks nextSampleTime = |
+ base::TimeTicks::HighResolutionNow() + period_; |
+ base::TimeTicks now; |
+ SampleProcessingResult result; |
+ // Keep processing existing events until we need to do next sample |
+ // or the ticks buffer is empty. |
do { |
- if (FoundSampleForNextCodeEvent == ProcessOneSample()) { |
+ result = ProcessOneSample(); |
+ if (result == FoundSampleForNextCodeEvent) { |
// All ticks of the current last_processed_code_event_id_ are |
// processed, proceed to the next code event. |
ProcessCodeEvent(); |
} |
- } while (!timer.HasExpired(period_)); |
+ now = base::TimeTicks::HighResolutionNow(); |
+ } while (result != NoSamplesInQueue && now < nextSampleTime); |
+ |
+ if (nextSampleTime > now) { |
+#if V8_OS_WIN |
+ // Do not use Sleep on Windows as it is very imprecise. |
+ // Could be up to 16ms jitter, which is unacceptable for the purpose. |
+ while (base::TimeTicks::HighResolutionNow() < nextSampleTime) { |
+ } |
+#else |
+ base::OS::Sleep(nextSampleTime - now); |
+#endif |
+ } |
// Schedule next sample. sampler_ is NULL in tests. |
if (sampler_) sampler_->DoSample(); |