Bug 1373536 - Move TimeoutBudgetManager to its own file. r=bkelly
authorAndreas Farre <farre@mozilla.com>
Fri, 16 Jun 2017 09:17:09 +0200
changeset 365706 a7e6ff8f2f3a7d5b50f8269fa553ba0bf3321f0d
parent 365705 b2e22a96e7c5c23a48e1bcfd1238dd80658b1322
child 365707 5cc17c25b2405dd4267d49664145702f6282eb13
push id32081
push usercbook@mozilla.com
push dateFri, 23 Jun 2017 09:28:37 +0000
treeherdermozilla-central@1466b62da7b2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1373536
milestone56.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 1373536 - Move TimeoutBudgetManager to its own file. r=bkelly
dom/base/TimeoutBudgetManager.cpp
dom/base/TimeoutBudgetManager.h
dom/base/TimeoutManager.cpp
dom/base/moz.build
new file mode 100644
--- /dev/null
+++ b/dom/base/TimeoutBudgetManager.cpp
@@ -0,0 +1,96 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et cindent: */
+/* 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 "TimeoutBudgetManager.h"
+
+namespace mozilla {
+namespace dom {
+
+// Time between sampling timeout execution time.
+const uint32_t kTelemetryPeriodMS = 1000;
+
+static TimeoutBudgetManager gTimeoutBudgetManager;
+
+/* static */ TimeoutBudgetManager&
+TimeoutBudgetManager::Get()
+{
+  return gTimeoutBudgetManager;
+}
+
+void
+TimeoutBudgetManager::StartRecording(const TimeStamp& aNow)
+{
+  mStart = aNow;
+}
+
+void
+TimeoutBudgetManager::StopRecording()
+{
+  mStart = TimeStamp();
+}
+
+TimeDuration
+TimeoutBudgetManager::RecordExecution(const TimeStamp& aNow,
+                                      bool aIsTracking,
+                                      bool aIsBackground)
+{
+  if (!mStart) {
+    // If we've started a sync operation mStart might be null, in
+    // which case we should not record this piece of execution.
+    return TimeDuration();
+  }
+
+  TimeDuration duration = aNow - mStart;
+
+  if (aIsBackground) {
+    if (aIsTracking) {
+      mTelemetryData.mBackgroundTracking += duration;
+    } else {
+      mTelemetryData.mBackgroundNonTracking += duration;
+    }
+  } else {
+    if (aIsTracking) {
+      mTelemetryData.mForegroundTracking += duration;
+    } else {
+      mTelemetryData.mForegroundNonTracking += duration;
+    }
+  }
+
+  return duration;
+}
+
+void
+TimeoutBudgetManager::Accumulate(Telemetry::HistogramID aId,
+                                 const TimeDuration& aSample)
+{
+  uint32_t sample = std::round(aSample.ToMilliseconds());
+  if (sample) {
+    Telemetry::Accumulate(aId, sample);
+  }
+}
+
+void
+TimeoutBudgetManager::MaybeCollectTelemetry(const TimeStamp& aNow)
+{
+  if ((aNow - mLastCollection).ToMilliseconds() < kTelemetryPeriodMS) {
+    return;
+  }
+
+  Accumulate(Telemetry::TIMEOUT_EXECUTION_FG_TRACKING_MS,
+             mTelemetryData.mForegroundTracking);
+  Accumulate(Telemetry::TIMEOUT_EXECUTION_FG_MS,
+             mTelemetryData.mForegroundNonTracking);
+  Accumulate(Telemetry::TIMEOUT_EXECUTION_BG_TRACKING_MS,
+             mTelemetryData.mBackgroundTracking);
+  Accumulate(Telemetry::TIMEOUT_EXECUTION_BG_MS,
+             mTelemetryData.mBackgroundNonTracking);
+
+  mTelemetryData = TelemetryData();
+  mLastCollection = aNow;
+}
+
+} // namespace dom
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/base/TimeoutBudgetManager.h
@@ -0,0 +1,47 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et cindent: */
+/* 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/. */
+
+#ifndef mozilla_dom_timeoutbudgetmanager_h
+#define mozilla_dom_timeoutbudgetmanager_h
+
+#include "mozilla/Telemetry.h"
+#include "mozilla/TimeStamp.h"
+
+namespace mozilla {
+namespace dom {
+
+class TimeoutBudgetManager
+{
+public:
+  static TimeoutBudgetManager& Get();
+  TimeoutBudgetManager() : mLastCollection(TimeStamp::Now()) {}
+
+  void StartRecording(const TimeStamp& aNow);
+  void StopRecording();
+  TimeDuration RecordExecution(const TimeStamp& aNow,
+                               bool aIsTracking,
+                               bool aIsBackground);
+  void MaybeCollectTelemetry(const TimeStamp& aNow);
+private:
+  struct TelemetryData
+  {
+    TimeDuration mForegroundTracking;
+    TimeDuration mForegroundNonTracking;
+    TimeDuration mBackgroundTracking;
+    TimeDuration mBackgroundNonTracking;
+  };
+
+  void Accumulate(Telemetry::HistogramID aId, const TimeDuration& aSample);
+
+  TelemetryData mTelemetryData;
+  TimeStamp mStart;
+  TimeStamp mLastCollection;
+};
+
+} // namespace dom
+} // namespace mozilla
+
+#endif // mozilla_dom_timeoutbudgetmanager_h
--- a/dom/base/TimeoutManager.cpp
+++ b/dom/base/TimeoutManager.cpp
@@ -9,133 +9,23 @@
 #include "mozilla/Logging.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/ThrottledEventQueue.h"
 #include "mozilla/TimeStamp.h"
 #include "nsITimeoutHandler.h"
 #include "mozilla/dom/TabGroup.h"
 #include "OrderedTimeoutIterator.h"
 #include "TimeoutExecutor.h"
+#include "TimeoutBudgetManager.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 static LazyLogModule gLog("Timeout");
 
-// Time between sampling timeout execution time.
-const uint32_t kTelemetryPeriodMS = 1000;
-
-class TimeoutBudgetManager
-{
-public:
-  static TimeoutBudgetManager& Get();
-  TimeoutBudgetManager() : mLastCollection(TimeStamp::Now()) {}
-
-  void StartRecording(const TimeStamp& aNow);
-  void StopRecording();
-  TimeDuration RecordExecution(const TimeStamp& aNow,
-                               bool aIsTracking,
-                               bool aIsBackground);
-  void MaybeCollectTelemetry(const TimeStamp& aNow);
-private:
-  struct TelemetryData
-  {
-    TimeDuration mForegroundTracking;
-    TimeDuration mForegroundNonTracking;
-    TimeDuration mBackgroundTracking;
-    TimeDuration mBackgroundNonTracking;
-  };
-
-  void Accumulate(Telemetry::HistogramID aId, const TimeDuration& aSample);
-
-  TelemetryData mTelemetryData;
-  TimeStamp mStart;
-  TimeStamp mLastCollection;
-};
-
-static TimeoutBudgetManager gTimeoutBudgetManager;
-
-/* static */ TimeoutBudgetManager&
-TimeoutBudgetManager::Get()
-{
-  return gTimeoutBudgetManager;
-}
-
-void
-TimeoutBudgetManager::StartRecording(const TimeStamp& aNow)
-{
-  mStart = aNow;
-}
-
-void
-TimeoutBudgetManager::StopRecording()
-{
-  mStart = TimeStamp();
-}
-
-TimeDuration
-TimeoutBudgetManager::RecordExecution(const TimeStamp& aNow,
-                                      bool aIsTracking,
-                                      bool aIsBackground)
-{
-  if (!mStart) {
-    // If we've started a sync operation mStart might be null, in
-    // which case we should not record this piece of execution.
-    return TimeDuration();
-  }
-
-  TimeDuration duration = aNow - mStart;
-
-  if (aIsBackground) {
-    if (aIsTracking) {
-      mTelemetryData.mBackgroundTracking += duration;
-    } else {
-      mTelemetryData.mBackgroundNonTracking += duration;
-    }
-  } else {
-    if (aIsTracking) {
-      mTelemetryData.mForegroundTracking += duration;
-    } else {
-      mTelemetryData.mForegroundNonTracking += duration;
-    }
-  }
-
-  return duration;
-}
-
-void
-TimeoutBudgetManager::Accumulate(Telemetry::HistogramID aId,
-                                 const TimeDuration& aSample)
-{
-  uint32_t sample = std::round(aSample.ToMilliseconds());
-  if (sample) {
-    Telemetry::Accumulate(aId, sample);
-  }
-}
-
-void
-TimeoutBudgetManager::MaybeCollectTelemetry(const TimeStamp& aNow)
-{
-  if ((aNow - mLastCollection).ToMilliseconds() < kTelemetryPeriodMS) {
-    return;
-  }
-
-  Accumulate(Telemetry::TIMEOUT_EXECUTION_FG_TRACKING_MS,
-             mTelemetryData.mForegroundTracking);
-  Accumulate(Telemetry::TIMEOUT_EXECUTION_FG_MS,
-             mTelemetryData.mForegroundNonTracking);
-  Accumulate(Telemetry::TIMEOUT_EXECUTION_BG_TRACKING_MS,
-             mTelemetryData.mBackgroundTracking);
-  Accumulate(Telemetry::TIMEOUT_EXECUTION_BG_MS,
-             mTelemetryData.mBackgroundNonTracking);
-
-  mTelemetryData = TelemetryData();
-  mLastCollection = aNow;
-}
-
 static int32_t              gRunningTimeoutDepth       = 0;
 
 // The default shortest interval/timeout we permit
 #define DEFAULT_MIN_CLAMP_TIMEOUT_VALUE 4 // 4ms
 #define DEFAULT_MIN_BACKGROUND_TIMEOUT_VALUE 1000 // 1000ms
 #define DEFAULT_MIN_TRACKING_TIMEOUT_VALUE 4 // 4ms
 #define DEFAULT_MIN_TRACKING_BACKGROUND_TIMEOUT_VALUE 1000 // 1000ms
 static int32_t gMinClampTimeoutValue = 0;
--- a/dom/base/moz.build
+++ b/dom/base/moz.build
@@ -347,16 +347,17 @@ UNIFIED_SOURCES += [
     'StructuredCloneHolder.cpp',
     'StyleSheetList.cpp',
     'SubtleCrypto.cpp',
     'TabGroup.cpp',
     'Text.cpp',
     'TextInputProcessor.cpp',
     'ThirdPartyUtil.cpp',
     'Timeout.cpp',
+    'TimeoutBudgetManager.cpp',
     'TimeoutExecutor.cpp',
     'TimeoutHandler.cpp',
     'TimeoutManager.cpp',
     'TreeWalker.cpp',
     'WebKitCSSMatrix.cpp',
     'WebSocket.cpp',
     'WindowNamedPropertiesHandler.cpp',
     'WindowOrientationObserver.cpp',