Bug 829439 (part 2) - Some memory reporter clean-ups. r=jlebar.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 14 Jan 2013 16:28:36 -0800
changeset 118854 6925a363cddf9878026275346fa7e4e378c78997
parent 118853 f6cf84d5ec1a8179cfd7564e45357efac1dc52cb
child 118855 adb13d36e50a3dbef1062e3ec7519878ebb32552
push id24180
push useremorley@mozilla.com
push dateTue, 15 Jan 2013 22:58:27 +0000
treeherdermozilla-central@72e34ce7fd92 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlebar
bugs829439
milestone21.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 829439 (part 2) - Some memory reporter clean-ups. r=jlebar.
dom/ipc/ContentParent.cpp
xpcom/base/nsMemoryReporterManager.cpp
xpcom/base/nsMemoryReporterManager.h
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -66,17 +66,16 @@
 #include "nsIMutable.h"
 #include "nsIObserverService.h"
 #include "nsIPresShell.h"
 #include "nsIRemoteBlob.h"
 #include "nsIScriptError.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsISupportsPrimitives.h"
 #include "nsIWindowWatcher.h"
-#include "nsMemoryReporterManager.h"
 #include "nsServiceManagerUtils.h"
 #include "nsSystemInfo.h"
 #include "nsThreadUtils.h"
 #include "nsToolkitCompsCID.h"
 #include "nsWidgetsCID.h"
 #include "SandboxHal.h"
 #include "StructuredCloneUtils.h"
 #include "TabParent.h"
@@ -125,23 +124,45 @@ using namespace mozilla::ipc;
 using namespace mozilla::layers;
 using namespace mozilla::net;
 
 namespace mozilla {
 namespace dom {
 
 #define NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC "ipc:network:set-offline"
 
+// This represents a single measurement taken by a memory reporter in a child
+// process and passed to this one.  Its process is non-empty, and its amount is
+// fixed.
+class ChildMemoryReporter MOZ_FINAL : public MemoryReporterBase
+{
+public:
+    ChildMemoryReporter(const char* aProcess, const char* aPath, int32_t aKind,
+                        int32_t aUnits, int64_t aAmount,
+                        const char* aDescription)
+      : MemoryReporterBase(aPath, aKind, aUnits, aDescription)
+      , mProcess(aProcess)
+      , mAmount(aAmount)
+    {
+    }
+
+private:
+    int64_t Amount() { return mAmount; }
+
+    nsCString mProcess;
+    int64_t   mAmount;
+};
+
 class MemoryReportRequestParent : public PMemoryReportRequestParent
 {
 public:
     MemoryReportRequestParent();
     virtual ~MemoryReportRequestParent();
 
-    virtual bool    Recv__delete__(const InfallibleTArray<MemoryReport>& report);
+    virtual bool Recv__delete__(const InfallibleTArray<MemoryReport>& report);
 private:
     ContentParent* Owner()
     {
         return static_cast<ContentParent*>(Manager());
     }
 };
     
 
@@ -1691,19 +1712,20 @@ ContentParent::SetChildMemoryReporters(c
 
     for (uint32_t i = 0; i < report.Length(); i++) {
         nsCString process  = report[i].process();
         nsCString path     = report[i].path();
         int32_t   kind     = report[i].kind();
         int32_t   units    = report[i].units();
         int64_t   amount   = report[i].amount();
         nsCString desc     = report[i].desc();
-        
-        nsRefPtr<nsMemoryReporter> r =
-            new nsMemoryReporter(process, path, kind, units, amount, desc);
+
+        nsRefPtr<ChildMemoryReporter> r =
+            new ChildMemoryReporter(process.get(), path.get(), kind, units,
+                                    amount, desc.get());
 
         mMemoryReporters.AppendObject(r);
         mgr->RegisterReporter(r);
     }
 
     nsCOMPtr<nsIObserverService> obs =
         do_GetService("@mozilla.org/observer-service;1");
     if (obs)
--- a/xpcom/base/nsMemoryReporterManager.cpp
+++ b/xpcom/base/nsMemoryReporterManager.cpp
@@ -764,35 +764,16 @@ nsMemoryReporterManager::GetResident(int
 #if HAVE_VSIZE_AND_RESIDENT_REPORTERS
     return ::GetResident(aResident);
 #else
     *aResident = 0;
     return NS_ERROR_NOT_AVAILABLE;
 #endif
 }
 
-struct MemoryReport {
-    MemoryReport(const nsACString &path, int64_t amount) 
-    : path(path), amount(amount)
-    {
-        MOZ_COUNT_CTOR(MemoryReport);
-    }
-    MemoryReport(const MemoryReport& rhs)
-    : path(rhs.path), amount(rhs.amount)
-    {
-        MOZ_COUNT_CTOR(MemoryReport);
-    }
-    ~MemoryReport() 
-    {
-        MOZ_COUNT_DTOR(MemoryReport);
-    }
-    const nsCString path;
-    int64_t amount;
-};
-
 #if defined(DEBUG) && !defined(MOZ_DMD)
 // This is just a wrapper for int64_t that implements nsISupports, so it can be
 // passed to nsIMemoryMultiReporter::CollectReports.
 class Int64Wrapper MOZ_FINAL : public nsISupports {
 public:
     NS_DECL_ISUPPORTS
     Int64Wrapper() : mValue(0) { }
     int64_t mValue;
@@ -1021,73 +1002,16 @@ nsMemoryReporterManager::MinimizeMemoryU
 
   nsRefPtr<nsICancelableRunnable> runnable =
     new MinimizeMemoryUsageRunnable(aCallback);
   NS_ADDREF(*result = runnable);
 
   return NS_DispatchToMainThread(runnable);
 }
 
-NS_IMPL_ISUPPORTS1(nsMemoryReporter, nsIMemoryReporter)
-
-nsMemoryReporter::nsMemoryReporter(nsACString& process,
-                                   nsACString& path,
-                                   int32_t kind,
-                                   int32_t units,
-                                   int64_t amount,
-                                   nsACString& desc)
-: mProcess(process)
-, mPath(path)
-, mKind(kind)
-, mUnits(units)
-, mAmount(amount)
-, mDesc(desc)
-{
-}
-
-nsMemoryReporter::~nsMemoryReporter()
-{
-}
-
-NS_IMETHODIMP nsMemoryReporter::GetProcess(nsACString &aProcess)
-{
-    aProcess.Assign(mProcess);
-    return NS_OK;
-}
-
-NS_IMETHODIMP nsMemoryReporter::GetPath(nsACString &aPath)
-{
-    aPath.Assign(mPath);
-    return NS_OK;
-}
-
-NS_IMETHODIMP nsMemoryReporter::GetKind(int32_t *aKind)
-{
-    *aKind = mKind;
-    return NS_OK;
-}
-
-NS_IMETHODIMP nsMemoryReporter::GetUnits(int32_t *aUnits)
-{
-    *aUnits = mUnits;
-    return NS_OK;
-}
-
-NS_IMETHODIMP nsMemoryReporter::GetAmount(int64_t *aAmount)
-{
-    *aAmount = mAmount;
-    return NS_OK;
-}
-
-NS_IMETHODIMP nsMemoryReporter::GetDescription(nsACString &aDescription)
-{
-    aDescription.Assign(mDesc);
-    return NS_OK;
-}
-
 // Most memory reporters don't need thread safety, but some do.  Make them all
 // thread-safe just to be safe.  Memory reporters are created and destroyed
 // infrequently enough that the performance cost should be negligible.
 NS_IMPL_THREADSAFE_ISUPPORTS1(MemoryReporterBase, nsIMemoryReporter)
 
 nsresult
 NS_RegisterMemoryReporter (nsIMemoryReporter *reporter)
 {
--- a/xpcom/base/nsMemoryReporterManager.h
+++ b/xpcom/base/nsMemoryReporterManager.h
@@ -1,56 +1,32 @@
+/* -*- 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 "nsIMemoryReporter.h"
 #include "nsCOMArray.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/Attributes.h"
 #include "nsString.h"
 
 using mozilla::Mutex;
 
-class nsMemoryReporter MOZ_FINAL : public nsIMemoryReporter
+class nsMemoryReporterManager : public nsIMemoryReporterManager
 {
 public:
   NS_DECL_ISUPPORTS
-  NS_DECL_NSIMEMORYREPORTER
-
-  nsMemoryReporter(nsACString& process,
-                   nsACString& path, 
-                   int32_t kind,
-                   int32_t units,
-                   int64_t amount,
-                   nsACString& desc);
-
-  ~nsMemoryReporter();
+  NS_DECL_NSIMEMORYREPORTERMANAGER
 
-protected:
-  nsCString mProcess;
-  nsCString mPath;
-  int32_t   mKind;
-  int32_t   mUnits;
-  int64_t   mAmount;
-  nsCString mDesc;
-};
-
-
-class nsMemoryReporterManager : public nsIMemoryReporterManager
-{
-public:
-    NS_DECL_ISUPPORTS
-    NS_DECL_NSIMEMORYREPORTERMANAGER
-
-    nsMemoryReporterManager();
-    virtual ~nsMemoryReporterManager();
+  nsMemoryReporterManager();
+  virtual ~nsMemoryReporterManager();
 
 private:
-    nsCOMArray<nsIMemoryReporter>      mReporters;
-    nsCOMArray<nsIMemoryMultiReporter> mMultiReporters;
-    Mutex                              mMutex;
+  nsCOMArray<nsIMemoryReporter>      mReporters;
+  nsCOMArray<nsIMemoryMultiReporter> mMultiReporters;
+  Mutex                              mMutex;
 };
 
 #define NS_MEMORY_REPORTER_MANAGER_CID \
 { 0xfb97e4f5, 0x32dd, 0x497a, \
 { 0xba, 0xa2, 0x7d, 0x1e, 0x55, 0x7, 0x99, 0x10 } }