Bug 765244 - add a memory reporter for preferences; r=njn

--HG--
extra : rebase_source : 1be2d7c4e2f4d1747afdb025392009532bc71add
This commit is contained in:
Nathan Froyd 2012-10-11 11:36:21 -04:00
Родитель 45284bf0c5
Коммит aa1d32544e
5 изменённых файлов: 79 добавлений и 0 удалений

Просмотреть файл

@ -333,6 +333,8 @@ public:
static void GetPreference(PrefSetting* aPref);
static void SetPreference(const PrefSetting& aPref);
static int64_t GetPreferencesMemoryUsed();
protected:
nsresult NotifyServiceObservers(const char *aSubject);
/**

Просмотреть файл

@ -42,6 +42,7 @@
#include "nsTArray.h"
#include "nsRefPtrHashtable.h"
#include "nsIMemoryReporter.h"
namespace mozilla {
@ -158,6 +159,56 @@ static nsTArray<nsAutoPtr<CacheData> >* gCacheData = nullptr;
static nsRefPtrHashtable<ValueObserverHashKey,
ValueObserver>* gObserverTable = nullptr;
NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(PreferencesMallocSizeOf, "preferences")
static size_t
SizeOfObserverEntryExcludingThis(ValueObserverHashKey* aKey,
const nsRefPtr<ValueObserver>& aData,
nsMallocSizeOfFun aMallocSizeOf,
void*)
{
size_t n = 0;
n += aKey->mPrefName.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
n += aData->mClosures.SizeOfExcludingThis(aMallocSizeOf);
return n;
}
// static
int64_t
Preferences::GetPreferencesMemoryUsed()
{
size_t n = 0;
n += PreferencesMallocSizeOf(sPreferences);
if (gHashTable.ops) {
// pref keys are allocated in a private arena, which we count elsewhere.
// pref stringvals are allocated out of the same private arena.
n += PL_DHashTableSizeOfExcludingThis(&gHashTable, nullptr,
PreferencesMallocSizeOf);
}
if (gCacheData) {
n += gCacheData->SizeOfIncludingThis(PreferencesMallocSizeOf);
for (uint32_t i = 0, count = gCacheData->Length(); i < count; ++i) {
n += PreferencesMallocSizeOf((*gCacheData)[i]);
}
}
if (gObserverTable) {
n += PreferencesMallocSizeOf(gObserverTable);
n += gObserverTable->SizeOfExcludingThis(SizeOfObserverEntryExcludingThis,
PreferencesMallocSizeOf);
}
// We don't measure sRootBranch and sDefaultRootBranch here because
// DMD indicates they are not significant.
n += pref_SizeOfPrivateData(PreferencesMallocSizeOf);
return n;
}
NS_MEMORY_REPORTER_IMPLEMENT(Preferences,
"explicit/preferences",
KIND_HEAP,
UNITS_BYTES,
Preferences::GetPreferencesMemoryUsed,
"Memory used by the preferences system.")
// static
Preferences*
Preferences::GetInstanceForService()
@ -188,6 +239,9 @@ Preferences::GetInstanceForService()
gObserverTable = new nsRefPtrHashtable<ValueObserverHashKey, ValueObserver>();
gObserverTable->Init();
nsCOMPtr<nsIMemoryReporter> reporter(new NS_MEMORY_REPORTER_NAME(Preferences));
NS_RegisterMemoryReporter(reporter);
NS_ADDREF(sPreferences);
return sPreferences;
}

Просмотреть файл

@ -187,6 +187,8 @@ public:
static nsresult NotifyObserver(const char *newpref, void *data);
size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf);
protected:
nsPrefBranch() /* disallow use of this constructer */
{ }

Просмотреть файл

@ -806,6 +806,24 @@ nsresult pref_HashPref(const char *key, PrefValue value, PrefType type, uint32_t
return rv;
}
size_t
pref_SizeOfPrivateData(nsMallocSizeOfFun aMallocSizeOf)
{
size_t n = 0;
// The first PLArena is within the PLArenaPool, so start measuring
// malloc'd data with the second arena.
const PLArena* arena = gPrefNameArena.first.next;
while (arena) {
n += aMallocSizeOf(arena);
arena = arena->next;
}
for (struct CallbackNode* node = gCallbacks; node; node = node->next) {
n += aMallocSizeOf(node);
n += aMallocSizeOf(node->domain);
}
return n;
}
PrefType
PREF_GetPrefType(const char *pref_name)
{

Просмотреть файл

@ -37,3 +37,6 @@ PrefHashEntry* pref_HashTableLookup(const void *key);
void pref_GetPrefFromEntry(PrefHashEntry *aHashEntry,
mozilla::dom::PrefSetting* aPref);
size_t
pref_SizeOfPrivateData(nsMallocSizeOfFun aMallocSizeOf);