Bug 777032. Add support for high resolution profiling on win32. r=ehsan.
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Thu, 26 Jul 2012 12:02:48 -0400
changeset 100587 8ed3f453a114cbc662aa08828255bb8795e63282
parent 100583 e4330f6365d9ff9f79c673a215119b9053202583
child 100588 64cf4ece2a946e634fa17b569a5f75a0f55474dd
push id23188
push useremorley@mozilla.com
push dateFri, 27 Jul 2012 08:54:50 +0000
treeherdermozilla-central@399aff2fb74f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs777032
milestone17.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 777032. Add support for high resolution profiling on win32. r=ehsan. The default sleep time on windows is 15.6ms. This is insufficient for our profiling needs. Use timeBeingPeriod to adjust this when necessary.
tools/profiler/platform-win32.cc
--- a/tools/profiler/platform-win32.cc
+++ b/tools/profiler/platform-win32.cc
@@ -1,13 +1,14 @@
 // Copyright (c) 2006-2011 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
 #include <windows.h>
+#include <mmsystem.h>
 #include "platform.h"
 #include <process.h>
 
 
 class Sampler::PlatformData : public Malloced {
  public:
   // Get a handle to the calling thread. This is the thread that we are
   // going to profile. We need to make a copy of the handle because we are
@@ -58,21 +59,32 @@ class SamplerThread : public Thread {
   static void StopSampler() {
     instance_->Join();
     delete instance_;
     instance_ = NULL;
   }
 
   // Implement Thread::Run().
   virtual void Run() {
+
+    // By default we'll not adjust the timer resolution which tends to be around
+    // 16ms. However, if the requested interval is sufficiently low we'll try to
+    // adjust the resolution to match.
+    if (interval_ < 10)
+        ::timeBeginPeriod(interval_);
+
     while (sampler_->IsActive()) {
       if (!sampler_->IsPaused())
         SampleContext(sampler_);
       OS::Sleep(interval_);
     }
+
+    // disable any timer resolution changes we've made
+    if (interval_ < 10)
+        ::timeEndPeriod(interval_);
   }
 
   void SampleContext(Sampler* sampler) {
     HANDLE profiled_thread = sampler->platform_data()->profiled_thread();
     if (profiled_thread == NULL)
       return;
 
     // Context used for sampling the register state of the profiled thread.