Skip to content

Commit a2b286f

Browse files
committed
Bug 964039 - Memory used by the new cache backend is not reported, r=michal
1 parent 7d882ef commit a2b286f

21 files changed

+681
-31
lines changed

netwerk/cache2/CacheEntry.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "nsICacheStorage.h"
1616
#include "nsISerializable.h"
1717
#include "nsIStreamTransportService.h"
18+
#include "nsISizeOf.h"
1819

1920
#include "nsComponentManagerUtils.h"
2021
#include "nsServiceManagerUtils.h"
@@ -1545,5 +1546,40 @@ NS_IMETHODIMP CacheOutputCloseListener::Run()
15451546
return NS_OK;
15461547
}
15471548

1549+
// Memory reporting
1550+
1551+
size_t CacheEntry::SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const
1552+
{
1553+
size_t n = 0;
1554+
nsCOMPtr<nsISizeOf> sizeOf;
1555+
1556+
n += mCallbacks.SizeOfExcludingThis(mallocSizeOf);
1557+
if (mFile) {
1558+
n += mFile->SizeOfIncludingThis(mallocSizeOf);
1559+
}
1560+
1561+
sizeOf = do_QueryInterface(mURI);
1562+
if (sizeOf) {
1563+
n += sizeOf->SizeOfIncludingThis(mallocSizeOf);
1564+
}
1565+
1566+
n += mEnhanceID.SizeOfExcludingThisIfUnshared(mallocSizeOf);
1567+
n += mStorageID.SizeOfExcludingThisIfUnshared(mallocSizeOf);
1568+
1569+
// mDoomCallback is an arbitrary class that is probably reported elsewhere.
1570+
// mOutputStream is reported in mFile.
1571+
// mWriter is one of many handles we create, but (intentionally) not keep
1572+
// any reference to, so those unfortunatelly cannot be reported. Handles are
1573+
// small, though.
1574+
// mSecurityInfo doesn't impl nsISizeOf.
1575+
1576+
return n;
1577+
}
1578+
1579+
size_t CacheEntry::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const
1580+
{
1581+
return mallocSizeOf(this) + SizeOfExcludingThis(mallocSizeOf);
1582+
}
1583+
15481584
} // net
15491585
} // mozilla

netwerk/cache2/CacheEntry.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ class CacheEntry : public nsICacheEntry
105105
double mFrecency;
106106
uint32_t mSortingExpirationTime;
107107

108+
// Memory reporting
109+
size_t SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
110+
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
111+
108112
private:
109113
virtual ~CacheEntry();
110114

netwerk/cache2/CacheFile.cpp

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ CacheFile::Unlock()
933933
}
934934

935935
void
936-
CacheFile::AssertOwnsLock()
936+
CacheFile::AssertOwnsLock() const
937937
{
938938
mLock.AssertCurrentThreadOwns();
939939
}
@@ -1578,5 +1578,57 @@ CacheFile::InitIndexEntry()
15781578
return NS_OK;
15791579
}
15801580

1581+
// Memory reporting
1582+
1583+
namespace { // anon
1584+
1585+
size_t
1586+
CollectChunkSize(uint32_t const & aIdx,
1587+
nsRefPtr<mozilla::net::CacheFileChunk> const & aChunk,
1588+
mozilla::MallocSizeOf mallocSizeOf, void* aClosure)
1589+
{
1590+
return aChunk->SizeOfIncludingThis(mallocSizeOf);
1591+
}
1592+
1593+
} // anon
1594+
1595+
size_t
1596+
CacheFile::SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const
1597+
{
1598+
CacheFileAutoLock lock(const_cast<CacheFile*>(this));
1599+
1600+
size_t n = 0;
1601+
n += mChunks.SizeOfExcludingThis(CollectChunkSize, mallocSizeOf);
1602+
n += mCachedChunks.SizeOfExcludingThis(CollectChunkSize, mallocSizeOf);
1603+
if (mMetadata) {
1604+
n += mMetadata->SizeOfIncludingThis(mallocSizeOf);
1605+
}
1606+
1607+
// Input streams are not elsewhere reported.
1608+
n += mInputs.SizeOfExcludingThis(mallocSizeOf);
1609+
for (uint32_t i = 0; i < mInputs.Length(); ++i) {
1610+
n += mInputs[i]->SizeOfIncludingThis(mallocSizeOf);
1611+
}
1612+
1613+
// Output streams are not elsewhere reported.
1614+
if (mOutput) {
1615+
n += mOutput->SizeOfIncludingThis(mallocSizeOf);
1616+
}
1617+
1618+
// The listeners are usually classes reported just above.
1619+
n += mChunkListeners.SizeOfExcludingThis(nullptr, mallocSizeOf);
1620+
n += mObjsToRelease.SizeOfExcludingThis(mallocSizeOf);
1621+
1622+
// mHandle reported directly from CacheFileIOManager.
1623+
1624+
return n;
1625+
}
1626+
1627+
size_t
1628+
CacheFile::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const
1629+
{
1630+
return mallocSizeOf(this) + SizeOfExcludingThis(mallocSizeOf);
1631+
}
1632+
15811633
} // net
15821634
} // mozilla

netwerk/cache2/CacheFile.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ class CacheFile : public CacheFileChunkListener
9999
void Key(nsACString& aKey) { aKey = mKey; }
100100
bool IsDoomed();
101101

102+
// Memory reporting
103+
size_t SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
104+
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
105+
102106
private:
103107
friend class CacheFileIOManager;
104108
friend class CacheFileChunk;
@@ -111,7 +115,7 @@ class CacheFile : public CacheFileChunkListener
111115

112116
void Lock();
113117
void Unlock();
114-
void AssertOwnsLock();
118+
void AssertOwnsLock() const;
115119
void ReleaseOutsideLock(nsISupports *aObject);
116120

117121
nsresult GetChunk(uint32_t aIndex, bool aWriter,

netwerk/cache2/CacheFileChunk.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -597,23 +597,23 @@ CacheFileChunk::OnFileRenamed(CacheFileHandle *aHandle, nsresult aResult)
597597
}
598598

599599
bool
600-
CacheFileChunk::IsReady()
600+
CacheFileChunk::IsReady() const
601601
{
602602
mFile->AssertOwnsLock();
603603

604604
return (mState == READY || mState == WRITING);
605605
}
606606

607607
bool
608-
CacheFileChunk::IsDirty()
608+
CacheFileChunk::IsDirty() const
609609
{
610610
mFile->AssertOwnsLock();
611611

612612
return mIsDirty;
613613
}
614614

615615
char *
616-
CacheFileChunk::BufForWriting()
616+
CacheFileChunk::BufForWriting() const
617617
{
618618
mFile->AssertOwnsLock();
619619

@@ -627,7 +627,7 @@ CacheFileChunk::BufForWriting()
627627
}
628628

629629
const char *
630-
CacheFileChunk::BufForReading()
630+
CacheFileChunk::BufForReading() const
631631
{
632632
mFile->AssertOwnsLock();
633633

@@ -677,5 +677,24 @@ CacheFileChunk::EnsureBufSize(uint32_t aBufSize)
677677
DoMemoryReport(MemorySize());
678678
}
679679

680+
// Memory reporting
681+
682+
size_t
683+
CacheFileChunk::SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const
684+
{
685+
size_t n = 0;
686+
n += mallocSizeOf(mBuf);
687+
n += mallocSizeOf(mRWBuf);
688+
n += mValidityMap.SizeOfExcludingThis(mallocSizeOf);
689+
690+
return n;
691+
}
692+
693+
size_t
694+
CacheFileChunk::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const
695+
{
696+
return mallocSizeOf(this) + SizeOfExcludingThis(mallocSizeOf);
697+
}
698+
680699
} // net
681700
} // mozilla

netwerk/cache2/CacheFileChunk.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,17 @@ class CacheFileChunk : public CacheFileIOListener
9494
NS_IMETHOD OnEOFSet(CacheFileHandle *aHandle, nsresult aResult);
9595
NS_IMETHOD OnFileRenamed(CacheFileHandle *aHandle, nsresult aResult);
9696

97-
bool IsReady();
98-
bool IsDirty();
97+
bool IsReady() const;
98+
bool IsDirty() const;
9999

100-
char * BufForWriting();
101-
const char * BufForReading();
100+
char * BufForWriting() const;
101+
const char * BufForReading() const;
102102
void EnsureBufSize(uint32_t aBufSize);
103-
uint32_t MemorySize() { return mRWBufSize + mBufSize; }
103+
uint32_t MemorySize() const { return mRWBufSize + mBufSize; }
104+
105+
// Memory reporting
106+
size_t SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
107+
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
104108

105109
private:
106110
friend class CacheFileInputStream;

0 commit comments

Comments
 (0)