Bug 831193 (part 20) - Make nsPrefixSetReporter a subclass of MemoryReporterBase. r=gcp.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 17 Jan 2013 21:43:21 -0800
changeset 144683 e4eb75e2d77e479e33ee8b08e5db1f466c19d801
parent 144682 595cec1f096a3713325595e79a742b9252692ea0
child 144684 eead1e72622dbf85ebb0d1fa9695e341ab5830a2
push id25171
push useremorley@mozilla.com
push dateWed, 28 Aug 2013 15:20:13 +0000
treeherdermozilla-central@f280351a238f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgcp
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 20) - Make nsPrefixSetReporter a subclass of MemoryReporterBase. r=gcp.
toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
toolkit/components/url-classifier/nsUrlClassifierPrefixSet.h
--- a/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
@@ -1,23 +1,25 @@
-//* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
+/* -*- 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 "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsDebug.h"
+#include "nsPrintfCString.h"
 #include "nsTArray.h"
 #include "nsString.h"
 #include "nsUrlClassifierPrefixSet.h"
 #include "nsIUrlClassifierPrefixSet.h"
 #include "nsIRandomGenerator.h"
 #include "nsIFile.h"
+#include "nsIMemoryReporter.h"
 #include "nsToolkitCompsCID.h"
 #include "nsTArray.h"
 #include "nsThreadUtils.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/FileUtils.h"
 #include "prlog.h"
@@ -29,103 +31,55 @@ using namespace mozilla;
 static const PRLogModuleInfo *gUrlClassifierPrefixSetLog = nullptr;
 #define LOG(args) PR_LOG(gUrlClassifierPrefixSetLog, PR_LOG_DEBUG, args)
 #define LOG_ENABLED() PR_LOG_TEST(gUrlClassifierPrefixSetLog, 4)
 #else
 #define LOG(args)
 #define LOG_ENABLED() (false)
 #endif
 
-class nsPrefixSetReporter : public nsIMemoryReporter
+class PrefixSetReporter MOZ_FINAL : public MemoryReporterBase
 {
 public:
-  nsPrefixSetReporter(nsUrlClassifierPrefixSet* aParent, const nsACString& aName);
-  virtual ~nsPrefixSetReporter() {}
-
-  NS_DECL_THREADSAFE_ISUPPORTS
-  NS_DECL_NSIMEMORYREPORTER
+  PrefixSetReporter(nsUrlClassifierPrefixSet* aPrefixSet,
+                    const nsACString& aName)
+    : MemoryReporterBase(
+        nsPrintfCString(
+          "explicit/storage/prefix-set/%s",
+          (!aName.IsEmpty() ? PromiseFlatCString(aName).get() : "?!")
+        ).get(),
+        KIND_HEAP, UNITS_BYTES,
+        "Memory used by the prefix set for a URL classifier.")
+    , mPrefixSet(aPrefixSet)
+  {}
 
 private:
-  nsCString mPath;
-  nsUrlClassifierPrefixSet* mParent;
-};
-
-NS_IMPL_ISUPPORTS1(nsPrefixSetReporter, nsIMemoryReporter)
-
-NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(StoragePrefixSetMallocSizeOf)
-
-nsPrefixSetReporter::nsPrefixSetReporter(nsUrlClassifierPrefixSet* aParent,
-                                         const nsACString& aName)
-: mParent(aParent)
-{
-  mPath.Assign(NS_LITERAL_CSTRING("explicit/storage/prefixset"));
-  if (!aName.IsEmpty()) {
-    mPath.Append("/");
-    mPath.Append(aName);
+  int64_t Amount() MOZ_OVERRIDE
+  {
+    return mPrefixSet->SizeOfIncludingThis(MallocSizeOf);
   }
-}
-
-NS_IMETHODIMP
-nsPrefixSetReporter::GetProcess(nsACString& aProcess)
-{
-  aProcess.Truncate();
-  return NS_OK;
-}
 
-NS_IMETHODIMP
-nsPrefixSetReporter::GetPath(nsACString& aPath)
-{
-  aPath.Assign(mPath);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsPrefixSetReporter::GetKind(int32_t* aKind)
-{
-  *aKind = nsIMemoryReporter::KIND_HEAP;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsPrefixSetReporter::GetUnits(int32_t* aUnits)
-{
-  *aUnits = nsIMemoryReporter::UNITS_BYTES;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsPrefixSetReporter::GetAmount(int64_t* aAmount)
-{
-  *aAmount = mParent->SizeOfIncludingThis(StoragePrefixSetMallocSizeOf);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsPrefixSetReporter::GetDescription(nsACString& aDescription)
-{
-  aDescription.Assign(NS_LITERAL_CSTRING("Memory used by a PrefixSet for "
-                                         "UrlClassifier, in bytes."));
-  return NS_OK;
-}
+  nsUrlClassifierPrefixSet* mPrefixSet;
+};
 
 NS_IMPL_ISUPPORTS1(nsUrlClassifierPrefixSet, nsIUrlClassifierPrefixSet)
 
 nsUrlClassifierPrefixSet::nsUrlClassifierPrefixSet()
   : mHasPrefixes(false)
 {
 #if defined(PR_LOGGING)
   if (!gUrlClassifierPrefixSetLog)
     gUrlClassifierPrefixSetLog = PR_NewLogModule("UrlClassifierPrefixSet");
 #endif
 }
 
 NS_IMETHODIMP
 nsUrlClassifierPrefixSet::Init(const nsACString& aName)
 {
-  mReporter = new nsPrefixSetReporter(this, aName);
+  mReporter = new PrefixSetReporter(this, aName);
   NS_RegisterMemoryReporter(mReporter);
 
   return NS_OK;
 }
 
 nsUrlClassifierPrefixSet::~nsUrlClassifierPrefixSet()
 {
   NS_UnregisterMemoryReporter(mReporter);
--- a/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.h
+++ b/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.h
@@ -7,25 +7,24 @@
 #ifndef nsUrlClassifierPrefixSet_h_
 #define nsUrlClassifierPrefixSet_h_
 
 #include "nsISupportsUtils.h"
 #include "nsID.h"
 #include "nsIFile.h"
 #include "nsIMutableArray.h"
 #include "nsIUrlClassifierPrefixSet.h"
-#include "nsIMemoryReporter.h"
 #include "nsTArray.h"
 #include "nsToolkitCompsCID.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/CondVar.h"
 #include "mozilla/FileUtils.h"
 
-class nsPrefixSetReporter;
+class nsIMemoryReporter;
 
 class nsUrlClassifierPrefixSet : public nsIUrlClassifierPrefixSet
 {
 public:
   nsUrlClassifierPrefixSet();
   virtual ~nsUrlClassifierPrefixSet();
 
   NS_IMETHOD Init(const nsACString& aName);
@@ -42,17 +41,17 @@ public:
   // in bytes
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);
 
 protected:
   static const uint32_t DELTAS_LIMIT = 100;
   static const uint32_t MAX_INDEX_DIFF = (1 << 16);
   static const uint32_t PREFIXSET_VERSION_MAGIC = 1;
 
-  nsRefPtr<nsPrefixSetReporter> mReporter;
+  nsCOMPtr<nsIMemoryReporter> mReporter;
 
   nsresult MakePrefixSet(const uint32_t* aArray, uint32_t aLength);
   uint32_t BinSearch(uint32_t start, uint32_t end, uint32_t target);
   nsresult LoadFromFd(mozilla::AutoFDClose& fileFd);
   nsresult StoreToFd(mozilla::AutoFDClose& fileFd);
 
   // boolean indicating whether |setPrefixes| has been
   // called with a non-empty array.