From 3ee5b531ad64cc3ff6d2ac435aad79dcd826a6c9 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 3 Jan 2013 21:26:56 -0800 Subject: [PATCH] Bug 826553 - Add a memory reporter for the event listener manager's hash table. r=bz. --HG-- extra : rebase_source : 72584fbf0b80c1e8d5451486ca2c46efebc93b44 --- content/base/src/nsContentUtils.cpp | 26 ++++++++++++++++++++++++++ xpcom/base/nsMemoryReporterManager.cpp | 3 ++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index e45ed2e13e1..d2b910cea9e 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -247,6 +247,25 @@ static NS_DEFINE_CID(kParserServiceCID, NS_PARSERSERVICE_CID); static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID); static PLDHashTable sEventListenerManagersHash; +static nsCOMPtr sEventListenerManagersHashReporter; + +NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(EventListenerManagersHashMallocSizeOf) + +static int64_t GetEventListenerManagersHash() +{ + // We don't measure the |nsEventListenerManager| objects pointed to by the + // entries because those references are non-owning. + return PL_DHashTableSizeOfExcludingThis(&sEventListenerManagersHash, + nullptr, + EventListenerManagersHashMallocSizeOf); +} + +NS_MEMORY_REPORTER_IMPLEMENT(EventListenerManagersHash, + "explicit/dom/event-listener-managers-hash", + KIND_HEAP, + UNITS_BYTES, + GetEventListenerManagersHash, + "Memory used by the event listener manager's hash table.") class EventListenerManagerMapEntry : public PLDHashEntryHdr { @@ -383,6 +402,10 @@ nsContentUtils::Init() return NS_ERROR_OUT_OF_MEMORY; } + + sEventListenerManagersHashReporter = + new NS_MEMORY_REPORTER_NAME(EventListenerManagersHash); + (void)::NS_RegisterMemoryReporter(sEventListenerManagersHashReporter); } sBlockedScriptRunners = new nsTArray< nsCOMPtr >; @@ -1464,6 +1487,9 @@ nsContentUtils::Shutdown() if (sEventListenerManagersHash.entryCount == 0) { PL_DHashTableFinish(&sEventListenerManagersHash); sEventListenerManagersHash.ops = nullptr; + + (void)::NS_UnregisterMemoryReporter(sEventListenerManagersHashReporter); + sEventListenerManagersHashReporter = nullptr; } } diff --git a/xpcom/base/nsMemoryReporterManager.cpp b/xpcom/base/nsMemoryReporterManager.cpp index d050f3f8dca..db708221b79 100644 --- a/xpcom/base/nsMemoryReporterManager.cpp +++ b/xpcom/base/nsMemoryReporterManager.cpp @@ -1,4 +1,5 @@ -/* -*- Mode: C++; tab-width: 50; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 50; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim: set ts=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/. */