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
--- 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