Bug 705602 - Use mallocSizeOf in prefixset memory reporter. r=gpc.

--HG--
extra : rebase_source : f228466f7e082a152ceaafc8f8f1c4b71f5f550f
This commit is contained in:
Nicholas Nethercote 2011-12-13 20:54:18 -08:00
parent c1da559e35
commit 51f6493150
5 changed files with 22 additions and 23 deletions

View File

@ -163,9 +163,9 @@
#define NS_TYPEAHEADFIND_CID \
{ 0xe7f70966, 0x9a37, 0x48d7, { 0x8a, 0xeb, 0x35, 0x99, 0x8f, 0x31, 0x09, 0x0e} }
// {51464459-4e46-4f31-8745-4acfa7c1e2f2}
// {7902e243-9b00-4673-9288-1b7fc246a8f8}
#define NS_URLCLASSIFIERPREFIXSET_CID \
{ 0x51464459, 0x4e46, 0x4f31, { 0x87, 0x45, 0x4a, 0xcf, 0xa7, 0xc1, 0xe2, 0xf2} }
{ 0x7902e243, 0x9b00, 0x4673, { 0x92, 0x88, 0x1b, 0x7f, 0xc2, 0x46, 0xa8, 0xf8} }
// {5eb7c3c1-ec1f-4007-87cc-eefb37d68ce6}
#define NS_URLCLASSIFIERDBSERVICE_CID \

View File

@ -41,7 +41,7 @@
interface nsIArray;
[scriptable, uuid(51464459-4e46-4f31-8745-4acfa7c1e2f2)]
[scriptable, uuid(7902e243-9b00-4673-9288-1b7fc246a8f8)]
interface nsIUrlClassifierPrefixSet : nsISupports
{
void setPrefixes([const, array, size_is(aLength)] in unsigned long aPrefixes,
@ -51,7 +51,6 @@ interface nsIUrlClassifierPrefixSet : nsISupports
boolean contains(in unsigned long aPrefix);
boolean probe(in unsigned long aPrefix, in unsigned long aKey,
inout boolean aReady);
PRUint32 sizeOfIncludingThis();
PRUint32 getKey();
boolean isEmpty();
void loadFromFile(in nsIFile aFile);

View File

@ -3691,10 +3691,8 @@ nsUrlClassifierDBServiceWorker::LoadPrefixSet(nsCOMPtr<nsIFile> & aFile)
}
#ifdef DEBUG
PRUint32 size = 0;
rv = mPrefixSet->SizeOfIncludingThis(&size);
LOG(("SB tree done, size = %d bytes\n", size));
NS_ENSURE_SUCCESS(rv, rv);
LOG(("SB tree done, size = %d bytes\n",
mPrefixSet->SizeOfIncludingThis(moz_malloc_size_of)));
#endif
#if defined(PR_LOGGING)
if (LOG_ENABLED()) {

View File

@ -84,6 +84,9 @@ private:
NS_IMPL_THREADSAFE_ISUPPORTS1(nsPrefixSetReporter, nsIMemoryReporter)
NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(StoragePrefixSetMallocSizeOf,
"storage/prefixset")
nsPrefixSetReporter::nsPrefixSetReporter(nsUrlClassifierPrefixSet * aParent,
const nsACString & aName)
: mParent(aParent)
@ -126,10 +129,8 @@ nsPrefixSetReporter::GetUnits(PRInt32 * aUnits)
NS_IMETHODIMP
nsPrefixSetReporter::GetAmount(PRInt64 * aAmount)
{
PRUint32 size;
nsresult rv = mParent->SizeOfIncludingThis(&size);
*aAmount = size;
return rv;
*aAmount = mParent->SizeOfIncludingThis(StoragePrefixSetMallocSizeOf);
return NS_OK;
}
NS_IMETHODIMP
@ -333,16 +334,16 @@ nsUrlClassifierPrefixSet::Contains(PRUint32 aPrefix, bool * aFound)
return NS_OK;
}
NS_IMETHODIMP
nsUrlClassifierPrefixSet::SizeOfIncludingThis(PRUint32 * aSize)
size_t
nsUrlClassifierPrefixSet::SizeOfIncludingThis(nsMallocSizeOfFun mallocSizeOf)
{
MutexAutoLock lock(mPrefixSetLock);
size_t usable = moz_malloc_usable_size(this);
*aSize = (PRUint32)(usable ? usable : sizeof(*this));
*aSize += mDeltas.SizeOf();
*aSize += mIndexPrefixes.SizeOf();
*aSize += mIndexStarts.SizeOf();
return NS_OK;
size_t n = 0;
n += mallocSizeOf(this, sizeof(nsUrlClassifierPrefixSet));
n += mDeltas.SizeOf();
n += mIndexPrefixes.SizeOf();
n += mIndexStarts.SizeOf();
return n;
}
NS_IMETHODIMP

View File

@ -70,9 +70,6 @@ public:
// if aReady is set, we will block until there are any entries
// if not set, we will return in aReady whether we were ready or not
NS_IMETHOD Probe(PRUint32 aPrefix, PRUint32 aKey, bool* aReady, bool* aFound);
// Return the estimated size of the set on disk and in memory,
// in bytes
NS_IMETHOD SizeOfIncludingThis(PRUint32* aSize);
NS_IMETHOD IsEmpty(bool * aEmpty);
NS_IMETHOD LoadFromFile(nsIFile* aFile);
NS_IMETHOD StoreToFile(nsIFile* aFile);
@ -81,6 +78,10 @@ public:
NS_DECL_ISUPPORTS
// Return the estimated size of the set on disk and in memory,
// in bytes
size_t SizeOfIncludingThis(nsMallocSizeOfFun mallocSizeOf);
protected:
static const PRUint32 DELTAS_LIMIT = 100;
static const PRUint32 MAX_INDEX_DIFF = (1 << 16);