bug 1357742 - Drop INPUT_EVENT_RESPONSE_MS measurements across sleep/wake r?smaug draft
authorChris H-C <chutten@mozilla.com>
Wed, 19 Apr 2017 11:17:20 -0400
changeset 565123 10aa1516d856617582f180c10dd4e740400a57fb
parent 565030 c0ea5ed7f91a6be996a4a3c5ab25e2cdf6b4377e
child 624928 1b894e6a5e0f7ec1d521e1b0a755fa38afe29370
push id54798
push userbmo:chutten@mozilla.com
push dateWed, 19 Apr 2017 15:22:07 +0000
reviewerssmaug
bugs1357742
milestone55.0a1
bug 1357742 - Drop INPUT_EVENT_RESPONSE_MS measurements across sleep/wake r?smaug It is possible that events created before the OS goes to sleep will remain unhandled until after the OS wakes. They will have long response times on platforms where TimeStamp increments during sleep (like Windows) even though they really shouldn't. (and the user likely doesn't care if they do). So don't record those. MozReview-Commit-ID: 4ybjF8gjkae
layout/base/PresShell.cpp
layout/base/PresShell.h
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -848,17 +848,17 @@ PresShell::PresShell()
   , mIsLastChromeOnlyEscapeKeyConsumed(false)
   , mHasReceivedPaintMessage(false)
 {
 #ifdef MOZ_REFLOW_PERF
   mReflowCountMgr = new ReflowCountMgr();
   mReflowCountMgr->SetPresContext(mPresContext);
   mReflowCountMgr->SetPresShell(this);
 #endif
-  mLoadBegin = TimeStamp::Now();
+  mLastOSWake = mLoadBegin = TimeStamp::Now();
 
   mSelectionFlags = nsISelectionDisplay::DISPLAY_TEXT | nsISelectionDisplay::DISPLAY_IMAGES;
   mIsThemeSupportDisabled = false;
   mIsActive = true;
   // FIXME/bug 735029: find a better solution to this problem
   mIsFirstPaint = true;
   mPresShellId = sNextPresShellId++;
   mFrozen = false;
@@ -1018,16 +1018,17 @@ PresShell::Init(nsIDocument* aDocument,
 
   {
     nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
     if (os) {
 #ifdef MOZ_XUL
       os->AddObserver(this, "chrome-flush-skin-caches", false);
 #endif
       os->AddObserver(this, "memory-pressure", false);
+      os->AddObserver(this, NS_WIDGET_WAKE_OBSERVER_TOPIC, false);
     }
   }
 
 #ifdef MOZ_REFLOW_PERF
     if (mReflowCountMgr) {
       bool paintFrameCounts =
         Preferences::GetBool("layout.reflow.showframecounts");
 
@@ -1245,16 +1246,17 @@ PresShell::Destroy()
 
   {
     nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
     if (os) {
 #ifdef MOZ_XUL
       os->RemoveObserver(this, "chrome-flush-skin-caches");
 #endif
       os->RemoveObserver(this, "memory-pressure");
+      os->RemoveObserver(this, NS_WIDGET_WAKE_OBSERVER_TOPIC);
     }
   }
 
   // If our paint suppression timer is still active, kill it.
   if (mPaintSuppressionTimer) {
     mPaintSuppressionTimer->Cancel();
     mPaintSuppressionTimer = nullptr;
   }
@@ -8248,16 +8250,17 @@ PresShell::HandleEventInternal(WidgetEve
       break;
     default:
       break;
     }
   }
 
   if (Telemetry::CanRecordBase() &&
       !aEvent->mTimeStamp.IsNull() &&
+      aEvent->mTimeStamp > mLastOSWake &&
       aEvent->AsInputEvent()) {
     double millis = (TimeStamp::Now() - aEvent->mTimeStamp).ToMilliseconds();
     Telemetry::Accumulate(Telemetry::INPUT_EVENT_RESPONSE_MS, millis);
     if (mDocument && mDocument->GetReadyStateEnum() != nsIDocument::READYSTATE_COMPLETE) {
       Telemetry::Accumulate(Telemetry::LOAD_INPUT_EVENT_RESPONSE_MS, millis);
     }
   }
 
@@ -9683,16 +9686,20 @@ PresShell::Observe(nsISupports* aSubject
 
   if (!nsCRT::strcmp(aTopic, "memory-pressure")) {
     if (!AssumeAllFramesVisible() && mPresContext->IsRootContentDocument()) {
       DoUpdateApproximateFrameVisibility(/* aRemoveOnly = */ true);
     }
     return NS_OK;
   }
 
+  if (!nsCRT::strcmp(aTopic, NS_WIDGET_WAKE_OBSERVER_TOPIC)) {
+    mLastOSWake = TimeStamp::Now();
+  }
+
   NS_WARNING("unrecognized topic in PresShell::Observe");
   return NS_ERROR_FAILURE;
 }
 
 bool
 nsIPresShell::AddRefreshObserverInternal(nsARefreshObserver* aObserver,
                                          FlushType aFlushType)
 {
--- a/layout/base/PresShell.h
+++ b/layout/base/PresShell.h
@@ -901,13 +901,15 @@ protected:
   bool                      mIsLastChromeOnlyEscapeKeyConsumed : 1;
 
   // Whether the widget has received a paint message yet.
   bool                      mHasReceivedPaintMessage : 1;
 
   bool                      mIsLastKeyDownCanceled : 1;
 
   static bool               sDisableNonTestMouseEvents;
+
+  mozilla::TimeStamp        mLastOSWake;
 };
 
 } // namespace mozilla
 
 #endif // mozilla_PresShell_h