Bug 1690905 - Factors DOM memory sizes out to its own struct r=mccr8

This patch factors the DOM related sizes in nsWindowSizes to its own
struct, such that callers can easily acess DOM memory sizes.

Differential Revision: https://phabricator.services.mozilla.com/D111317
This commit is contained in:
Sean Feng 2021-05-27 17:55:44 +00:00
parent a38a1616b0
commit e58bb429df
9 changed files with 138 additions and 85 deletions

View File

@ -14889,7 +14889,8 @@ void Document::MaybeActiveMediaComponents() {
}
void Document::DocAddSizeOfExcludingThis(nsWindowSizes& aWindowSizes) const {
nsINode::AddSizeOfExcludingThis(aWindowSizes, &aWindowSizes.mDOMOtherSize);
nsINode::AddSizeOfExcludingThis(aWindowSizes,
&aWindowSizes.mDOMSizes.mDOMOtherSize);
for (nsIContent* kid = GetFirstChild(); kid; kid = kid->GetNextSibling()) {
AddSizeOfNodeTree(*kid, aWindowSizes);
@ -14919,11 +14920,12 @@ void Document::DocAddSizeOfExcludingThis(nsWindowSizes& aWindowSizes) const {
mNodeInfoManager->AddSizeOfIncludingThis(aWindowSizes);
}
aWindowSizes.mDOMMediaQueryLists += mDOMMediaQueryLists.sizeOfExcludingThis(
aWindowSizes.mState.mMallocSizeOf);
aWindowSizes.mDOMSizes.mDOMMediaQueryLists +=
mDOMMediaQueryLists.sizeOfExcludingThis(
aWindowSizes.mState.mMallocSizeOf);
for (const MediaQueryList* mql : mDOMMediaQueryLists) {
aWindowSizes.mDOMMediaQueryLists +=
aWindowSizes.mDOMSizes.mDOMMediaQueryLists +=
mql->SizeOfExcludingThis(aWindowSizes.mState.mMallocSizeOf);
}
@ -14945,13 +14947,14 @@ void Document::DocAddSizeOfExcludingThis(nsWindowSizes& aWindowSizes) const {
mResizeObserverController->AddSizeOfIncludingThis(aWindowSizes);
}
aWindowSizes.mDOMOtherSize += mAttrStyleSheet
? mAttrStyleSheet->DOMSizeOfIncludingThis(
aWindowSizes.mState.mMallocSizeOf)
: 0;
aWindowSizes.mDOMSizes.mDOMOtherSize +=
mAttrStyleSheet ? mAttrStyleSheet->DOMSizeOfIncludingThis(
aWindowSizes.mState.mMallocSizeOf)
: 0;
aWindowSizes.mDOMOtherSize += mStyledLinks.ShallowSizeOfExcludingThis(
aWindowSizes.mState.mMallocSizeOf);
aWindowSizes.mDOMSizes.mDOMOtherSize +=
mStyledLinks.ShallowSizeOfExcludingThis(
aWindowSizes.mState.mMallocSizeOf);
// Measurement of the following members may be added later if DMD finds it
// is worthwhile:
@ -14960,7 +14963,8 @@ void Document::DocAddSizeOfExcludingThis(nsWindowSizes& aWindowSizes) const {
}
void Document::DocAddSizeOfIncludingThis(nsWindowSizes& aWindowSizes) const {
aWindowSizes.mDOMOtherSize += aWindowSizes.mState.mMallocSizeOf(this);
aWindowSizes.mDOMSizes.mDOMOtherSize +=
aWindowSizes.mState.mMallocSizeOf(this);
DocAddSizeOfExcludingThis(aWindowSizes);
}
@ -14982,19 +14986,19 @@ void Document::AddSizeOfNodeTree(nsINode& aNode, nsWindowSizes& aWindowSizes) {
// nsINode::AddSizeOfIncludingThis() to a value in nsWindowSizes.
switch (aNode.NodeType()) {
case nsINode::ELEMENT_NODE:
aWindowSizes.mDOMElementNodesSize += nodeSize;
aWindowSizes.mDOMSizes.mDOMElementNodesSize += nodeSize;
break;
case nsINode::TEXT_NODE:
aWindowSizes.mDOMTextNodesSize += nodeSize;
aWindowSizes.mDOMSizes.mDOMTextNodesSize += nodeSize;
break;
case nsINode::CDATA_SECTION_NODE:
aWindowSizes.mDOMCDATANodesSize += nodeSize;
aWindowSizes.mDOMSizes.mDOMCDATANodesSize += nodeSize;
break;
case nsINode::COMMENT_NODE:
aWindowSizes.mDOMCommentNodesSize += nodeSize;
aWindowSizes.mDOMSizes.mDOMCommentNodesSize += nodeSize;
break;
default:
aWindowSizes.mDOMOtherSize += nodeSize;
aWindowSizes.mDOMSizes.mDOMOtherSize += nodeSize;
break;
}

View File

@ -55,7 +55,7 @@ void DocumentOrShadowRoot::AddSizeOfOwnedSheetArrayExcludingThis(
void DocumentOrShadowRoot::AddSizeOfExcludingThis(nsWindowSizes& aSizes) const {
AddSizeOfOwnedSheetArrayExcludingThis(aSizes, mStyleSheets);
aSizes.mDOMOtherSize +=
aSizes.mDOMSizes.mDOMOtherSize +=
mIdentifierMap.SizeOfExcludingThis(aSizes.mState.mMallocSizeOf);
}

View File

@ -220,7 +220,7 @@ void ResizeObserverController::AddSizeOfIncludingThis(
size += mResizeObservers.ShallowSizeOfExcludingThis(mallocSizeOf);
// TODO(emilio): Measure the observers individually or something? They aren't
// really owned by us.
aSizes.mDOMResizeObserverControllerSize += size;
aSizes.mDOMSizes.mDOMResizeObserverControllerSize += size;
}
} // namespace mozilla::dom

View File

@ -6598,13 +6598,15 @@ bool nsGlobalWindowInner::IsVRContentPresenting() const {
void nsGlobalWindowInner::AddSizeOfIncludingThis(
nsWindowSizes& aWindowSizes) const {
aWindowSizes.mDOMOtherSize += aWindowSizes.mState.mMallocSizeOf(this);
aWindowSizes.mDOMOtherSize += nsIGlobalObject::ShallowSizeOfExcludingThis(
aWindowSizes.mState.mMallocSizeOf);
aWindowSizes.mDOMSizes.mDOMOtherSize +=
aWindowSizes.mState.mMallocSizeOf(this);
aWindowSizes.mDOMSizes.mDOMOtherSize +=
nsIGlobalObject::ShallowSizeOfExcludingThis(
aWindowSizes.mState.mMallocSizeOf);
EventListenerManager* elm = GetExistingListenerManager();
if (elm) {
aWindowSizes.mDOMOtherSize +=
aWindowSizes.mDOMSizes.mDOMOtherSize +=
elm->SizeOfIncludingThis(aWindowSizes.mState.mMallocSizeOf);
aWindowSizes.mDOMEventListenersCount += elm->ListenerCount();
}
@ -6618,13 +6620,13 @@ void nsGlobalWindowInner::AddSizeOfIncludingThis(
}
if (mNavigator) {
aWindowSizes.mDOMOtherSize +=
aWindowSizes.mDOMSizes.mDOMOtherSize +=
mNavigator->SizeOfIncludingThis(aWindowSizes.mState.mMallocSizeOf);
}
ForEachEventTargetObject([&](DOMEventTargetHelper* et, bool* aDoneOut) {
if (nsCOMPtr<nsISizeOfEventTarget> iSizeOf = do_QueryObject(et)) {
aWindowSizes.mDOMEventTargetsSize +=
aWindowSizes.mDOMSizes.mDOMEventTargetsSize +=
iSizeOf->SizeOfEventTargetIncludingThis(
aWindowSizes.mState.mMallocSizeOf);
}
@ -6635,11 +6637,11 @@ void nsGlobalWindowInner::AddSizeOfIncludingThis(
});
if (mPerformance) {
aWindowSizes.mDOMPerformanceUserEntries =
aWindowSizes.mDOMSizes.mDOMPerformanceUserEntries =
mPerformance->SizeOfUserEntries(aWindowSizes.mState.mMallocSizeOf);
aWindowSizes.mDOMPerformanceResourceEntries =
aWindowSizes.mDOMSizes.mDOMPerformanceResourceEntries =
mPerformance->SizeOfResourceEntries(aWindowSizes.mState.mMallocSizeOf);
aWindowSizes.mDOMPerformanceEventEntries =
aWindowSizes.mDOMSizes.mDOMPerformanceEventEntries =
mPerformance->SizeOfEventEntries(aWindowSizes.mState.mMallocSizeOf);
}
}

View File

@ -7370,7 +7370,8 @@ nsresult nsGlobalWindowOuter::RestoreWindowState(nsISupports* aState) {
void nsGlobalWindowOuter::AddSizeOfIncludingThis(
nsWindowSizes& aWindowSizes) const {
aWindowSizes.mDOMOtherSize += aWindowSizes.mState.mMallocSizeOf(this);
aWindowSizes.mDOMSizes.mDOMOtherSize +=
aWindowSizes.mState.mMallocSizeOf(this);
}
uint32_t nsGlobalWindowOuter::GetAutoActivateVRDisplayID() {

View File

@ -410,7 +410,7 @@ bool nsNodeInfoManager::InternalMathMLEnabled() {
}
void nsNodeInfoManager::AddSizeOfIncludingThis(nsWindowSizes& aSizes) const {
aSizes.mDOMOtherSize += aSizes.mState.mMallocSizeOf(this);
aSizes.mDOMSizes.mDOMOtherSize += aSizes.mState.mMallocSizeOf(this);
// Measurement of the following members may be added later if DMD finds it
// is worthwhile:

View File

@ -205,6 +205,54 @@ static void ReportCount(const nsCString& aBasePath, const char* aPathTail,
aHandleReport, aData);
}
static void ReportDOMSize(const nsCString& aBasePath,
nsDOMSizes& aTotalDOMSizes,
nsIHandleReportCallback* aHandleReport,
nsISupports* aData, nsDOMSizes aDOMSizes) {
#define REPORT_DOM_SIZE(_windowPath, _pathTail, _field, _desc) \
ReportSize(_windowPath, _pathTail, aDOMSizes._field, \
nsLiteralCString(_desc), aHandleReport, aData); \
aTotalDOMSizes._field += aDOMSizes._field;
REPORT_DOM_SIZE(aBasePath, "/dom/element-nodes", mDOMElementNodesSize,
"Memory used by the element nodes in a window's DOM.");
REPORT_DOM_SIZE(aBasePath, "/dom/text-nodes", mDOMTextNodesSize,
"Memory used by the text nodes in a window's DOM.");
REPORT_DOM_SIZE(aBasePath, "/dom/cdata-nodes", mDOMCDATANodesSize,
"Memory used by the CDATA nodes in a window's DOM.");
REPORT_DOM_SIZE(aBasePath, "/dom/comment-nodes", mDOMCommentNodesSize,
"Memory used by the comment nodes in a window's DOM.");
REPORT_DOM_SIZE(
aBasePath, "/dom/event-targets", mDOMEventTargetsSize,
"Memory used by the event targets table in a window's DOM, and "
"the objects it points to, which include XHRs.");
REPORT_DOM_SIZE(aBasePath, "/dom/performance/user-entries",
mDOMPerformanceUserEntries,
"Memory used for performance user entries.");
REPORT_DOM_SIZE(aBasePath, "/dom/performance/resource-entries",
mDOMPerformanceResourceEntries,
"Memory used for performance resource entries.");
REPORT_DOM_SIZE(aBasePath, "/dom/media-query-lists", mDOMMediaQueryLists,
"Memory used by MediaQueryList objects for the window's "
"document.");
REPORT_DOM_SIZE(aBasePath, "/dom/resize-observers",
mDOMResizeObserverControllerSize,
"Memory used for resize observers.");
REPORT_DOM_SIZE(aBasePath, "/dom/other", mDOMOtherSize,
"Memory used by a window's DOM that isn't measured by the "
"other 'dom/' numbers.");
#undef REPORT_DOM_SIZE
}
static void CollectWindowReports(nsGlobalWindowInner* aWindow,
nsWindowSizes* aWindowTotalSizes,
nsTHashSet<uint64_t>* aGhostWindowIDs,
@ -279,39 +327,8 @@ static void CollectWindowReports(nsGlobalWindowInner* aWindow,
nsWindowSizes windowSizes(state);
aWindow->AddSizeOfIncludingThis(windowSizes);
REPORT_SIZE("/dom/element-nodes", mDOMElementNodesSize,
"Memory used by the element nodes in a window's DOM.");
REPORT_SIZE("/dom/text-nodes", mDOMTextNodesSize,
"Memory used by the text nodes in a window's DOM.");
REPORT_SIZE("/dom/cdata-nodes", mDOMCDATANodesSize,
"Memory used by the CDATA nodes in a window's DOM.");
REPORT_SIZE("/dom/comment-nodes", mDOMCommentNodesSize,
"Memory used by the comment nodes in a window's DOM.");
REPORT_SIZE("/dom/event-targets", mDOMEventTargetsSize,
"Memory used by the event targets table in a window's DOM, and "
"the objects it points to, which include XHRs.");
REPORT_SIZE("/dom/performance/user-entries", mDOMPerformanceUserEntries,
"Memory used for performance user entries.");
REPORT_SIZE("/dom/performance/resource-entries",
mDOMPerformanceResourceEntries,
"Memory used for performance resource entries.");
REPORT_SIZE("/dom/media-query-lists", mDOMMediaQueryLists,
"Memory used by MediaQueryList objects for the window's "
"document.");
REPORT_SIZE("/dom/resize-observers", mDOMResizeObserverControllerSize,
"Memory used for resize observers.");
REPORT_SIZE("/dom/other", mDOMOtherSize,
"Memory used by a window's DOM that isn't measured by the "
"other 'dom/' numbers.");
ReportDOMSize(windowPath, aWindowTotalSizes->mDOMSizes, aHandleReport, aData,
windowSizes.mDOMSizes);
REPORT_SIZE("/layout/style-sheets", mLayoutStyleSheetsSize,
"Memory used by document style sheets within a window.");
@ -562,29 +579,31 @@ nsWindowMemoryReporter::CollectReports(nsIHandleReportCallback* aHandleReport,
aData);
REPORT("window-objects/dom/element-nodes",
windowTotalSizes.mDOMElementNodesSize,
windowTotalSizes.mDOMSizes.mDOMElementNodesSize,
"This is the sum of all windows' 'dom/element-nodes' numbers.");
REPORT("window-objects/dom/text-nodes", windowTotalSizes.mDOMTextNodesSize,
REPORT("window-objects/dom/text-nodes",
windowTotalSizes.mDOMSizes.mDOMTextNodesSize,
"This is the sum of all windows' 'dom/text-nodes' numbers.");
REPORT("window-objects/dom/cdata-nodes", windowTotalSizes.mDOMCDATANodesSize,
REPORT("window-objects/dom/cdata-nodes",
windowTotalSizes.mDOMSizes.mDOMCDATANodesSize,
"This is the sum of all windows' 'dom/cdata-nodes' numbers.");
REPORT("window-objects/dom/comment-nodes",
windowTotalSizes.mDOMCommentNodesSize,
windowTotalSizes.mDOMSizes.mDOMCommentNodesSize,
"This is the sum of all windows' 'dom/comment-nodes' numbers.");
REPORT("window-objects/dom/event-targets",
windowTotalSizes.mDOMEventTargetsSize,
windowTotalSizes.mDOMSizes.mDOMEventTargetsSize,
"This is the sum of all windows' 'dom/event-targets' numbers.");
REPORT("window-objects/dom/performance",
windowTotalSizes.mDOMPerformanceUserEntries +
windowTotalSizes.mDOMPerformanceResourceEntries,
windowTotalSizes.mDOMSizes.mDOMPerformanceUserEntries +
windowTotalSizes.mDOMSizes.mDOMPerformanceResourceEntries,
"This is the sum of all windows' 'dom/performance/' numbers.");
REPORT("window-objects/dom/other", windowTotalSizes.mDOMOtherSize,
REPORT("window-objects/dom/other", windowTotalSizes.mDOMSizes.mDOMOtherSize,
"This is the sum of all windows' 'dom/other' numbers.");
REPORT("window-objects/layout/style-sheets",

View File

@ -132,19 +132,41 @@ struct nsArenaSizes {
int dummy;
};
struct nsDOMSizes {
#define FOR_EACH_SIZE(MACRO) \
MACRO(DOM, mDOMElementNodesSize) \
MACRO(DOM, mDOMTextNodesSize) \
MACRO(DOM, mDOMCDATANodesSize) \
MACRO(DOM, mDOMCommentNodesSize) \
MACRO(DOM, mDOMEventTargetsSize) \
MACRO(DOM, mDOMMediaQueryLists) \
MACRO(DOM, mDOMPerformanceEventEntries) \
MACRO(DOM, mDOMPerformanceUserEntries) \
MACRO(DOM, mDOMPerformanceResourceEntries) \
MACRO(DOM, mDOMResizeObserverControllerSize)
nsDOMSizes() : FOR_EACH_SIZE(ZERO_SIZE) mDOMOtherSize(0) {}
void addToTabSizes(nsTabSizes* aSizes) const {
FOR_EACH_SIZE(ADD_TO_TAB_SIZES)
aSizes->add(nsTabSizes::DOM, mDOMOtherSize);
}
size_t getTotalSize() const {
size_t total = 0;
FOR_EACH_SIZE(ADD_TO_TOTAL_SIZE)
total += mDOMOtherSize;
return total;
}
FOR_EACH_SIZE(DECL_SIZE)
size_t mDOMOtherSize;
#undef FOR_EACH_SIZE
};
class nsWindowSizes {
#define FOR_EACH_SIZE(MACRO) \
MACRO(DOM, mDOMElementNodesSize) \
MACRO(DOM, mDOMTextNodesSize) \
MACRO(DOM, mDOMCDATANodesSize) \
MACRO(DOM, mDOMCommentNodesSize) \
MACRO(DOM, mDOMEventTargetsSize) \
MACRO(DOM, mDOMMediaQueryLists) \
MACRO(DOM, mDOMPerformanceEventEntries) \
MACRO(DOM, mDOMPerformanceUserEntries) \
MACRO(DOM, mDOMPerformanceResourceEntries) \
MACRO(DOM, mDOMResizeObserverControllerSize) \
MACRO(DOM, mDOMOtherSize) \
MACRO(Style, mLayoutStyleSheetsSize) \
MACRO(Style, mLayoutShadowDomStyleSheetsSize) \
MACRO(Style, mLayoutShadowDomAuthorStyles) \
@ -177,6 +199,7 @@ class nsWindowSizes {
void addToTabSizes(nsTabSizes* aSizes) const {
FOR_EACH_SIZE(ADD_TO_TAB_SIZES)
mDOMSizes.addToTabSizes(aSizes);
mArenaSizes.addToTabSizes(aSizes);
mStyleSizes.addToTabSizes(aSizes);
}
@ -185,6 +208,7 @@ class nsWindowSizes {
size_t total = 0;
FOR_EACH_SIZE(ADD_TO_TOTAL_SIZE)
total += mDOMSizes.getTotalSize();
total += mArenaSizes.getTotalSize();
total += mStyleSizes.getTotalSize();
@ -196,6 +220,8 @@ class nsWindowSizes {
uint32_t mDOMEventTargetsCount;
uint32_t mDOMEventListenersCount;
nsDOMSizes mDOMSizes;
nsArenaSizes mArenaSizes;
nsStyleSizes mStyleSizes;

View File

@ -189,15 +189,16 @@ class ContentBlockingLog final {
}
void AddSizeOfExcludingThis(nsWindowSizes& aSizes) const {
aSizes.mDOMOtherSize +=
aSizes.mDOMSizes.mDOMOtherSize +=
mLog.ShallowSizeOfExcludingThis(aSizes.mState.mMallocSizeOf);
// Now add the sizes of each origin log queue.
for (const OriginEntry& entry : mLog) {
if (entry.mData) {
aSizes.mDOMOtherSize += aSizes.mState.mMallocSizeOf(entry.mData.get()) +
entry.mData->mLogs.ShallowSizeOfExcludingThis(
aSizes.mState.mMallocSizeOf);
aSizes.mDOMSizes.mDOMOtherSize +=
aSizes.mState.mMallocSizeOf(entry.mData.get()) +
entry.mData->mLogs.ShallowSizeOfExcludingThis(
aSizes.mState.mMallocSizeOf);
}
}
}