b=566447; add presshell memory reporter; r=bz

This commit is contained in:
Vladimir Vukicevic 2010-05-31 19:19:35 -07:00
parent 002224fae6
commit 73cbd73f4a
12 changed files with 198 additions and 1 deletions

View File

@ -850,6 +850,8 @@ public:
nsresult WriteReverse(const PRUnichar *aSrc, PRInt32 aSrcLength, PRUnichar *aDest, PRUint16 aOptions, PRInt32 *aDestSize);
protected:
friend class nsBidiPresUtils;
/** length of the current text */
PRInt32 mLength;

View File

@ -1664,4 +1664,19 @@ nsresult nsBidiPresUtils::ProcessTextForRenderingContext(const PRUnichar*
return ProcessText(aText, aLength, aBaseDirection, aPresContext, processor,
aMode, aPosResolve, aPosResolveCount, aWidth);
}
PRUint32 nsBidiPresUtils::EstimateMemoryUsed()
{
PRUint32 size = 0;
size += sizeof(nsBidiPresUtils);
size += mBuffer.Length() * sizeof(PRUnichar);
size += moz_malloc_usable_size(mBidiEngine->mDirPropsMemory);
size += moz_malloc_usable_size(mBidiEngine->mLevelsMemory);
size += moz_malloc_usable_size(mBidiEngine->mRunsMemory);
return size;
}
#endif // IBMBIDI

View File

@ -313,6 +313,12 @@ public:
PRInt32 aPosResolveCount,
nscoord* aWidth);
/**
* Guess at how much memory is being used by this nsBidiPresUtils instance,
* including memory used by nsBidi.
*/
PRUint32 EstimateMemoryUsed();
private:
nsresult ProcessTextForRenderingContext(const PRUnichar* aText,
PRInt32 aLength,

View File

@ -54,6 +54,8 @@
#ifndef nsIPresShell_h___
#define nsIPresShell_h___
#include "nsTHashtable.h"
#include "nsHashKeys.h"
#include "nsISupports.h"
#include "nsQueryFrame.h"
#include "nsCoord.h"
@ -997,6 +999,12 @@ public:
PRUint64 GetPaintCount() { return mPaintCount; }
void IncrementPaintCount() { ++mPaintCount; }
/**
* Initialize and shut down static variables.
*/
static void InitializeStatics();
static void ReleaseStatics();
protected:
// IMPORTANT: The ownership implicit in the following member variables
// has been explicitly checked. If you add any members to this class,
@ -1049,6 +1057,10 @@ protected:
// Most recent canvas background color.
nscolor mCanvasBackgroundColor;
// Live pres shells, for memory and other tracking
typedef nsPtrHashKey<nsIPresShell> PresShellPtrKey;
static nsTHashtable<PresShellPtrKey> *sLiveShells;
};
/**

View File

@ -357,6 +357,20 @@ struct nsPresArena::State {
}
};
PRUint32
nsPresArena::Size()
{
PLArena *arena = &mState->mPool.first;
PRUint32 result = 0;
while (arena) {
result += arena->limit - arena->base;
arena = arena->next;
}
return result;
}
#else
// Stub implementation that forwards everything to malloc and does not
// poison.
@ -374,6 +388,12 @@ struct nsPresArena::State
}
};
PRUint32
nsPresArena::Size()
{
return 0;
}
#endif // DEBUG_TRACEMALLOC_PRESARENA
// Public interface

View File

@ -74,6 +74,8 @@ public:
NS_HIDDEN_(void*) AllocateByCode(nsQueryFrame::FrameIID aCode, size_t aSize);
NS_HIDDEN_(void) FreeByCode(nsQueryFrame::FrameIID aCode, void* aPtr);
PRUint32 Size();
private:
struct State;
State* mState;

View File

@ -1416,6 +1416,16 @@ nsPresContext::GetBidi() const
{
return Document()->GetBidiOptions();
}
PRUint32
nsPresContext::GetBidiMemoryUsed()
{
if (!mBidiUtils)
return 0;
return mBidiUtils->EstimateMemoryUsed();
}
#endif //IBMBIDI
PRBool

View File

@ -746,6 +746,10 @@ public:
* include nsIDocument.
*/
NS_HIDDEN_(PRUint32) GetBidi() const;
PRUint32 GetBidiMemoryUsed();
#else
PRUint32 GetBidiMemoryUsed() { return 0; }
#endif // IBMBIDI
/**
@ -956,6 +960,15 @@ public:
return nsnull;
}
PRUint32 EstimateMemoryUsed() {
PRUint32 result = 0;
result += sizeof(nsPresContext);
result += GetBidiMemoryUsed();
return result;
}
protected:
friend class nsRunnableMethod<nsPresContext>;
NS_HIDDEN_(void) ThemeChangedInternal();

View File

@ -499,6 +499,16 @@ public:
void Push();
void Pop();
PRUint32 Size() {
PRUint32 result = 0;
StackBlock *block = mBlocks;
while (block) {
result += sizeof(StackBlock);
block = block->mNext;
}
return result;
}
private:
// our current position in memory
size_t mPos;
@ -1296,6 +1306,54 @@ private:
// Ensure that every allocation from the PresArena is eventually freed.
PRUint32 mPresArenaAllocCount;
#endif
public:
PRUint32 EstimateMemoryUsed() {
PRUint32 result = 0;
result += sizeof(PresShell);
result += mStackArena.Size();
result += mFrameArena.Size();
return result;
}
static PLDHashOperator LiveShellSizeEnumerator(PresShellPtrKey *aEntry,
void *userArg)
{
PresShell *aShell = static_cast<PresShell*>(aEntry->GetKey());
PRUint32 *val = (PRUint32*)userArg;
*val += aShell->EstimateMemoryUsed();
*val += aShell->mPresContext->EstimateMemoryUsed();
return PL_DHASH_NEXT;
}
static PLDHashOperator LiveShellBidiSizeEnumerator(PresShellPtrKey *aEntry,
void *userArg)
{
PresShell *aShell = static_cast<PresShell*>(aEntry->GetKey());
PRUint32 *val = (PRUint32*)userArg;
*val += aShell->mPresContext->GetBidiMemoryUsed();
return PL_DHASH_NEXT;
}
static PRUint32
EstimateShellsMemory(nsTHashtable<PresShellPtrKey>::Enumerator aEnumerator)
{
PRUint32 result = 0;
sLiveShells->EnumerateEntries(aEnumerator, &result);
return result;
}
static PRInt64 SizeOfLayoutMemoryReporter(void *) {
return EstimateShellsMemory(LiveShellSizeEnumerator);
}
static PRInt64 SizeOfBidiMemoryReporter(void *) {
return EstimateShellsMemory(LiveShellBidiSizeEnumerator);
}
};
class nsAutoCauseReflowNotifier
@ -1501,6 +1559,20 @@ NS_NewPresShell(nsIPresShell** aInstancePtrResult)
return NS_OK;
}
nsTHashtable<PresShell::PresShellPtrKey> *nsIPresShell::sLiveShells = 0;
NS_MEMORY_REPORTER_IMPLEMENT(LayoutPresShell,
"layout/all",
"Memory in use by layout PresShell, PresContext, and other related areas.",
PresShell::SizeOfLayoutMemoryReporter,
nsnull);
NS_MEMORY_REPORTER_IMPLEMENT(LayoutBidi,
"layout/bidi",
"Memory in use by layout Bidi processor.",
PresShell::SizeOfBidiMemoryReporter,
nsnull);
PresShell::PresShell()
{
mSelection = nsnull;
@ -1519,7 +1591,16 @@ PresShell::PresShell()
mPresArenaAllocCount = 0;
#endif
static bool registeredReporter = false;
if (!registeredReporter) {
NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(LayoutPresShell));
NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(LayoutBidi));
registeredReporter = true;
}
new (this) nsFrameManager();
sLiveShells->PutEntry(this);
}
NS_IMPL_ISUPPORTS8(PresShell, nsIPresShell, nsIDocumentObserver,
@ -1529,6 +1610,8 @@ NS_IMPL_ISUPPORTS8(PresShell, nsIPresShell, nsIDocumentObserver,
PresShell::~PresShell()
{
sLiveShells->RemoveEntry(this);
if (!mHaveShutDown) {
NS_NOTREACHED("Someone did not call nsIPresShell::destroy");
Destroy();
@ -8694,3 +8777,17 @@ nsIFrame* nsIPresShell::GetAbsoluteContainingBlock(nsIFrame *aFrame)
{
return FrameConstructor()->GetAbsoluteContainingBlock(aFrame);
}
void nsIPresShell::InitializeStatics()
{
NS_ASSERTION(sLiveShells == nsnull, "InitializeStatics called multiple times!");
sLiveShells = new nsTHashtable<PresShellPtrKey>();
sLiveShells->Init();
}
void nsIPresShell::ReleaseStatics()
{
NS_ASSERTION(sLiveShells, "ReleaseStatics called without Initialize!");
delete sLiveShells;
sLiveShells = nsnull;
}

View File

@ -284,6 +284,7 @@ nsLayoutStatics::Initialize()
nsContentSink::InitializeStatics();
nsHtml5Module::InitializeStatics();
nsIPresShell::InitializeStatics();
nsCrossSiteListenerProxy::Startup();
@ -380,6 +381,8 @@ nsLayoutStatics::Shutdown()
nsXMLHttpRequest::ShutdownACCache();
nsIPresShell::ReleaseStatics();
nsHtml5Module::ReleaseStatics();
nsRegion::ShutdownStatic();

View File

@ -229,6 +229,22 @@ moz_valloc(size_t size)
}
#endif // if defined(HAVE_VALLOC)
size_t
moz_malloc_usable_size(void *ptr)
{
if (!ptr)
return 0;
#if defined(MOZ_MEMORY)
return malloc_usable_size(ptr);
#elif defined(XP_MACOSX)
return malloc_size(ptr);
#elif defined(XP_WIN)
return _msize(ptr);
#else
return 0;
#endif
}
namespace mozilla {

View File

@ -131,6 +131,7 @@ MOZALLOC_EXPORT char* moz_xstrdup(const char* str)
MOZALLOC_EXPORT char* moz_strdup(const char* str)
NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
MOZALLOC_EXPORT size_t moz_malloc_usable_size(void *ptr);
#if defined(HAVE_STRNDUP)
MOZALLOC_EXPORT char* moz_xstrndup(const char* str, size_t strsize)