Bug 831193 (part 17) - Don't use NS_MEMORY_REPORTER_IMPLEMENT in xpcom/. r=jlebar.

--HG--
extra : rebase_source : 7e2984a99fb7e00aa0ea6bebc23e23e4c99e0b1e
This commit is contained in:
Nicholas Nethercote 2013-01-17 21:43:21 -08:00
parent 3e0ffbadf7
commit d9ca4d212c
12 changed files with 147 additions and 168 deletions

View File

@ -1,5 +1,5 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 ci et: */
/* -*- 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/. */
@ -325,47 +325,14 @@ CreateDIBSectionHook(HDC aDC,
return result;
}
class NumLowMemoryEventsReporter : public nsIMemoryReporter
{
NS_IMETHOD GetProcess(nsACString &aProcess)
{
aProcess.Truncate();
return NS_OK;
}
NS_IMETHOD GetKind(int *aKind)
{
*aKind = KIND_OTHER;
return NS_OK;
}
NS_IMETHOD GetUnits(int *aUnits)
{
*aUnits = UNITS_COUNT_CUMULATIVE;
return NS_OK;
}
};
class NumLowVirtualMemoryEventsMemoryReporter MOZ_FINAL : public NumLowMemoryEventsReporter
class LowMemoryEventsVirtualReporter MOZ_FINAL : public MemoryReporterBase
{
public:
NS_DECL_ISUPPORTS
NS_IMETHOD GetPath(nsACString &aPath)
{
aPath.AssignLiteral("low-memory-events/virtual");
return NS_OK;
}
NS_IMETHOD GetAmount(int64_t *aAmount)
{
// This memory reporter shouldn't be installed on 64-bit machines, since we
// force-disable virtual-memory tracking there.
MOZ_ASSERT(sizeof(void*) == 4);
*aAmount = sNumLowVirtualMemEvents;
return NS_OK;
}
// The description is "???" because we implement GetDescription().
LowMemoryEventsVirtualReporter()
: MemoryReporterBase("low-memory-events/virtual",
KIND_OTHER, UNITS_COUNT_CUMULATIVE, "???")
{}
NS_IMETHOD GetDescription(nsACString &aDescription)
{
@ -388,26 +355,26 @@ public:
}
return NS_OK;
}
private:
int64_t Amount() MOZ_OVERRIDE
{
// This memory reporter shouldn't be installed on 64-bit machines, since we
// force-disable virtual-memory tracking there.
MOZ_ASSERT(sizeof(void*) == 4);
return sNumLowVirtualMemEvents;
}
};
NS_IMPL_ISUPPORTS1(NumLowVirtualMemoryEventsMemoryReporter, nsIMemoryReporter)
class NumLowCommitSpaceEventsMemoryReporter MOZ_FINAL : public NumLowMemoryEventsReporter
class LowCommitSpaceEventsReporter MOZ_FINAL : public MemoryReporterBase
{
public:
NS_DECL_ISUPPORTS
NS_IMETHOD GetPath(nsACString &aPath)
{
aPath.AssignLiteral("low-commit-space-events");
return NS_OK;
}
NS_IMETHOD GetAmount(int64_t *aAmount)
{
*aAmount = sNumLowCommitSpaceEvents;
return NS_OK;
}
// The description is "???" because we implement GetDescription().
LowCommitSpaceEventsReporter()
: MemoryReporterBase("low-commit-space-events",
KIND_OTHER, UNITS_COUNT_CUMULATIVE, "???")
{}
NS_IMETHOD GetDescription(nsACString &aDescription)
{
@ -430,26 +397,19 @@ public:
}
return NS_OK;
}
private:
int64_t Amount() MOZ_OVERRIDE { return sNumLowCommitSpaceEvents; }
};
NS_IMPL_ISUPPORTS1(NumLowCommitSpaceEventsMemoryReporter, nsIMemoryReporter)
class NumLowPhysicalMemoryEventsMemoryReporter MOZ_FINAL : public NumLowMemoryEventsReporter
class LowMemoryEventsPhysicalReporter MOZ_FINAL : public MemoryReporterBase
{
public:
NS_DECL_ISUPPORTS
NS_IMETHOD GetPath(nsACString &aPath)
{
aPath.AssignLiteral("low-memory-events/physical");
return NS_OK;
}
NS_IMETHOD GetAmount(int64_t *aAmount)
{
*aAmount = sNumLowPhysicalMemEvents;
return NS_OK;
}
// The description is "???" because we implement GetDescription().
LowMemoryEventsPhysicalReporter()
: MemoryReporterBase("low-memory-events/physical",
KIND_OTHER, UNITS_COUNT_CUMULATIVE, "???")
{}
NS_IMETHOD GetDescription(nsACString &aDescription)
{
@ -473,9 +433,10 @@ public:
}
return NS_OK;
}
};
NS_IMPL_ISUPPORTS1(NumLowPhysicalMemoryEventsMemoryReporter, nsIMemoryReporter)
private:
int64_t Amount() MOZ_OVERRIDE { return sNumLowPhysicalMemEvents; }
};
#endif // defined(XP_WIN)
@ -592,10 +553,10 @@ void Activate()
Preferences::AddUintVarCache(&sLowMemoryNotificationIntervalMS,
"memory.low_memory_notification_interval_ms", 10000);
NS_RegisterMemoryReporter(new NumLowCommitSpaceEventsMemoryReporter());
NS_RegisterMemoryReporter(new NumLowPhysicalMemoryEventsMemoryReporter());
NS_RegisterMemoryReporter(new LowCommitSpaceEventsReporter());
NS_RegisterMemoryReporter(new LowMemoryEventsPhysicalReporter());
if (sizeof(void*) == 4) {
NS_RegisterMemoryReporter(new NumLowVirtualMemoryEventsMemoryReporter());
NS_RegisterMemoryReporter(new LowMemoryEventsVirtualReporter());
}
sHooksActive = true;
#endif

View File

@ -1,5 +1,5 @@
/* -*- Mode: C++; tab-width: 50; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 ci et: */
/* -*- 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/. */
@ -520,8 +520,20 @@ MapsReporter::ParseMapBody(
return NS_OK;
}
static nsresult GetUSS(int64_t *n)
class ResidentUniqueReporter MOZ_FINAL : public MemoryReporterBase
{
public:
ResidentUniqueReporter()
: MemoryReporterBase("resident-unique", KIND_OTHER, UNITS_BYTES,
"Memory mapped by the process that is present in physical memory and not "
"shared with any other processes. This is also known as the process's unique "
"set size (USS). This is the amount of RAM we'd expect to be freed if we "
"closed this process.")
{}
private:
NS_IMETHOD GetAmount(int64_t *aAmount)
{
// You might be tempted to calculate USS by subtracting the "shared" value
// from the "resident" value in /proc/<pid>/statm. But at least on Linux,
// statm's "shared" value actually counts pages backed by files, which has
@ -533,42 +545,33 @@ static nsresult GetUSS(int64_t *n)
// smaps reporter in normal about:memory operation). Hopefully this
// implementation is fast enough not to matter.
*n = 0;
*aAmount = 0;
FILE *f = fopen("/proc/self/smaps", "r");
NS_ENSURE_STATE(f);
int64_t total = 0;
char line[256];
while(fgets(line, sizeof(line), f)) {
long long val = 0;
if(sscanf(line, "Private_Dirty: %lld kB", &val) == 1 ||
sscanf(line, "Private_Clean: %lld kB", &val) == 1) {
total += val * 1024; // convert from kB to bytes
}
while (fgets(line, sizeof(line), f)) {
long long val = 0;
if (sscanf(line, "Private_Dirty: %lld kB", &val) == 1 ||
sscanf(line, "Private_Clean: %lld kB", &val) == 1) {
total += val * 1024; // convert from kB to bytes
}
}
*n = total;
*aAmount = total;
fclose(f);
return NS_OK;
}
NS_FALLIBLE_MEMORY_REPORTER_IMPLEMENT(USS,
"resident-unique",
KIND_OTHER,
UNITS_BYTES,
GetUSS,
"Memory mapped by the process that is present in physical memory and not "
"shared with any other processes. This is also known as the process's "
"unique set size (USS). This is the amount of RAM we'd expect to be freed "
"if we closed this process.")
}
};
void Init()
{
nsCOMPtr<nsIMemoryMultiReporter> reporter = new MapsReporter();
NS_RegisterMemoryMultiReporter(reporter);
NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(USS));
NS_RegisterMemoryReporter(new ResidentUniqueReporter());
}
} // namespace MapsMemoryReporter

View File

@ -16,6 +16,7 @@
#include "mozilla/dom/ContentChild.h"
#include "nsIConsoleService.h"
#include "nsICycleCollectorListener.h"
#include "nsIMemoryReporter.h"
#include "nsDirectoryServiceDefs.h"
#include "nsGZFileWriter.h"
#include "nsJSEnvironment.h"

View File

@ -490,7 +490,7 @@ public:
"exact amount requested is not recorded.)")
{}
private:
int64_t Amount()
int64_t Amount() MOZ_OVERRIDE
{
jemalloc_stats_t stats;
jemalloc_stats(&stats);

View File

@ -82,7 +82,6 @@
#include "nsIInterfaceRequestor.h"
#include "nsILineInputStream.h"
#include "nsIMemory.h"
#include "nsIMemoryReporter.h"
#include "nsIMutable.h"
#include "nsIObserver.h"
#include "nsIObserverService.h"

View File

@ -402,14 +402,20 @@ CategoryEnumerator::enumfunc_createenumerator(const char* aStr, CategoryNode* aN
NS_IMPL_QUERY_INTERFACE1(nsCategoryManager, nsICategoryManager)
NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(CategoryManagerMallocSizeOf)
NS_MEMORY_REPORTER_IMPLEMENT(CategoryManager,
"explicit/xpcom/category-manager",
KIND_HEAP,
nsIMemoryReporter::UNITS_BYTES,
nsCategoryManager::GetCategoryManagerSize,
"Memory used for the XPCOM category manager.")
class XPCOMCategoryManagerReporter MOZ_FINAL : public MemoryReporterBase
{
public:
XPCOMCategoryManagerReporter()
: MemoryReporterBase("explicit/xpcom/category-manager",
KIND_HEAP, UNITS_BYTES,
"Memory used for the XPCOM category manager.")
{}
private:
int64_t Amount() MOZ_OVERRIDE
{
return nsCategoryManager::SizeOfIncludingThis(MallocSizeOf);
}
};
NS_IMETHODIMP_(nsrefcnt)
nsCategoryManager::AddRef()
@ -463,14 +469,13 @@ nsCategoryManager::nsCategoryManager()
void
nsCategoryManager::InitMemoryReporter()
{
mReporter = new NS_MEMORY_REPORTER_NAME(CategoryManager);
mReporter = new XPCOMCategoryManagerReporter();
NS_RegisterMemoryReporter(mReporter);
}
nsCategoryManager::~nsCategoryManager()
{
(void)::NS_UnregisterMemoryReporter(mReporter);
mReporter = nullptr;
NS_UnregisterMemoryReporter(mReporter);
// the hashtable contains entries that must be deleted before the arena is
// destroyed, or else you will have PRLocks undestroyed and other Really
@ -490,11 +495,12 @@ nsCategoryManager::get_category(const char* aName) {
}
/* static */ int64_t
nsCategoryManager::GetCategoryManagerSize()
nsCategoryManager::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf)
{
MOZ_ASSERT(nsCategoryManager::gCategoryManager);
return nsCategoryManager::gCategoryManager->SizeOfIncludingThis(
CategoryManagerMallocSizeOf);
return nsCategoryManager::gCategoryManager
? nsCategoryManager::gCategoryManager->SizeOfIncludingThisHelper(
aMallocSizeOf)
: 0;
}
static size_t
@ -509,7 +515,7 @@ SizeOfCategoryManagerTableEntryExcludingThis(nsDepCharHashKey::KeyType aKey,
}
size_t
nsCategoryManager::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf)
nsCategoryManager::SizeOfIncludingThisHelper(MallocSizeOf aMallocSizeOf)
{
size_t n = aMallocSizeOf(this);

View File

@ -122,8 +122,7 @@ public:
static nsCategoryManager* GetSingleton();
static void Destroy();
static int64_t GetCategoryManagerSize();
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
static int64_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
private:
static nsCategoryManager* gCategoryManager;
@ -131,6 +130,8 @@ private:
nsCategoryManager();
~nsCategoryManager();
size_t SizeOfIncludingThisHelper(mozilla::MallocSizeOf aMallocSizeOf);
CategoryNode* get_category(const char* aName);
void NotifyObservers(const char* aTopic,
const char* aCategoryName, // must be a static string
@ -141,7 +142,7 @@ private:
mozilla::Mutex mLock;
bool mSuppressNotifications;
nsIMemoryReporter* mReporter;
nsCOMPtr<nsIMemoryReporter> mReporter;
};
#endif

View File

@ -1,4 +1,5 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set ts=8 sts=4 et sw=4 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/.
@ -279,22 +280,23 @@ CloneAndAppend(nsIFile* aBase, const nsACString& append)
// nsComponentManagerImpl
////////////////////////////////////////////////////////////////////////////////
NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(ComponentManagerMallocSizeOf)
static int64_t
GetComponentManagerSize()
class XPCOMComponentManagerReporter MOZ_FINAL : public MemoryReporterBase
{
MOZ_ASSERT(nsComponentManagerImpl::gComponentManager);
return nsComponentManagerImpl::gComponentManager->SizeOfIncludingThis(
ComponentManagerMallocSizeOf);
}
NS_MEMORY_REPORTER_IMPLEMENT(ComponentManager,
"explicit/xpcom/component-manager",
KIND_HEAP,
nsIMemoryReporter::UNITS_BYTES,
GetComponentManagerSize,
"Memory used for the XPCOM component manager.")
public:
XPCOMComponentManagerReporter()
: MemoryReporterBase("explicit/xpcom/component-manager",
KIND_HEAP, UNITS_BYTES,
"Memory used for the XPCOM component manager.")
{}
private:
int64_t Amount() MOZ_OVERRIDE
{
return nsComponentManagerImpl::gComponentManager
? nsComponentManagerImpl::gComponentManager->SizeOfIncludingThis(
MallocSizeOf)
: 0;
}
};
nsresult
nsComponentManagerImpl::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult)
@ -412,8 +414,8 @@ nsresult nsComponentManagerImpl::Init()
nsCategoryManager::GetSingleton()->SuppressNotifications(false);
mReporter = new NS_MEMORY_REPORTER_NAME(ComponentManager);
(void)::NS_RegisterMemoryReporter(mReporter);
mReporter = new XPCOMComponentManagerReporter();
NS_RegisterMemoryReporter(mReporter);
// Unfortunately, we can't register the nsCategoryManager memory reporter
// in its constructor (which is triggered by the GetSingleton() call
@ -798,7 +800,7 @@ nsresult nsComponentManagerImpl::Shutdown(void)
// Shutdown the component manager
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsComponentManager: Beginning Shutdown."));
(void)::NS_UnregisterMemoryReporter(mReporter);
NS_UnregisterMemoryReporter(mReporter);
mReporter = nullptr;
// Release all cached factories

View File

@ -38,8 +38,8 @@
#include "mozilla/Attributes.h"
struct nsFactoryEntry;
class nsIServiceManager;
class nsIMemoryReporter;
class nsIServiceManager;
struct PRThread;
#define NS_COMPONENTMANAGER_CID \
@ -317,7 +317,7 @@ public:
private:
~nsComponentManagerImpl();
nsIMemoryReporter* mReporter;
nsCOMPtr<nsIMemoryReporter> mReporter;
};

View File

@ -15,6 +15,7 @@
#include "nsDataHashtable.h"
template<typename T> class nsCOMArray;
class nsIMemoryReporter;
class XPTHeader;
class XPTInterfaceDirectoryEntry;
class xptiInterfaceEntry;
@ -108,6 +109,8 @@ private:
xptiWorkingSet mWorkingSet;
Mutex mResolveLock;
nsCOMPtr<nsIMemoryReporter> mReporter;
};
}

View File

@ -1,4 +1,5 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* -*- 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/. */
@ -19,7 +20,7 @@
using namespace mozilla;
NS_IMPL_ISUPPORTS1(XPTInterfaceInfoManager,
NS_IMPL_ISUPPORTS1(XPTInterfaceInfoManager,
nsIInterfaceInfoManager)
static XPTInterfaceInfoManager* gInterfaceInfoManager = nullptr;
@ -27,9 +28,6 @@ static XPTInterfaceInfoManager* gInterfaceInfoManager = nullptr;
static int gCallCount = 0;
#endif
NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(XPTMallocSizeOf)
size_t
XPTInterfaceInfoManager::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf)
{
@ -37,30 +35,33 @@ XPTInterfaceInfoManager::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf)
ReentrantMonitorAutoEnter monitor(mWorkingSet.mTableReentrantMonitor);
// The entries themselves are allocated out of an arena accounted
// for elsewhere, so don't measure them
n += mWorkingSet.mIIDTable.SizeOfExcludingThis(NULL, XPTMallocSizeOf);
n += mWorkingSet.mNameTable.SizeOfExcludingThis(NULL, XPTMallocSizeOf);
n += mWorkingSet.mIIDTable.SizeOfExcludingThis(NULL, aMallocSizeOf);
n += mWorkingSet.mNameTable.SizeOfExcludingThis(NULL, aMallocSizeOf);
return n;
}
// static
int64_t
XPTInterfaceInfoManager::GetXPTIWorkingSetSize()
class XPTIWorkingSetReporter MOZ_FINAL : public MemoryReporterBase
{
size_t n = XPT_SizeOfArena(gXPTIStructArena, XPTMallocSizeOf);
public:
XPTIWorkingSetReporter()
: MemoryReporterBase("explicit/xpti-working-set", KIND_HEAP, UNITS_BYTES,
"Memory used by the XPCOM typelib system.")
{}
private:
int64_t Amount() MOZ_OVERRIDE
{
size_t n = gInterfaceInfoManager
? gInterfaceInfoManager->SizeOfIncludingThis(MallocSizeOf)
: 0;
if (gInterfaceInfoManager) {
n += gInterfaceInfoManager->SizeOfIncludingThis(XPTMallocSizeOf);
// Measure gXPTIStructArena here, too. This is a bit grotty because it
// doesn't belong to the xptiInterfaceInfoManager, but there's no
// obviously better place to measure it.
n += XPT_SizeOfArena(gXPTIStructArena, MallocSizeOf);
return n;
}
return n;
}
NS_MEMORY_REPORTER_IMPLEMENT(XPTInterfaceInfoManager,
"explicit/xpti-working-set",
KIND_HEAP,
UNITS_BYTES,
XPTInterfaceInfoManager::GetXPTIWorkingSetSize,
"Memory used by the XPCOM typelib system.")
};
// static
XPTInterfaceInfoManager*
@ -83,7 +84,8 @@ XPTInterfaceInfoManager::XPTInterfaceInfoManager()
: mWorkingSet(),
mResolveLock("XPTInterfaceInfoManager.mResolveLock")
{
NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(XPTInterfaceInfoManager));
mReporter = new XPTIWorkingSetReporter();
NS_RegisterMemoryReporter(mReporter);
}
XPTInterfaceInfoManager::~XPTInterfaceInfoManager()
@ -91,6 +93,8 @@ XPTInterfaceInfoManager::~XPTInterfaceInfoManager()
// We only do this on shutdown of the service.
mWorkingSet.InvalidateInterfaceInfos();
NS_UnregisterMemoryReporter(mReporter);
gInterfaceInfoManager = nullptr;
#ifdef DEBUG
gCallCount = 0;

View File

@ -72,7 +72,6 @@
/***************************************************************************/
class xptiInterfaceInfo;
class xptiInterfaceInfoManager;
class xptiInterfaceEntry;
class xptiTypelibGuts;