Chromium Code Reviews| 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 |
|
Benedikt Meurer
2015/04/30 05:06:01
I don't really like this special casing for Window
yurys
2015/04/30 08:10:02
Would "Multimedia Timers" work here?
alph
2015/04/30 10:13:34
I'm not aware of such method. I appreciate if you
alph
2015/04/30 10:13:34
They have 1ms resolution at best which is still no
|
| + // 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(); |