Bug 1394729 - Measure memory usage of Stylo's Rule Tree. r=heycam.

This patch splits up the existing "layout/style-sets" measurement into
"layout/gecko-style-sets", or "layout/servo-style-sets/stylist/rule-tree" and
"layout/servo-style-sets/other". (Additional things will be measured under
"layout/servo-style-sets/" later, such as cascade data.)

This requires introducing a new type, ServoStyleSetSizes, for transferring the
multiple measurements from Rust code to C++ code.

MozReview-Commit-ID: FbmzpsjBpgI

--HG--
extra : rebase_source : f2d1441705139e6674d355792255302fcd89f748
This commit is contained in:
Nicholas Nethercote 2017-08-30 18:21:26 +10:00
Родитель 83f77707b7
Коммит 9251ef42b7
10 изменённых файлов: 82 добавлений и 26 удалений

Просмотреть файл

@ -364,9 +364,23 @@ CollectWindowReports(nsGlobalWindow *aWindow,
"within a window.");
aWindowTotalSizes->mLayoutPresShellSize += windowSizes.mLayoutPresShellSize;
REPORT_SIZE("/layout/style-sets", windowSizes.mLayoutStyleSetsSize,
"Memory used by style sets within a window.");
aWindowTotalSizes->mLayoutStyleSetsSize += windowSizes.mLayoutStyleSetsSize;
REPORT_SIZE("/layout/gecko-style-sets", windowSizes.mLayoutGeckoStyleSets,
"Memory used by Gecko style sets within a window.");
aWindowTotalSizes->mLayoutGeckoStyleSets += windowSizes.mLayoutGeckoStyleSets;
REPORT_SIZE("/layout/servo-style-sets/stylist/rule-tree",
windowSizes.mLayoutServoStyleSetsStylistRuleTree,
"Memory used by rule trees within Servo style sets within a "
"window.");
aWindowTotalSizes->mLayoutServoStyleSetsStylistRuleTree +=
windowSizes.mLayoutServoStyleSetsStylistRuleTree;
REPORT_SIZE("/layout/servo-style-sets/other",
windowSizes.mLayoutServoStyleSetsOther,
"Memory used by other parts of Servo style sets within a "
"window.");
aWindowTotalSizes->mLayoutServoStyleSetsOther +=
windowSizes.mLayoutServoStyleSetsOther;
REPORT_SIZE("/layout/text-runs", windowSizes.mLayoutTextRunsSize,
"Memory used for text-runs (glyph layout) in the PresShell's "
@ -638,9 +652,15 @@ nsWindowMemoryReporter::CollectReports(nsIHandleReportCallback* aHandleReport,
windowTotalSizes.mLayoutPresShellSize,
"This is the sum of all windows' 'layout/arenas' numbers.");
REPORT("window-objects/layout/style-sets",
windowTotalSizes.mLayoutStyleSetsSize,
"This is the sum of all windows' 'layout/style-sets' numbers.");
REPORT("window-objects/layout/gecko-style-sets",
windowTotalSizes.mLayoutGeckoStyleSets,
"This is the sum of all windows' 'layout/gecko-style-sets' numbers.");
REPORT("window-objects/layout/servo-style-sets",
windowTotalSizes.mLayoutServoStyleSetsStylistRuleTree +
windowTotalSizes.mLayoutServoStyleSetsOther,
"This is the sum of all windows' 'layout/servo-style-sets/' numbers.");
REPORT("window-objects/layout/text-runs", windowTotalSizes.mLayoutTextRunsSize,
"This is the sum of all windows' 'layout/text-runs' numbers.");

Просмотреть файл

@ -175,7 +175,9 @@ class nsWindowSizes
macro(DOM, mDOMOtherSize) \
macro(Style, mStyleSheetsSize) \
macro(Other, mLayoutPresShellSize) \
macro(Style, mLayoutStyleSetsSize) \
macro(Style, mLayoutGeckoStyleSets) \
macro(Style, mLayoutServoStyleSetsStylistRuleTree) \
macro(Style, mLayoutServoStyleSetsOther) \
macro(Other, mLayoutTextRunsSize) \
macro(Other, mLayoutPresContextSize) \
macro(Other, mLayoutFramePropertiesSize) \

Просмотреть файл

@ -11066,9 +11066,9 @@ PresShell::AddSizeOfIncludingThis(nsWindowSizes& aSizes) const
mFramesToDirty.ShallowSizeOfExcludingThis(mallocSizeOf);
if (nsStyleSet* styleSet = StyleSet()->GetAsGecko()) {
aSizes.mLayoutStyleSetsSize += styleSet->SizeOfIncludingThis(mallocSizeOf);
styleSet->AddSizeOfIncludingThis(aSizes);
} else if (ServoStyleSet* styleSet = StyleSet()->GetAsServo()) {
aSizes.mLayoutStyleSetsSize += styleSet->SizeOfIncludingThis(mallocSizeOf);
styleSet->AddSizeOfIncludingThis(aSizes);
} else {
MOZ_CRASH();
}

Просмотреть файл

@ -112,6 +112,10 @@ SERVO_BINDING_FUNC(Servo_StyleSet_ResolveForDeclarations,
RawServoStyleSetBorrowed set,
ServoStyleContextBorrowedOrNull parent_style,
RawServoDeclarationBlockBorrowed declarations)
SERVO_BINDING_FUNC(Servo_StyleSet_AddSizeOfExcludingThis, void,
mozilla::MallocSizeOf malloc_size_of,
mozilla::ServoStyleSetSizes* sizes,
RawServoStyleSetBorrowed set)
SERVO_BINDING_FUNC(Servo_StyleContext_AddRef, void, ServoStyleContextBorrowed ctx);
SERVO_BINDING_FUNC(Servo_StyleContext_Release, void, ServoStyleContextBorrowed ctx);

Просмотреть файл

@ -130,6 +130,7 @@ whitelist-types = [
"mozilla::ServoElementSnapshot.*",
"mozilla::ServoStyleContext",
"mozilla::ServoStyleSheetInner",
"mozilla::ServoStyleSetSizes",
"mozilla::CSSPseudoClassType",
"mozilla::css::ErrorReporter",
"mozilla::css::LoaderReusableStyleSheets",
@ -417,6 +418,7 @@ structs-types = [
"ServoBundledURI",
"ServoElementSnapshot",
"ServoElementSnapshotTable",
"ServoStyleSetSizes",
"SheetParsingMode",
"StyleBasicShape",
"StyleBasicShapeType",

Просмотреть файл

@ -182,25 +182,39 @@ ServoStyleSet::MediumFeaturesChanged(bool aViewportChanged)
return nsRestyleHint(0);
}
size_t
ServoStyleSet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
MOZ_DEFINE_MALLOC_SIZE_OF(ServoStyleSetMallocSizeOf)
void
ServoStyleSet::AddSizeOfIncludingThis(nsWindowSizes& aSizes) const
{
size_t n = aMallocSizeOf(this);
MallocSizeOf mallocSizeOf = aSizes.mState.mMallocSizeOf;
aSizes.mLayoutServoStyleSetsOther += mallocSizeOf(this);
if (mRawSet) {
aSizes.mLayoutServoStyleSetsOther += mallocSizeOf(mRawSet.get());
ServoStyleSetSizes sizes;
// Measure mRawSet. We use ServoStyleSetMallocSizeOf rather than
// aMallocSizeOf to distinguish in DMD's output the memory measured within
// Servo code.
Servo_StyleSet_AddSizeOfExcludingThis(ServoStyleSetMallocSizeOf, &sizes,
mRawSet.get());
aSizes.mLayoutServoStyleSetsStylistRuleTree += sizes.mStylistRuleTree;
aSizes.mLayoutServoStyleSetsOther += sizes.mOther;
}
if (mStyleRuleMap) {
n += mStyleRuleMap->SizeOfIncludingThis(aMallocSizeOf);
aSizes.mLayoutServoStyleSetsOther +=
mStyleRuleMap->SizeOfIncludingThis(aSizes.mState.mMallocSizeOf);
}
// Measurement of the following members may be added later if DMD finds it is
// worthwhile:
// - mRawSet
// - mSheets
// - mNonInheritingStyleContexts
//
// The following members are not measured:
// - mPresContext, because it a non-owning pointer
return n;
}
bool

Просмотреть файл

@ -121,7 +121,7 @@ public:
void InvalidateStyleForCSSRuleChanges();
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
void AddSizeOfIncludingThis(nsWindowSizes& aSizes) const;
const RawServoStyleSet* RawSet() const {
return mRawSet.get();
}

Просмотреть файл

@ -201,6 +201,18 @@ struct ServoComputedValueFlags {
#undef STYLE_STRUCT
#undef STYLE_STRUCT_LIST_IGNORE_VARIABLES
class ServoStyleSetSizes
{
public:
size_t mStylistRuleTree;
size_t mOther;
ServoStyleSetSizes()
: mStylistRuleTree(0)
, mOther(0)
{}
};
} // namespace mozilla
class ServoComputedData;

Просмотреть файл

@ -250,10 +250,12 @@ nsStyleSet::~nsStyleSet()
}
}
size_t
nsStyleSet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
void
nsStyleSet::AddSizeOfIncludingThis(nsWindowSizes& aSizes) const
{
size_t n = aMallocSizeOf(this);
MallocSizeOf mallocSizeOf = aSizes.mState.mMallocSizeOf;
size_t n = mallocSizeOf(this);
for (SheetType type : MakeEnumeratedRange(SheetType::Count)) {
if (mRuleProcessors[type]) {
@ -265,20 +267,20 @@ nsStyleSet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
shared = rp->IsShared();
}
if (!shared) {
n += mRuleProcessors[type]->SizeOfIncludingThis(aMallocSizeOf);
n += mRuleProcessors[type]->SizeOfIncludingThis(mallocSizeOf);
}
}
// We don't own the sheets (either the nsLayoutStyleSheetCache singleton
// or our document owns them).
n += mSheets[type].ShallowSizeOfExcludingThis(aMallocSizeOf);
n += mSheets[type].ShallowSizeOfExcludingThis(mallocSizeOf);
}
for (uint32_t i = 0; i < mScopedDocSheetRuleProcessors.Length(); i++) {
n += mScopedDocSheetRuleProcessors[i]->SizeOfIncludingThis(aMallocSizeOf);
n += mScopedDocSheetRuleProcessors[i]->SizeOfIncludingThis(mallocSizeOf);
}
n += mScopedDocSheetRuleProcessors.ShallowSizeOfExcludingThis(aMallocSizeOf);
n += mScopedDocSheetRuleProcessors.ShallowSizeOfExcludingThis(mallocSizeOf);
return n;
aSizes.mLayoutGeckoStyleSets += n;
}
void

Просмотреть файл

@ -106,7 +106,7 @@ class nsStyleSet final
nsStyleSet();
~nsStyleSet();
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
void AddSizeOfIncludingThis(nsWindowSizes& aSizes) const;
void Init(nsPresContext* aPresContext, nsBindingManager* aBindingManager);