Bug 831193 (part 9) - Don't use NS_MEMORY_REPORTER_IMPLEMENT in Preferences.cpp. r=nfroyd.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 17 Jan 2013 16:45:11 -0800
changeset 144648 24b0e5ef846ae160051aa86a8ff10a3af2fc0781
parent 144647 5c86a02a4c2f5f15e8f6b14d1c40c30243c01517
child 144649 e704db333c96ee0c3d724d755249e7a836e17749
push id33045
push usernnethercote@mozilla.com
push dateWed, 28 Aug 2013 08:59:06 +0000
treeherdermozilla-inbound@eead1e72622d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnfroyd
bugs831193
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 831193 (part 9) - Don't use NS_MEMORY_REPORTER_IMPLEMENT in Preferences.cpp. r=nfroyd.
modules/libpref/public/Preferences.h
modules/libpref/src/Preferences.cpp
--- a/modules/libpref/public/Preferences.h
+++ b/modules/libpref/public/Preferences.h
@@ -12,16 +12,17 @@
 
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
 #include "nsIPrefBranchInternal.h"
 #include "nsIObserver.h"
 #include "nsCOMPtr.h"
 #include "nsTArray.h"
 #include "nsWeakReference.h"
+#include "mozilla/MemoryReporting.h"
 
 class nsIFile;
 class nsCString;
 class nsString;
 class nsAdoptingString;
 class nsAdoptingCString;
 
 #ifndef have_PrefChangedFunc_typedef
@@ -343,17 +344,17 @@ public:
    */
   static int32_t GetDefaultType(const char* aPref);
 
   // Used to synchronise preferences between chrome and content processes.
   static void GetPreferences(InfallibleTArray<PrefSetting>* aPrefs);
   static void GetPreference(PrefSetting* aPref);
   static void SetPreference(const PrefSetting& aPref);
 
-  static int64_t GetPreferencesMemoryUsed();
+  static int64_t SizeOfIncludingThisAndOtherStuff(mozilla::MallocSizeOf aMallocSizeOf);
   static nsresult SetFloat(const char* aPref, float aValue);
 
 protected:
   nsresult NotifyServiceObservers(const char *aSubject);
   /**
    * Reads the default pref file or, if that failed, try to save a new one.
    *
    * @return NS_OK if either action succeeded,
--- a/modules/libpref/src/Preferences.cpp
+++ b/modules/libpref/src/Preferences.cpp
@@ -1,9 +1,10 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/dom/ContentChild.h"
 
 #include "mozilla/Attributes.h"
@@ -155,76 +156,78 @@ struct CacheData {
     float defaultValueFloat;
   };
 };
 
 static nsTArray<nsAutoPtr<CacheData> >* gCacheData = nullptr;
 static nsRefPtrHashtable<ValueObserverHashKey,
                          ValueObserver>* gObserverTable = nullptr;
 
-NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(PreferencesMallocSizeOf)
-
 static size_t
 SizeOfObserverEntryExcludingThis(ValueObserverHashKey* aKey,
                                  const nsRefPtr<ValueObserver>& aData,
                                  mozilla::MallocSizeOf aMallocSizeOf,
                                  void*)
 {
   size_t n = 0;
   n += aKey->mPrefName.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
   n += aData->mClosures.SizeOfExcludingThis(aMallocSizeOf);
   return n;
 }
 
-// static
-int64_t
-Preferences::GetPreferencesMemoryUsed()
+// Although this is a member of Preferences, it measures sPreferences and
+// several other global structures.
+/* static */ int64_t
+Preferences::SizeOfIncludingThisAndOtherStuff(mozilla::MallocSizeOf aMallocSizeOf)
 {
   NS_ENSURE_TRUE(InitStaticMembers(), 0);
 
-  size_t n = 0;
-  n += PreferencesMallocSizeOf(sPreferences);
+  size_t n = aMallocSizeOf(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);
+    n += PL_DHashTableSizeOfExcludingThis(&gHashTable, nullptr, aMallocSizeOf);
   }
   if (gCacheData) {
-    n += gCacheData->SizeOfIncludingThis(PreferencesMallocSizeOf);
+    n += gCacheData->SizeOfIncludingThis(aMallocSizeOf);
     for (uint32_t i = 0, count = gCacheData->Length(); i < count; ++i) {
-      n += PreferencesMallocSizeOf((*gCacheData)[i]);
+      n += aMallocSizeOf((*gCacheData)[i]);
     }
   }
   if (gObserverTable) {
-    n += PreferencesMallocSizeOf(gObserverTable);
+    n += aMallocSizeOf(gObserverTable);
     n += gObserverTable->SizeOfExcludingThis(SizeOfObserverEntryExcludingThis,
-                                             PreferencesMallocSizeOf);
+                                             aMallocSizeOf);
   }
   // We don't measure sRootBranch and sDefaultRootBranch here because
   // DMD indicates they are not significant.
-  n += pref_SizeOfPrivateData(PreferencesMallocSizeOf);
+  n += pref_SizeOfPrivateData(aMallocSizeOf);
   return n;
 }
 
-NS_MEMORY_REPORTER_IMPLEMENT(Preferences,
-  "explicit/preferences",
-  KIND_HEAP,
-  UNITS_BYTES,
-  Preferences::GetPreferencesMemoryUsed,
-  "Memory used by the preferences system.")
+class PreferencesReporter MOZ_FINAL : public MemoryReporterBase
+{
+public:
+  PreferencesReporter()
+    : MemoryReporterBase("explicit/preferences", KIND_HEAP, UNITS_BYTES,
+                         "Memory used by the preferences system.")
+  {}
+private:
+  int64_t Amount() MOZ_OVERRIDE
+  {
+    return Preferences::SizeOfIncludingThisAndOtherStuff(MallocSizeOf);
+  }
+};
 
 namespace {
 class AddPreferencesMemoryReporterRunnable : public nsRunnable
 {
   NS_IMETHOD Run()
   {
-    nsCOMPtr<nsIMemoryReporter> reporter =
-      new NS_MEMORY_REPORTER_NAME(Preferences);
-    return NS_RegisterMemoryReporter(reporter);
+    return NS_RegisterMemoryReporter(new PreferencesReporter());
   }
 };
 } // anonymous namespace
 
 // static
 Preferences*
 Preferences::GetInstanceForService()
 {