From 20b8376ffd49814cd64c1a2b1721c7c274820362 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Wed, 31 May 2017 19:52:47 +0100 Subject: [PATCH] Bug 1368654 - pt 1 - Implement memory reporter support for FrameProperties. r=mats --- dom/base/nsDocument.cpp | 3 ++- dom/base/nsWindowMemoryReporter.cpp | 9 +++++++++ dom/base/nsWindowMemoryReporter.h | 1 + layout/base/FrameProperties.h | 3 +++ layout/base/PresShell.cpp | 17 ++++++++++++----- layout/base/PresShell.h | 11 ++++++----- layout/base/nsIPresShell.h | 11 ++++++----- layout/generic/nsFrame.cpp | 20 ++++++++++++++++++++ layout/generic/nsIFrame.h | 3 +++ 9 files changed, 62 insertions(+), 16 deletions(-) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 3cf56a224a50..c5ba207988bc 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -12338,7 +12338,8 @@ nsIDocument::DocAddSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const &aWindowSizes->mLayoutPresShellSize, &aWindowSizes->mLayoutStyleSetsSize, &aWindowSizes->mLayoutTextRunsSize, - &aWindowSizes->mLayoutPresContextSize); + &aWindowSizes->mLayoutPresContextSize, + &aWindowSizes->mLayoutFramePropertiesSize); } aWindowSizes->mPropertyTablesSize += diff --git a/dom/base/nsWindowMemoryReporter.cpp b/dom/base/nsWindowMemoryReporter.cpp index 5e808b0fe00f..108c094b0387 100644 --- a/dom/base/nsWindowMemoryReporter.cpp +++ b/dom/base/nsWindowMemoryReporter.cpp @@ -400,6 +400,12 @@ CollectWindowReports(nsGlobalWindow *aWindow, aWindowTotalSizes->mLayoutPresContextSize += windowSizes.mLayoutPresContextSize; + REPORT_SIZE("/layout/frame-properties", windowSizes.mLayoutFramePropertiesSize, + "Memory used for frame properties attached to frames " + "within a window."); + aWindowTotalSizes->mLayoutFramePropertiesSize += + windowSizes.mLayoutFramePropertiesSize; + // There are many different kinds of frames, but it is very likely // that only a few matter. Implement a cutoff so we don't bloat // about:memory with many uninteresting entries. @@ -565,6 +571,9 @@ nsWindowMemoryReporter::CollectReports(nsIHandleReportCallback* aHandleReport, REPORT("window-objects/layout/pres-contexts", windowTotalSizes.mLayoutPresContextSize, "This is the sum of all windows' 'layout/pres-contexts' numbers."); + REPORT("window-objects/layout/frame-properties", windowTotalSizes.mLayoutFramePropertiesSize, + "This is the sum of all windows' 'layout/frame-properties' numbers."); + size_t frameTotal = 0; #define FRAME_ID(classname, ...) \ frameTotal += windowTotalSizes.mArenaStats.FRAME_ID_STAT_FIELD(classname); diff --git a/dom/base/nsWindowMemoryReporter.h b/dom/base/nsWindowMemoryReporter.h index b9e9869590e6..5d40dc9f562c 100644 --- a/dom/base/nsWindowMemoryReporter.h +++ b/dom/base/nsWindowMemoryReporter.h @@ -33,6 +33,7 @@ class nsWindowSizes { macro(Style, mLayoutStyleSetsSize) \ macro(Other, mLayoutTextRunsSize) \ macro(Other, mLayoutPresContextSize) \ + macro(Other, mLayoutFramePropertiesSize) \ macro(Other, mPropertyTablesSize) \ public: diff --git a/layout/base/FrameProperties.h b/layout/base/FrameProperties.h index 885a86852dcd..ac48f878d0bd 100644 --- a/layout/base/FrameProperties.h +++ b/layout/base/FrameProperties.h @@ -268,6 +268,9 @@ public: void DeleteAll(const nsIFrame* aFrame); size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; + size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { + return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf); + } private: friend class ::nsIFrame; diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp index 73754aef2990..ba0f1adbc707 100644 --- a/layout/base/PresShell.cpp +++ b/layout/base/PresShell.cpp @@ -10957,11 +10957,12 @@ PresShell::GetRootPresShell() void PresShell::AddSizeOfIncludingThis(MallocSizeOf aMallocSizeOf, - nsArenaMemoryStats *aArenaObjectsSize, - size_t *aPresShellSize, - size_t *aStyleSetsSize, - size_t *aTextRunsSize, - size_t *aPresContextSize) + nsArenaMemoryStats* aArenaObjectsSize, + size_t* aPresShellSize, + size_t* aStyleSetsSize, + size_t* aTextRunsSize, + size_t* aPresContextSize, + size_t* aFramePropertiesSize) { mFrameArena.AddSizeOfExcludingThis(aMallocSizeOf, aArenaObjectsSize); *aPresShellSize += aMallocSizeOf(this); @@ -10983,6 +10984,12 @@ PresShell::AddSizeOfIncludingThis(MallocSizeOf aMallocSizeOf, *aTextRunsSize += SizeOfTextRuns(aMallocSizeOf); *aPresContextSize += mPresContext->SizeOfIncludingThis(aMallocSizeOf); + + nsIFrame* rootFrame = mFrameConstructor->GetRootFrame(); + if (rootFrame) { + *aFramePropertiesSize += + rootFrame->SizeOfFramePropertiesForTree(aMallocSizeOf); + } } size_t diff --git a/layout/base/PresShell.h b/layout/base/PresShell.h index 3132538722c1..b1687bff111c 100644 --- a/layout/base/PresShell.h +++ b/layout/base/PresShell.h @@ -370,11 +370,12 @@ public: virtual void LoadComplete() override; void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf, - nsArenaMemoryStats *aArenaObjectsSize, - size_t *aPresShellSize, - size_t *aStyleSetsSize, - size_t *aTextRunsSize, - size_t *aPresContextSize) override; + nsArenaMemoryStats* aArenaObjectsSize, + size_t* aPresShellSize, + size_t* aStyleSetsSize, + size_t* aTextRunsSize, + size_t* aPresContextSize, + size_t* aFramePropertiesSize) override; size_t SizeOfTextRuns(mozilla::MallocSizeOf aMallocSizeOf) const; // This data is stored as a content property (nsGkAtoms::scrolling) on diff --git a/layout/base/nsIPresShell.h b/layout/base/nsIPresShell.h index 8ae778f623fd..28acf111a470 100644 --- a/layout/base/nsIPresShell.h +++ b/layout/base/nsIPresShell.h @@ -1590,11 +1590,12 @@ public: bool aFlushOnHoverChange) = 0; virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf, - nsArenaMemoryStats *aArenaObjectsSize, - size_t *aPresShellSize, - size_t *aStyleSetsSize, - size_t *aTextRunsSize, - size_t *aPresContextSize) = 0; + nsArenaMemoryStats* aArenaObjectsSize, + size_t* aPresShellSize, + size_t* aStyleSetsSize, + size_t* aTextRunsSize, + size_t* aPresContextSize, + size_t* aFramePropertiesSize) = 0; /** * Methods that retrieve the cached font inflation preferences. diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp index e2d8f08d7c2d..9f1dbffc1606 100644 --- a/layout/generic/nsFrame.cpp +++ b/layout/generic/nsFrame.cpp @@ -10549,6 +10549,26 @@ nsFrame::HasCSSTransitions() return collection && collection->mAnimations.Length() > 0; } +size_t +nsIFrame::SizeOfFramePropertiesForTree(MallocSizeOf aMallocSizeOf) const +{ + size_t result = 0; + + if (mProperties) { + result += mProperties->SizeOfIncludingThis(aMallocSizeOf); + } + + FrameChildListIterator iter(this); + while (!iter.IsDone()) { + for (const nsIFrame* f : iter.CurrentList()) { + result += f->SizeOfFramePropertiesForTree(aMallocSizeOf); + } + iter.Next(); + } + + return result; +} + // Box layout debugging #ifdef DEBUG_REFLOW int32_t gIndent2 = 0; diff --git a/layout/generic/nsIFrame.h b/layout/generic/nsIFrame.h index 5994b78661ab..e44997870b68 100644 --- a/layout/generic/nsIFrame.h +++ b/layout/generic/nsIFrame.h @@ -3460,6 +3460,9 @@ public: } } + // Reports size of the FrameProperties for this frame and its descendants + size_t SizeOfFramePropertiesForTree(mozilla::MallocSizeOf aMallocSizeOf) const; + /** * Return true if and only if this frame obeys visibility:hidden. * if it does not, then nsContainerFrame will hide its view even though