Bug 1518624 - Add telemetry for amount and length in pixels of scroll anchor adjustments. r=dholbert
authorRyan Hunt <rhunt@eqrion.net>
Tue, 08 Jan 2019 15:18:12 -0600
changeset 514214 bd1415025d3e6b5fdf51803201ce06081beffd95
parent 514213 8e7a368e513a746650e08297b50c4d8ec971386c
child 514215 24f969298ec5c1a7cbc444bfc8f3d77b07f46bbe
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1518624
milestone66.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 1518624 - Add telemetry for amount and length in pixels of scroll anchor adjustments. r=dholbert This commit adds two new telemetry probes to collect: 1. The amount of scroll anchoring adjustments applied 2. The total absolute length in CSS pixels of scroll anchoring adjustments Both of these metrics are collected on a per top-level-document basis, and reported with other use-counters. Differential Revision: https://phabricator.services.mozilla.com/D16271
dom/base/Document.cpp
dom/base/Document.h
layout/generic/ScrollAnchorContainer.cpp
toolkit/components/telemetry/Histograms.json
--- a/dom/base/Document.cpp
+++ b/dom/base/Document.cpp
@@ -1326,16 +1326,18 @@ Document::Document(const char* aContentT
       mUserGestureActivated(false),
       mStackRefCnt(0),
       mUpdateNestLevel(0),
       mViewportType(Unknown),
       mViewportOverflowType(ViewportOverflowType::NoOverflow),
       mSubDocuments(nullptr),
       mHeaderData(nullptr),
       mFlashClassification(FlashClassification::Unknown),
+      mScrollAnchorAdjustmentLength(0),
+      mScrollAnchorAdjustmentCount(0),
       mBoxObjectTable(nullptr),
       mCurrentOrientationAngle(0),
       mCurrentOrientationType(OrientationType::Portrait_primary),
       mServoRestyleRootDirtyBits(0),
       mThrowOnDynamicMarkupInsertionCounter(0),
       mIgnoreOpensDuringUnloadCounter(0),
       mDocLWTheme(Doc_Theme_Uninitialized),
       mSavedResolution(1.0f) {
@@ -6911,16 +6913,21 @@ void Document::UpdateViewportOverflowTyp
     if (aScrolledWidth * minScale.scale < aScrollportWidth) {
       mViewportOverflowType = ViewportOverflowType::ButNotMinScaleSize;
     } else {
       mViewportOverflowType = ViewportOverflowType::MinScaleSize;
     }
   }
 }
 
+void Document::UpdateForScrollAnchorAdjustment(nscoord aLength) {
+  mScrollAnchorAdjustmentLength += abs(aLength);
+  mScrollAnchorAdjustmentCount += 1;
+}
+
 EventListenerManager* Document::GetOrCreateListenerManager() {
   if (!mListenerManager) {
     mListenerManager =
         new EventListenerManager(static_cast<EventTarget*>(this));
     SetFlags(NODE_HAS_LISTENERMANAGER);
   }
 
   return mListenerManager;
@@ -11338,16 +11345,25 @@ void Document::ReportUseCounters(UseCoun
       CASE_OVERFLOW_TYPE(NoOverflow)
       CASE_OVERFLOW_TYPE(Desktop)
       CASE_OVERFLOW_TYPE(ButNotMinScaleSize)
       CASE_OVERFLOW_TYPE(MinScaleSize)
 #undef CASE_OVERFLOW_TYPE
     }
     Telemetry::AccumulateCategorical(label);
   }
+
+  if (IsTopLevelContentDocument()) {
+    CSSIntCoord adjustmentLength =
+        CSSPixel::FromAppUnits(mScrollAnchorAdjustmentLength).Rounded();
+    Telemetry::Accumulate(Telemetry::SCROLL_ANCHOR_ADJUSTMENT_LENGTH,
+                          adjustmentLength);
+    Telemetry::Accumulate(Telemetry::SCROLL_ANCHOR_ADJUSTMENT_COUNT,
+                          mScrollAnchorAdjustmentCount);
+  }
 }
 
 void Document::UpdateIntersectionObservations() {
   if (mIntersectionObservers.IsEmpty()) {
     return;
   }
 
   DOMHighResTimeStamp time = 0;
--- a/dom/base/Document.h
+++ b/dom/base/Document.h
@@ -1277,16 +1277,18 @@ class Document : public nsINode,
    * This should only be called when there is out-of-reach overflow
    * happens on the viewport, i.e. the viewport should be using
    * `overflow: hidden`. And it should only be called on a top level
    * content document.
    */
   void UpdateViewportOverflowType(nscoord aScrolledWidth,
                                   nscoord aScrollportWidth);
 
+  void UpdateForScrollAnchorAdjustment(nscoord aLength);
+
   /**
    * True iff this doc will ignore manual character encoding overrides.
    */
   virtual bool WillIgnoreCharsetOverride() { return true; }
 
   /**
    * Return whether the document was created by a srcdoc iframe.
    */
@@ -4336,16 +4338,19 @@ class Document : public nsINode,
 
   // Recorded time of change to 'loading' state.
   mozilla::TimeStamp mLoadingTimeStamp;
 
   nsWeakPtr mAutoFocusElement;
 
   nsCString mScrollToRef;
 
+  nscoord mScrollAnchorAdjustmentLength;
+  int32_t mScrollAnchorAdjustmentCount;
+
   // Weak reference to the scope object (aka the script global object)
   // that, unlike mScriptGlobalObject, is never unset once set. This
   // is a weak reference to avoid leaks due to circular references.
   nsWeakPtr mScopeObject;
 
   // Array of intersection observers
   nsTHashtable<nsPtrHashKey<mozilla::dom::DOMIntersectionObserver>>
       mIntersectionObservers;
--- a/layout/generic/ScrollAnchorContainer.cpp
+++ b/layout/generic/ScrollAnchorContainer.cpp
@@ -285,16 +285,24 @@ void ScrollAnchorContainer::ApplyAdjustm
   MOZ_ASSERT(!mApplyingAnchorAdjustment);
   // We should use AutoRestore here, but that doesn't work with bitfields
   mApplyingAnchorAdjustment = true;
   mScrollFrame->ScrollBy(
       adjustmentDevicePixels, nsIScrollableFrame::DEVICE_PIXELS,
       nsIScrollableFrame::INSTANT, nullptr, nsGkAtoms::relative);
   mApplyingAnchorAdjustment = false;
 
+  nsPresContext* pc = Frame()->PresContext();
+  Document* doc = pc->Document();
+  if (writingMode.IsVertical()) {
+    doc->UpdateForScrollAnchorAdjustment(adjustment.x);
+  } else {
+    doc->UpdateForScrollAnchorAdjustment(adjustment.y);
+  }
+
   // The anchor position may not be in the same relative position after
   // adjustment. Update ourselves so we have consistent state.
   mLastAnchorPos =
       FindScrollAnchoringBoundingRect(Frame(), mAnchorNode).TopLeft();
 }
 
 ScrollAnchorContainer::ExamineResult
 ScrollAnchorContainer::ExamineAnchorCandidate(nsIFrame* aFrame) const {
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -14527,10 +14527,36 @@
       "esawin@mozilla.com"
     ],
     "expires_in_version": "never",
     "kind": "exponential",
     "high": 5000,
     "n_buckets": 50,
     "bug_numbers": [1499418],
     "description": "GeckoView: Time taken to initialize all GeckoView modules in ms."
+  },
+  "SCROLL_ANCHOR_ADJUSTMENT_LENGTH": {
+    "record_in_processes": ["main", "content"],
+    "alert_emails": [
+      "rhunt@mozilla.com"
+    ],
+    "expires_in_version": "70",
+    "kind": "exponential",
+    "low": 1,
+    "high": 10000,
+    "n_buckets": 50,
+    "bug_numbers": [1518624],
+    "description": "The absolute length in CSS pixels of all scroll adjustments performed by scroll anchoring in a top-level document."
+  },
+  "SCROLL_ANCHOR_ADJUSTMENT_COUNT": {
+    "record_in_processes": ["main", "content"],
+    "alert_emails": [
+      "rhunt@mozilla.com"
+    ],
+    "expires_in_version": "70",
+    "kind": "exponential",
+    "low": 1,
+    "high": 500,
+    "n_buckets": 50,
+    "bug_numbers": [1518624],
+    "description": "The amount of scroll adjustments performed by scroll anchoring in a top-level document."
   }
 }