mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
b=566447; add presshell memory reporter; r=bz
This commit is contained in:
parent
002224fae6
commit
73cbd73f4a
@ -850,6 +850,8 @@ public:
|
|||||||
nsresult WriteReverse(const PRUnichar *aSrc, PRInt32 aSrcLength, PRUnichar *aDest, PRUint16 aOptions, PRInt32 *aDestSize);
|
nsresult WriteReverse(const PRUnichar *aSrc, PRInt32 aSrcLength, PRUnichar *aDest, PRUint16 aOptions, PRInt32 *aDestSize);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
friend class nsBidiPresUtils;
|
||||||
|
|
||||||
/** length of the current text */
|
/** length of the current text */
|
||||||
PRInt32 mLength;
|
PRInt32 mLength;
|
||||||
|
|
||||||
|
@ -1664,4 +1664,19 @@ nsresult nsBidiPresUtils::ProcessTextForRenderingContext(const PRUnichar*
|
|||||||
return ProcessText(aText, aLength, aBaseDirection, aPresContext, processor,
|
return ProcessText(aText, aLength, aBaseDirection, aPresContext, processor,
|
||||||
aMode, aPosResolve, aPosResolveCount, aWidth);
|
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
|
#endif // IBMBIDI
|
||||||
|
@ -313,6 +313,12 @@ public:
|
|||||||
PRInt32 aPosResolveCount,
|
PRInt32 aPosResolveCount,
|
||||||
nscoord* aWidth);
|
nscoord* aWidth);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Guess at how much memory is being used by this nsBidiPresUtils instance,
|
||||||
|
* including memory used by nsBidi.
|
||||||
|
*/
|
||||||
|
PRUint32 EstimateMemoryUsed();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nsresult ProcessTextForRenderingContext(const PRUnichar* aText,
|
nsresult ProcessTextForRenderingContext(const PRUnichar* aText,
|
||||||
PRInt32 aLength,
|
PRInt32 aLength,
|
||||||
|
@ -54,6 +54,8 @@
|
|||||||
#ifndef nsIPresShell_h___
|
#ifndef nsIPresShell_h___
|
||||||
#define nsIPresShell_h___
|
#define nsIPresShell_h___
|
||||||
|
|
||||||
|
#include "nsTHashtable.h"
|
||||||
|
#include "nsHashKeys.h"
|
||||||
#include "nsISupports.h"
|
#include "nsISupports.h"
|
||||||
#include "nsQueryFrame.h"
|
#include "nsQueryFrame.h"
|
||||||
#include "nsCoord.h"
|
#include "nsCoord.h"
|
||||||
@ -997,6 +999,12 @@ public:
|
|||||||
PRUint64 GetPaintCount() { return mPaintCount; }
|
PRUint64 GetPaintCount() { return mPaintCount; }
|
||||||
void IncrementPaintCount() { ++mPaintCount; }
|
void IncrementPaintCount() { ++mPaintCount; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize and shut down static variables.
|
||||||
|
*/
|
||||||
|
static void InitializeStatics();
|
||||||
|
static void ReleaseStatics();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// IMPORTANT: The ownership implicit in the following member variables
|
// IMPORTANT: The ownership implicit in the following member variables
|
||||||
// has been explicitly checked. If you add any members to this class,
|
// has been explicitly checked. If you add any members to this class,
|
||||||
@ -1049,6 +1057,10 @@ protected:
|
|||||||
|
|
||||||
// Most recent canvas background color.
|
// Most recent canvas background color.
|
||||||
nscolor mCanvasBackgroundColor;
|
nscolor mCanvasBackgroundColor;
|
||||||
|
|
||||||
|
// Live pres shells, for memory and other tracking
|
||||||
|
typedef nsPtrHashKey<nsIPresShell> PresShellPtrKey;
|
||||||
|
static nsTHashtable<PresShellPtrKey> *sLiveShells;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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
|
#else
|
||||||
// Stub implementation that forwards everything to malloc and does not
|
// Stub implementation that forwards everything to malloc and does not
|
||||||
// poison.
|
// poison.
|
||||||
@ -374,6 +388,12 @@ struct nsPresArena::State
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PRUint32
|
||||||
|
nsPresArena::Size()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // DEBUG_TRACEMALLOC_PRESARENA
|
#endif // DEBUG_TRACEMALLOC_PRESARENA
|
||||||
|
|
||||||
// Public interface
|
// Public interface
|
||||||
|
@ -74,6 +74,8 @@ public:
|
|||||||
NS_HIDDEN_(void*) AllocateByCode(nsQueryFrame::FrameIID aCode, size_t aSize);
|
NS_HIDDEN_(void*) AllocateByCode(nsQueryFrame::FrameIID aCode, size_t aSize);
|
||||||
NS_HIDDEN_(void) FreeByCode(nsQueryFrame::FrameIID aCode, void* aPtr);
|
NS_HIDDEN_(void) FreeByCode(nsQueryFrame::FrameIID aCode, void* aPtr);
|
||||||
|
|
||||||
|
PRUint32 Size();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct State;
|
struct State;
|
||||||
State* mState;
|
State* mState;
|
||||||
|
@ -1416,6 +1416,16 @@ nsPresContext::GetBidi() const
|
|||||||
{
|
{
|
||||||
return Document()->GetBidiOptions();
|
return Document()->GetBidiOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PRUint32
|
||||||
|
nsPresContext::GetBidiMemoryUsed()
|
||||||
|
{
|
||||||
|
if (!mBidiUtils)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return mBidiUtils->EstimateMemoryUsed();
|
||||||
|
}
|
||||||
|
|
||||||
#endif //IBMBIDI
|
#endif //IBMBIDI
|
||||||
|
|
||||||
PRBool
|
PRBool
|
||||||
|
@ -746,6 +746,10 @@ public:
|
|||||||
* include nsIDocument.
|
* include nsIDocument.
|
||||||
*/
|
*/
|
||||||
NS_HIDDEN_(PRUint32) GetBidi() const;
|
NS_HIDDEN_(PRUint32) GetBidi() const;
|
||||||
|
|
||||||
|
PRUint32 GetBidiMemoryUsed();
|
||||||
|
#else
|
||||||
|
PRUint32 GetBidiMemoryUsed() { return 0; }
|
||||||
#endif // IBMBIDI
|
#endif // IBMBIDI
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -956,6 +960,15 @@ public:
|
|||||||
return nsnull;
|
return nsnull;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PRUint32 EstimateMemoryUsed() {
|
||||||
|
PRUint32 result = 0;
|
||||||
|
|
||||||
|
result += sizeof(nsPresContext);
|
||||||
|
result += GetBidiMemoryUsed();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class nsRunnableMethod<nsPresContext>;
|
friend class nsRunnableMethod<nsPresContext>;
|
||||||
NS_HIDDEN_(void) ThemeChangedInternal();
|
NS_HIDDEN_(void) ThemeChangedInternal();
|
||||||
|
@ -499,6 +499,16 @@ public:
|
|||||||
void Push();
|
void Push();
|
||||||
void Pop();
|
void Pop();
|
||||||
|
|
||||||
|
PRUint32 Size() {
|
||||||
|
PRUint32 result = 0;
|
||||||
|
StackBlock *block = mBlocks;
|
||||||
|
while (block) {
|
||||||
|
result += sizeof(StackBlock);
|
||||||
|
block = block->mNext;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// our current position in memory
|
// our current position in memory
|
||||||
size_t mPos;
|
size_t mPos;
|
||||||
@ -1296,6 +1306,54 @@ private:
|
|||||||
// Ensure that every allocation from the PresArena is eventually freed.
|
// Ensure that every allocation from the PresArena is eventually freed.
|
||||||
PRUint32 mPresArenaAllocCount;
|
PRUint32 mPresArenaAllocCount;
|
||||||
#endif
|
#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
|
class nsAutoCauseReflowNotifier
|
||||||
@ -1501,6 +1559,20 @@ NS_NewPresShell(nsIPresShell** aInstancePtrResult)
|
|||||||
return NS_OK;
|
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()
|
PresShell::PresShell()
|
||||||
{
|
{
|
||||||
mSelection = nsnull;
|
mSelection = nsnull;
|
||||||
@ -1519,7 +1591,16 @@ PresShell::PresShell()
|
|||||||
mPresArenaAllocCount = 0;
|
mPresArenaAllocCount = 0;
|
||||||
#endif
|
#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();
|
new (this) nsFrameManager();
|
||||||
|
|
||||||
|
sLiveShells->PutEntry(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS8(PresShell, nsIPresShell, nsIDocumentObserver,
|
NS_IMPL_ISUPPORTS8(PresShell, nsIPresShell, nsIDocumentObserver,
|
||||||
@ -1529,6 +1610,8 @@ NS_IMPL_ISUPPORTS8(PresShell, nsIPresShell, nsIDocumentObserver,
|
|||||||
|
|
||||||
PresShell::~PresShell()
|
PresShell::~PresShell()
|
||||||
{
|
{
|
||||||
|
sLiveShells->RemoveEntry(this);
|
||||||
|
|
||||||
if (!mHaveShutDown) {
|
if (!mHaveShutDown) {
|
||||||
NS_NOTREACHED("Someone did not call nsIPresShell::destroy");
|
NS_NOTREACHED("Someone did not call nsIPresShell::destroy");
|
||||||
Destroy();
|
Destroy();
|
||||||
@ -8694,3 +8777,17 @@ nsIFrame* nsIPresShell::GetAbsoluteContainingBlock(nsIFrame *aFrame)
|
|||||||
{
|
{
|
||||||
return FrameConstructor()->GetAbsoluteContainingBlock(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;
|
||||||
|
}
|
||||||
|
@ -284,6 +284,7 @@ nsLayoutStatics::Initialize()
|
|||||||
|
|
||||||
nsContentSink::InitializeStatics();
|
nsContentSink::InitializeStatics();
|
||||||
nsHtml5Module::InitializeStatics();
|
nsHtml5Module::InitializeStatics();
|
||||||
|
nsIPresShell::InitializeStatics();
|
||||||
|
|
||||||
nsCrossSiteListenerProxy::Startup();
|
nsCrossSiteListenerProxy::Startup();
|
||||||
|
|
||||||
@ -380,6 +381,8 @@ nsLayoutStatics::Shutdown()
|
|||||||
|
|
||||||
nsXMLHttpRequest::ShutdownACCache();
|
nsXMLHttpRequest::ShutdownACCache();
|
||||||
|
|
||||||
|
nsIPresShell::ReleaseStatics();
|
||||||
|
|
||||||
nsHtml5Module::ReleaseStatics();
|
nsHtml5Module::ReleaseStatics();
|
||||||
|
|
||||||
nsRegion::ShutdownStatic();
|
nsRegion::ShutdownStatic();
|
||||||
|
@ -229,6 +229,22 @@ moz_valloc(size_t size)
|
|||||||
}
|
}
|
||||||
#endif // if defined(HAVE_VALLOC)
|
#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 {
|
namespace mozilla {
|
||||||
|
|
||||||
|
@ -131,6 +131,7 @@ MOZALLOC_EXPORT char* moz_xstrdup(const char* str)
|
|||||||
MOZALLOC_EXPORT char* moz_strdup(const char* str)
|
MOZALLOC_EXPORT char* moz_strdup(const char* str)
|
||||||
NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
|
NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
|
MOZALLOC_EXPORT size_t moz_malloc_usable_size(void *ptr);
|
||||||
|
|
||||||
#if defined(HAVE_STRNDUP)
|
#if defined(HAVE_STRNDUP)
|
||||||
MOZALLOC_EXPORT char* moz_xstrndup(const char* str, size_t strsize)
|
MOZALLOC_EXPORT char* moz_xstrndup(const char* str, size_t strsize)
|
||||||
|
Loading…
Reference in New Issue
Block a user