Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Unified Diff: src/cpu-profiler.cc

Issue 1118533003: Make CPU profiler do not hog 100% of CPU. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: still uploading Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/base/platform/platform-win32.cc ('k') | src/optimizing-compile-dispatcher.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
« no previous file with comments | « src/base/platform/platform-win32.cc ('k') | src/optimizing-compile-dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698