Bug 1441972 - Add probe for counting docgroups per tabgroup. r=nika, data-review=chutten
authorAndreas Farre <farre@mozilla.com>
Wed, 30 May 2018 05:48:00 +0300
changeset 420709 562b1f6ffe1898f14b3102b9ba5f2a5e7c6c73a5
parent 420708 516d9db19be35ad65ab546e78508f86e29c92522
child 420710 8f1c7005e2442848d542cd98e40c9150644e70ad
push id34077
push usernerli@mozilla.com
push dateThu, 31 May 2018 21:51:59 +0000
treeherdermozilla-central@42880a726964 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnika
bugs1441972
milestone62.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 1441972 - Add probe for counting docgroups per tabgroup. r=nika, data-review=chutten Add ACTIVE_DOCGROUPS_PER_TABGROUP and TOTAL_DOCGROUPS_PER_TABGROUP to collect data on how many docgroups a tabgroup has whenever a top level content document associated with that tabgroup would hide. This gives a fairly accurate estimate of the number of docgroups a site uses. TOTAL_* counts all docgroups while ACTIVE_* only count docgroups with at least one document not in the bfcache.
dom/base/DocGroup.cpp
dom/base/DocGroup.h
dom/base/TabGroup.cpp
dom/base/TabGroup.h
dom/base/nsDocument.cpp
toolkit/components/telemetry/Histograms.json
--- a/dom/base/DocGroup.cpp
+++ b/dom/base/DocGroup.cpp
@@ -179,10 +179,22 @@ DocGroup::MoveSignalSlotListTo(nsTArray<
   aDest.SetCapacity(aDest.Length() + mSignalSlotList.Length());
   for (RefPtr<HTMLSlotElement>& slot : mSignalSlotList) {
     slot->RemovedFromSignalSlotList();
     aDest.AppendElement(Move(slot));
   }
   mSignalSlotList.Clear();
 }
 
+bool
+DocGroup::IsActive() const
+{
+  for (nsIDocument* doc : mDocuments) {
+    if (doc->IsCurrentActiveDocument()) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
 }
 }
--- a/dom/base/DocGroup.h
+++ b/dom/base/DocGroup.h
@@ -117,16 +117,19 @@ public:
   // microtask.
   void SignalSlotChange(HTMLSlotElement& aSlot);
 
   void MoveSignalSlotListTo(nsTArray<RefPtr<HTMLSlotElement>>& aDest);
 
   // List of DocGroups that has non-empty signal slot list.
   static AutoTArray<RefPtr<DocGroup>, 2>* sPendingDocGroups;
 
+  // Returns true if any of its documents are active but not in the bfcache.
+  bool IsActive() const;
+
 private:
   DocGroup(TabGroup* aTabGroup, const nsACString& aKey);
   ~DocGroup();
 
   nsCString mKey;
   RefPtr<TabGroup> mTabGroup;
   nsTArray<nsIDocument*> mDocuments;
   RefPtr<mozilla::dom::CustomElementReactionsStack> mReactionsStack;
--- a/dom/base/TabGroup.cpp
+++ b/dom/base/TabGroup.cpp
@@ -301,10 +301,27 @@ TabGroup::IsBackground() const
     }
   }
   MOZ_ASSERT(foregrounded == mForegroundCount);
 #endif
 
   return mForegroundCount == 0;
 }
 
+uint32_t
+TabGroup::Count(bool aActiveOnly) const
+{
+  if (!aActiveOnly) {
+    return mDocGroups.Count();
+  }
+
+  uint32_t count = 0;
+  for (auto iter = mDocGroups.ConstIter(); !iter.Done(); iter.Next()) {
+    if (iter.Get()->mDocGroup->IsActive()) {
+      ++count;
+    }
+  }
+
+  return count;
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/base/TabGroup.h
+++ b/dom/base/TabGroup.h
@@ -95,16 +95,20 @@ public:
 
   void Leave(nsPIDOMWindowOuter* aWindow);
 
   Iterator Iter()
   {
     return mDocGroups.Iter();
   }
 
+  // Returns the size of the set of "similar-origin" DocGroups. To
+  // only consider DocGroups with at least one active document, call
+  // Count with 'aActiveOnly' = true
+  uint32_t Count(bool aActiveOnly = false) const;
 
   // Returns the nsIDocShellTreeItem with the given name, searching each of the
   // docShell trees which are within this TabGroup. It will pass itself as
   // aRequestor to each docShellTreeItem which it asks to search for the name,
   // and will not search the docShellTreeItem which is passed as aRequestor.
   //
   // This method is used in order to correctly namespace named windows based on
   // their unit of related browsing contexts.
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -8490,16 +8490,28 @@ DispatchFullScreenChange(nsIDocument* aT
     /* Bubbles */ true, /* OnlyChrome */ false);
 }
 
 static void ClearPendingFullscreenRequests(nsIDocument* aDoc);
 
 void
 nsIDocument::OnPageHide(bool aPersisted, EventTarget* aDispatchStartTarget)
 {
+  if (mDocGroup && Telemetry::CanRecordExtended() &&
+      IsTopLevelContentDocument()) {
+    TabGroup* tabGroup = mDocGroup->GetTabGroup();
+
+    if (tabGroup) {
+      Telemetry::Accumulate(Telemetry::ACTIVE_DOCGROUPS_PER_TABGROUP,
+                            tabGroup->Count(true /* aActiveOnly */));
+      Telemetry::Accumulate(Telemetry::TOTAL_DOCGROUPS_PER_TABGROUP,
+                            tabGroup->Count());
+    }
+  }
+
   // Send out notifications that our <link> elements are detached,
   // but only if this is not a full unload.
   Element* root = GetRootElement();
   if (aPersisted && root) {
     RefPtr<nsContentList> links = NS_GetContentList(root,
                                                     kNameSpaceID_XHTML,
                                                     NS_LITERAL_STRING("link"));
 
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -13779,10 +13779,30 @@
     "alert_emails": ["mnakano@mozilla.com"],
     "bug_numbers": [1452538,1449564],
     "expires_in_version": "65",
     "kind": "linear",
     "high": 50,
     "n_buckets": 20,
     "releaseChannelCollection": "opt-out",
     "description": "Number of HTML editors whose inline table editing UI is actually used by users."
+  },
+  "ACTIVE_DOCGROUPS_PER_TABGROUP": {
+    "record_in_processes": ["content"],
+    "alert_emails": ["farre@mozilla.com"],
+    "bug_numbers": [1441972],
+    "expires_in_version": "67",
+    "kind": "exponential",
+    "high": 50,
+    "n_buckets": 20,
+    "description": "Number of active doc groups per tab group. Collected at the point when the top level document of the tab group is unloaded."
+  },
+  "TOTAL_DOCGROUPS_PER_TABGROUP": {
+    "record_in_processes": ["content"],
+    "alert_emails": ["farre@mozilla.com"],
+    "bug_numbers": [1441972],
+    "expires_in_version": "67",
+    "kind": "exponential",
+    "high": 50,
+    "n_buckets": 20,
+    "description": "Total number of doc groups per tab group, including docgroups fully in bfcache. Collected at the point when the top level document of the tab group is unloaded."
   }
 }