@@ -108,16 +108,32 @@ ProfilerEventsProcessor::SampleProcessingResult
108108
109109void ProfilerEventsProcessor::Run () {
110110 while (running_) {
111- base::ElapsedTimer timer;
112- timer.Start ();
113- // Keep processing existing events until we need to do next sample.
111+ base::TimeTicks nextSampleTime =
112+ base::TimeTicks::HighResolutionNow () + period_;
113+ base::TimeTicks now;
114+ SampleProcessingResult result;
115+ // Keep processing existing events until we need to do next sample
116+ // or the ticks buffer is empty.
114117 do {
115- if (FoundSampleForNextCodeEvent == ProcessOneSample ()) {
118+ result = ProcessOneSample ();
119+ if (result == FoundSampleForNextCodeEvent) {
116120 // All ticks of the current last_processed_code_event_id_ are
117121 // processed, proceed to the next code event.
118122 ProcessCodeEvent ();
119123 }
120- } while (!timer.HasExpired (period_));
124+ now = base::TimeTicks::HighResolutionNow ();
125+ } while (result != NoSamplesInQueue && now < nextSampleTime);
126+
127+ if (nextSampleTime > now) {
128+ #if V8_OS_WIN
129+ // Do not use Sleep on Windows as it is very imprecise.
130+ // Could be up to 16ms jitter, which is unacceptable for the purpose.
131+ while (base::TimeTicks::HighResolutionNow () < nextSampleTime) {
132+ }
133+ #else
134+ base::OS::Sleep (nextSampleTime - now);
135+ #endif
136+ }
121137
122138 // Schedule next sample. sampler_ is NULL in tests.
123139 if (sampler_) sampler_->DoSample ();
0 commit comments