зеркало из https://github.com/mozilla/gecko-dev.git
Bug 697335 - Another memory reporter for the startup cache. r=taras.
This commit is contained in:
Родитель
5f03e241e2
Коммит
9dc2c72bd7
|
@ -82,24 +82,41 @@
|
|||
#define SC_WORDSIZE "8"
|
||||
#endif
|
||||
|
||||
namespace mozilla {
|
||||
namespace scache {
|
||||
|
||||
static PRInt64
|
||||
GetStartupCacheSize()
|
||||
GetStartupCacheMappingSize()
|
||||
{
|
||||
mozilla::scache::StartupCache* sc = mozilla::scache::StartupCache::GetSingleton();
|
||||
return sc ? sc->SizeOfMapping() : 0;
|
||||
}
|
||||
|
||||
NS_MEMORY_REPORTER_IMPLEMENT(StartupCache,
|
||||
"explicit/startup-cache",
|
||||
NS_MEMORY_REPORTER_IMPLEMENT(StartupCacheMapping,
|
||||
"explicit/startup-cache/mapping",
|
||||
KIND_NONHEAP,
|
||||
nsIMemoryReporter::UNITS_BYTES,
|
||||
GetStartupCacheSize,
|
||||
"Memory used to hold the startup cache. This "
|
||||
"memory is backed by a file and is likely to be "
|
||||
GetStartupCacheMappingSize,
|
||||
"Memory used to hold the mapping of the startup "
|
||||
"cache from file. This memory is likely to be "
|
||||
"swapped out shortly after start-up.")
|
||||
|
||||
namespace mozilla {
|
||||
namespace scache {
|
||||
NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(StartupCacheDataMallocSizeOf, "startup-cache/data")
|
||||
|
||||
static PRInt64
|
||||
GetStartupCacheDataSize()
|
||||
{
|
||||
mozilla::scache::StartupCache* sc = mozilla::scache::StartupCache::GetSingleton();
|
||||
return sc ? sc->HeapSizeOfIncludingThis(StartupCacheDataMallocSizeOf) : 0;
|
||||
}
|
||||
|
||||
NS_MEMORY_REPORTER_IMPLEMENT(StartupCacheData,
|
||||
"explicit/startup-cache/data",
|
||||
KIND_HEAP,
|
||||
nsIMemoryReporter::UNITS_BYTES,
|
||||
GetStartupCacheDataSize,
|
||||
"Memory used by the startup cache for things "
|
||||
"other than the file mapping.")
|
||||
|
||||
static const char sStartupCacheName[] = "startupCache." SC_WORDSIZE "." SC_ENDIAN;
|
||||
static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
|
||||
|
@ -138,7 +155,7 @@ bool StartupCache::gShutdownInitiated;
|
|||
|
||||
StartupCache::StartupCache()
|
||||
: mArchive(NULL), mStartupWriteInitiated(false), mWriteThread(NULL),
|
||||
mMemoryReporter(nsnull) { }
|
||||
mMappingMemoryReporter(nsnull), mDataMemoryReporter(nsnull) { }
|
||||
|
||||
StartupCache::~StartupCache()
|
||||
{
|
||||
|
@ -152,8 +169,10 @@ StartupCache::~StartupCache()
|
|||
WaitOnWriteThread();
|
||||
WriteToDisk();
|
||||
gStartupCache = nsnull;
|
||||
(void)::NS_UnregisterMemoryReporter(mMemoryReporter);
|
||||
mMemoryReporter = nsnull;
|
||||
(void)::NS_UnregisterMemoryReporter(mMappingMemoryReporter);
|
||||
(void)::NS_UnregisterMemoryReporter(mDataMemoryReporter);
|
||||
mMappingMemoryReporter = nsnull;
|
||||
mDataMemoryReporter = nsnull;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -227,8 +246,10 @@ StartupCache::Init()
|
|||
InvalidateCache();
|
||||
}
|
||||
|
||||
mMemoryReporter = new NS_MEMORY_REPORTER_NAME(StartupCache);
|
||||
(void)::NS_RegisterMemoryReporter(mMemoryReporter);
|
||||
mMappingMemoryReporter = new NS_MEMORY_REPORTER_NAME(StartupCacheMapping);
|
||||
mDataMemoryReporter = new NS_MEMORY_REPORTER_NAME(StartupCacheData);
|
||||
(void)::NS_RegisterMemoryReporter(mMappingMemoryReporter);
|
||||
(void)::NS_RegisterMemoryReporter(mDataMemoryReporter);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -335,12 +356,28 @@ StartupCache::PutBuffer(const char* id, const char* inbuf, PRUint32 len)
|
|||
return ResetStartupWriteTimer();
|
||||
}
|
||||
|
||||
PRInt64
|
||||
size_t
|
||||
StartupCache::SizeOfMapping()
|
||||
{
|
||||
return mArchive ? mArchive->SizeOfMapping() : 0;
|
||||
}
|
||||
|
||||
size_t
|
||||
StartupCache::HeapSizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf)
|
||||
{
|
||||
// This function could measure more members, but they haven't been found by
|
||||
// DMD to be significant. They can be added later if necessary.
|
||||
return aMallocSizeOf(this, sizeof(StartupCache)) +
|
||||
mTable.SizeOfExcludingThis(SizeOfEntryExcludingThis, aMallocSizeOf);
|
||||
}
|
||||
|
||||
/* static */ size_t
|
||||
StartupCache::SizeOfEntryExcludingThis(const nsACString& key, const nsAutoPtr<CacheEntry>& data,
|
||||
nsMallocSizeOfFun mallocSizeOf, void *)
|
||||
{
|
||||
return data->SizeOfExcludingThis(mallocSizeOf);
|
||||
}
|
||||
|
||||
struct CacheWriteHolder
|
||||
{
|
||||
nsCOMPtr<nsIZipWriter> writer;
|
||||
|
|
|
@ -113,6 +113,10 @@ struct CacheEntry
|
|||
~CacheEntry()
|
||||
{
|
||||
}
|
||||
|
||||
size_t SizeOfExcludingThis(nsMallocSizeOfFun mallocSizeOf) {
|
||||
return mallocSizeOf(data, size);
|
||||
}
|
||||
};
|
||||
|
||||
// We don't want to refcount StartupCache, and ObserverService wants to
|
||||
|
@ -150,7 +154,11 @@ public:
|
|||
static StartupCache* GetSingleton();
|
||||
static void DeleteSingleton();
|
||||
|
||||
PRInt64 SizeOfMapping();
|
||||
// This measures all the heap memory used by the StartupCache, i.e. it
|
||||
// excludes the mapping.
|
||||
size_t HeapSizeOfIncludingThis(nsMallocSizeOfFun mallocSizeOf);
|
||||
|
||||
size_t SizeOfMapping();
|
||||
|
||||
private:
|
||||
StartupCache();
|
||||
|
@ -166,6 +174,11 @@ private:
|
|||
static void WriteTimeout(nsITimer *aTimer, void *aClosure);
|
||||
static void ThreadedWrite(void *aClosure);
|
||||
|
||||
static size_t SizeOfEntryExcludingThis(const nsACString& key,
|
||||
const nsAutoPtr<CacheEntry>& data,
|
||||
nsMallocSizeOfFun mallocSizeOf,
|
||||
void *);
|
||||
|
||||
nsClassHashtable<nsCStringHashKey, CacheEntry> mTable;
|
||||
nsRefPtr<nsZipArchive> mArchive;
|
||||
nsCOMPtr<nsILocalFile> mFile;
|
||||
|
@ -183,7 +196,8 @@ private:
|
|||
nsTHashtable<nsISupportsHashKey> mWriteObjectMap;
|
||||
#endif
|
||||
|
||||
nsIMemoryReporter* mMemoryReporter;
|
||||
nsIMemoryReporter* mMappingMemoryReporter;
|
||||
nsIMemoryReporter* mDataMemoryReporter;
|
||||
};
|
||||
|
||||
// This debug outputstream attempts to detect if clients are writing multiple
|
||||
|
|
|
@ -272,7 +272,7 @@ public:
|
|||
* @return the summed size of all the entries
|
||||
*/
|
||||
size_t SizeOfExcludingThis(SizeOfEntryExcludingThisFun sizeOfEntryExcludingThis,
|
||||
nsMallocSizeOfFun mallocSizeOf, void *userArg)
|
||||
nsMallocSizeOfFun mallocSizeOf, void *userArg = NULL)
|
||||
{
|
||||
if (IsInitialized()) {
|
||||
s_SizeOfArgs args = { sizeOfEntryExcludingThis, userArg };
|
||||
|
|
Загрузка…
Ссылка в новой задаче