Bug 1188616 - CPOW monitoring should use JS_Now instead of PR_IntervalNow. r=jandem
authorDavid Rajchenbach-Teller <dteller@mozilla.com>
Thu, 30 Jul 2015 14:29:52 +0200
changeset 287712 3a45337c8727f0da108b0295089cb82482cea276
parent 287711 d4d78ac3f0d2734fa3e29c44163640f11fbeceb4
child 287713 991af90f693d1554b319ee1283e35097c2d6e740
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1188616
milestone42.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 1188616 - CPOW monitoring should use JS_Now instead of PR_IntervalNow. r=jandem
js/ipc/CPOWTimer.cpp
js/ipc/CPOWTimer.h
--- a/js/ipc/CPOWTimer.cpp
+++ b/js/ipc/CPOWTimer.cpp
@@ -4,36 +4,43 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "jsfriendapi.h"
 #include "nsContentUtils.h"
 #include "CPOWTimer.h"
 
+#include "jsapi.h"
+
 CPOWTimer::CPOWTimer(JSContext* cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
     : cx_(nullptr)
     , startInterval_(0)
 {
     MOZ_GUARD_OBJECT_NOTIFIER_INIT;
     JSRuntime* runtime = JS_GetRuntime(cx);
     if (!js::GetStopwatchIsMonitoringCPOW(runtime))
         return;
     cx_ = cx;
-    startInterval_ = PR_IntervalNow();
+    startInterval_ = JS_Now();
 }
 CPOWTimer::~CPOWTimer()
 {
     if (!cx_) {
         // Monitoring was off when we started the timer.
         return;
     }
 
     JSRuntime* runtime = JS_GetRuntime(cx_);
     if (!js::GetStopwatchIsMonitoringCPOW(runtime)) {
         // Monitoring has been deactivated while we were in the timer.
         return;
     }
 
+    const int64_t endInterval = JS_Now();
+    if (endInterval <= startInterval_) {
+        // Do not assume monotonicity.
+        return;
+    }
+
     js::PerformanceData* performance = js::GetPerformanceData(runtime);
-    uint64_t duration = PR_IntervalToMicroseconds(PR_IntervalNow() - startInterval_);
-    performance->totalCPOWTime += duration;
+    performance->totalCPOWTime += endInterval - startInterval_;
 }
--- a/js/ipc/CPOWTimer.h
+++ b/js/ipc/CPOWTimer.h
@@ -33,12 +33,12 @@ class MOZ_STACK_CLASS CPOWTimer final {
      * CPOW monitoring was off when the timer was created.
      */
     JSContext* cx_;
 
     /**
      * The instant at which the stopwatch was started. Undefined
      * if CPOW monitoring was off when the timer was created.
      */
-    PRIntervalTime startInterval_;
+    int64_t startInterval_;
 };
 
 #endif