Bug 795128: Add memory reporting for attribute maps and nodes. r=smaug

This commit is contained in:
Kyle Huey 2012-09-30 09:43:47 -07:00
parent 1ccfbe810b
commit 53271e4c0c
4 changed files with 58 additions and 2 deletions

View File

@ -348,6 +348,8 @@ public:
void Traverse(nsCycleCollectionTraversalCallback &cb, bool aIsXUL);
void Unlink(bool aIsXUL);
size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
/**
* The .style attribute (an interface that forwards to the actual
* style rules)

View File

@ -598,6 +598,30 @@ FragmentOrElement::nsDOMSlots::Unlink(bool aIsXUL)
}
}
size_t
FragmentOrElement::nsDOMSlots::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
{
size_t n = aMallocSizeOf(this);
if (mAttributeMap) {
n += mAttributeMap->SizeOfIncludingThis(aMallocSizeOf);
}
// Measurement of the following members may be added later if DMD finds it is
// worthwhile:
// - Superclass members (nsINode::nsSlots)
// - mStyle
// - mDataSet
// - mSMILOverrideStyle
// - mSMILOverrideStyleRule
// - mChildrenList
// - mClassList
// The following members are not measured:
// - mBindingParent / mControllers: because they're non-owning
return n;
}
FragmentOrElement::FragmentOrElement(already_AddRefed<nsINodeInfo> aNodeInfo)
: nsIContent(aNodeInfo)
{
@ -1938,6 +1962,14 @@ FragmentOrElement::FireNodeRemovedForChildren()
size_t
FragmentOrElement::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
{
return nsIContent::SizeOfExcludingThis(aMallocSizeOf) +
mAttrsAndChildren.SizeOfExcludingThis(aMallocSizeOf);
size_t n = 0;
n += nsIContent::SizeOfExcludingThis(aMallocSizeOf);
n += mAttrsAndChildren.SizeOfExcludingThis(aMallocSizeOf);
nsDOMSlots* slots = GetExistingDOMSlots();
if (slots) {
n += slots->SizeOfIncludingThis(aMallocSizeOf);
}
return n;
}

View File

@ -501,3 +501,23 @@ nsDOMAttributeMap::Enumerate(AttrCache::EnumReadFunction aFunc,
{
return mAttributeCache.EnumerateRead(aFunc, aUserArg);
}
size_t
AttrCacheSizeEnumerator(const nsAttrKey& aKey,
const nsRefPtr<nsDOMAttribute>& aValue,
nsMallocSizeOfFun aMallocSizeOf,
void* aUserArg)
{
return aMallocSizeOf(aValue.get());
}
size_t
nsDOMAttributeMap::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
{
size_t n = aMallocSizeOf(this);
n += mAttributeCache.SizeOfExcludingThis(AttrCacheSizeEnumerator,
aMallocSizeOf);
// NB: mContent is non-owning and thus not counted.
return n;
}

View File

@ -159,6 +159,8 @@ public:
NS_DECL_CYCLE_COLLECTION_CLASS(nsDOMAttributeMap)
size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
private:
Element *mContent; // Weak reference